Last updated by manooh on Mon, 2014-01-20 15:43
Overview
This tutorial has been updated to work with Ubuntu 9.04 (Jaunty Jackalope), but should also work well on earlier versions of Ubuntu. The intent is to provide step-by-step instructions to help you with the server setup of a complete development workstation on Ubuntu. DO NOT USE THESE INSTRUCTIONS FOR PRODUCTION SITES. This flexible setup will allow you to easily develop for multiple clients/projects AND work on multiple versions of Drupal. This tutorial is edited and maintained by the Drupal community. If you find something incorrect, know a better "best practice", or something simply doesn't work, please leave a comment and we'll fix the tutorial. But if you know how to correct the tutorial, please just update the wiki.
Details on Multi Vhost setup
This tutorial may seem incomplete. That's because it is only a part of a series of posts found in the Drubuntu group. After you've completed your server setup, you might want to know the details on how/why we chose this configuration. Be Sure to visit the overview and links of the Drubuntu HOWTO, which explains how to install and configure an Ubuntu/LAMP/Eclipse Drupal development environment.
GUI Centric Approach
If you would prefer to try a more GUI centric approach to installing LAMP, there is a great video walkthrough available that details some of these steps. However the video tutorial helps you to set up a single vhost server, not the multi vhost we configure below. A single vhost setup might be easier for someone deploying a single website. A multi vhost setup tends to be more useful for development, and is a much more flexible setup. Plus this configuration its ready to support Drupal in either a single OR multi-site setup.
Install LAMP Workstation packages from Ubuntu repository
The code packages that install LAMP are listed below. This command also installs other modules as the result of dependencies of the primary package.
*** !Important note for Ubuntu Lucid and higher releases, you should see the section on apt pinning if you intend on running PHP 5.2 instead of the default 5.3 that is in the lucid and higher repositories.
To install LAMP, run this command at a terminal:
sudo apt-get install apache2 php5 php5-mysql php5-gd mysql-server
To install optional extensions, run this command at a terminal:
sudo apt-get install php5-curl php5-imagick php5-ffmpeg phpmyadmin mysql-workbench php5-cli php5-mcrypt
- Query the web for updates (php5-curl)
- Provide additional imaging capabilities (php5-imagick)
- Various media capabilities (php5-ffmpeg)
- Opcode cache for faster page loads (php-apc)
- Interactive PHP debugging (php5-xdebug)
- PHP command line (php5-cli)
- KCacheGrind is a graphical tool to let you browse xdebug trace datafiles
- Mysql utilties (phpmyadmin, mysql-workbench, mysql-admin):
Note: This installs php5 as an apache module - if you want to develop/test code using php 4 (no longer necessary in most cases) please read the PHP 4 Support page.
Configure Apache
Note: Replace USER with your Ubuntu username in the following code snippets.
Now that you have a basic LAMP install, you need to configure your setup. Following are a series of snippets to streamline the configuration process.
-
Enable apache modules:
sudo a2enmod vhost_alias rewrite
-
Configure apache webserver access to your workspace and a catch-all vhost by adding the following to /etc/apache2/httpd.conf:
Copy the following snippet into httpd.conf
# based on Drubuntu multisite config file from http://groups.drupal.org/node/6266
#
# IMPORTANT! READ ME!
# In the Directory below, change USER to match YOUR USERNAME
# If you're unsure, Open the PLACES > HOME FOLDER menu. Nautilus will list your username in the Titlebar.
<Directory "/home/USER/workspace">
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
NameVirtualHost *
ServerName localhost
If you can't save the httpd.conf, you should be editing it as a user with root permissions - i.e. something like
sudo vi /etc/apache2/httpd.conf
OR
gksudo gedit /etc/apache2/httpd.confIf you use phpmyadmin you can add the following line to this file import phpmyadmin's configuration file:
Include /etc/phpmyadmin/apache.conf
If you are concerned about Apache allowing the trace http method (which could be a security issue in some situations) you can also add the following line to this file:
TraceEnable Off
-
Configure automatic vhosts for non-multisite or non-Drupal sites.
Save the following as /etc/apache2/sites-available/localhost:
If you want, you can skip this part and just put each drupal install in a separate folder
on your web document root.
# Based on Drubuntu multisite config file from http://groups.drupal.org/node/6266
#
# IMPORTANT! READ ME!
# In the VirtualDocumentRoot below, change USER to match YOUR USERNAME
#
# What this file does:
# Configure Apache so that when you browse the local URL http://DOMAIN.localhost/
# Apache will use the siteroot path /home/USER/workspace/DOMAIN/
# Remember to add your new DOMAIN.localhost domain to /etc/hosts for 127.0.0.1
<VirtualHost *>
ServerName localhost
ServerAlias localhost *.localhost
VirtualDocumentRoot /home/USER/workspace/%1/
</VirtualHost>
For Drupal sites using this setup will also require a change in the .htaccess file located in the root Drupal folder or Clean URLs will not work. Change the line# RewriteBase /
toRewriteBase /
to allow Clean URLs to function properly. -
Configure a vhost for each Drupal version by creating a file in /etc/apache2/sites-available as shown below and by updating the file /etc/hosts as mentioned in the code comments of Step 3 above.
Here's an example for Drupal 6:
Save the following as /etc/apache2/sites-available/6:
# Based on Drubuntu multisite config file from http://groups.drupal.org/node/6266
#
# IMPORTANT! READ ME!
# In the DocumentRoot below, change USER to match YOUR USERNAME
#
# What this file does:
# Configure Apache so that when you browse the local URL http://DOMAIN.{Drupal-version}/
# Apache will use the siteroot path /home/USER/workspace/{Drupal-version}/
# and Drupal multi-site will do the rest
# See http://groups.drupal.org/node/6268 for full details on how to add a new site.
<VirtualHost *>
ServerName 6
ServerAlias 6 *.6
DocumentRoot /home/USER/workspace/drupal-6/
</VirtualHost>Then edit the file /etc/hosts and add this line at the top:
127.0.0.1 drupal-6.localhost
If you get an error about permissions then be sure that you are editing the file with "sudo" or "gksudo" as in the httpd.conf examples above.IMPORTANT: Now,
- Repeat this step for other Drupal versions, saving a file for each vhost as 5, 47 and/or head, AND updating the /etc/hosts file for each as shown above.
-
Enable each vhosts site as needed (definitely the first three lines):
sudo a2dissite default
sudo a2ensite localhost 6 5 47 head - Configure PHP: In /etc/php5/apache2/php.ini search for the memory_limit parameter, and raise it's value to something like 64M.
Or use sed to do this:
sudo sed -i 's/memory_limit = 16M/memory_limit = 64M/' /etc/php5/apache2/php.ini
-
Restart Apache:
sudo /etc/init.d/apache2 restart
APT Pinning
If you are on Ubuntu 10.04 or higher you may want or need to run PHP 5.2 instead of 5.3. If this is the case and you plan on following the above instructions with no serious modifications then you will likely only need to do the following:
- Remove any previously installed PHP 5.3 packages:
dpkg -l | grep php
- Duplicate your existing sources.list replacing lucid with karmic and save it in sources.list.d
sed s/lucid/karmic/g /etc/apt/sources.list | sudo tee /etc/apt/sources.list.d/karmic.list
- Create a file in /etc/apt/preferences.d like this (call it for example /etc/apt/preferences.d/php):
sudo vi /etc/apt/preferences.d/php
OR
gksudo gedit /etc/apt/preferences.d/phpPaste the following in the new file:
Package: php5
Pin: release a=karmic
Pin-Priority: 991
Package: php5-common
Pin: release a=karmic
Pin-Priority: 991
Package: libapache2-mod-php5
Pin: release a=karmic
Pin-Priority: 991
Package: libapache2-mod-php5filter
Pin: release a=karmic
Pin-Priority: 991
Package: php5-cgi
Pin: release a=karmic
Pin-Priority: 991
Package: php5-mcrypt
Pin: release a=karmic
Pin-Priority: 991
Package: php5-mysql
Pin: release a=karmic
Pin-Priority: 991
Package: php5-gd
Pin: release a=karmic
Pin-Priority: 991
Package: php5-curl
Pin: release a=karmic
Pin-Priority: 991
Package: php5-imagick
Pin: release a=karmic
Pin-Priority: 991
Package: php5-ffmpeg
Pin: release a=karmic
Pin-Priority: 991
Package: php5-cli
Pin: release a=karmic
Pin-Priority: 991
* now you can continue with the normal installation instructions and you will end up with PHP 5.2 instead of 5.3.
Comments
http://localhost and VirtualDocumentRoot vs. DocumentRoot
I've followed this guide step by step, and got it working (Ubuntu 8.04; btw I am still quite new to both Ubuntu and Drupal). I still have two questions though:
When I setup a http://domain.localhost everything works, but when I try http://localhost I get a "Not Found - The requested URL / was not found on this server." error. Is this expected with this setup, or should I change some configuration? I did put an index.html in the ~/workspace/ folder.
Second question, could you explain why in step 3 we use "VirtualDocumentRoot /home/USER/workspace/%1/" while in step 4 it's just "DocumentRoot ..."?
And thanks for the howto! Cheers, Arjan
You must use this to import
I think this should be:
You must use this to import phpmyadmin's apache.conf file. Add this to /etc/apache2/apache2.conf
It's a wiki - be bold
I made this update, but It's a wiki - please make any corrections you feel help.
--
mike stewart { twitter: @MediaDoneRight | IRC nick: mike stewart }
ubuntu install_drupal script - first cut
The purpose of this script is to install drupal in user space on an Ubuntu server with LAMP installed.
usage: install_drupal user pass domain dbpass dbname
http://domain/ brings up Drupal's installer
Suggestions solicited.
# Remember to add your new domain to /etc/hosts
I struggled with this formula over too many hours and too many other posts until I applied a comment in Step 3 (which says "If you want, you can skip this part..."). Perhaps Step 3 can be skipped but the comment is important. That is, I needed to add my new domains created in Step 4 to the /etc/hosts file.
Step 4 should include the comment "Remember to add your new ServerName to /etc/hosts for 127.0.0.1".
Also, in Step 6, I did not "dissite" (disable site) the default but rather edited the default to point to my new DocumentRoot.
Be bold? I'm too new to vhosts to lead someone astray.
phpmyadmin
does any one know where i can find the phpmyadmin with this setup..or..what the supposed path might be?
lol...edit a wiki, we would all be lost if i did something like that. what do they say, The blind leading the blind.
http://example.com/phpmyadmin
For me, it comes up at htp://example.com/phpmyadmin Be sure you follow the instructions above about adding the Include to your httpd.conf file.
knaddison blog | Morris Animal Foundation
accessing vmware 'guest' virtual host from vista vmware 'host'
Hi all, I installed ubuntu 8.04 server edition as a guest on a vmware server with vista as the host and follow the instructions above. I can get into my default site using the ip(with default enabled) but not on any other hostname created as per the instructions above.
I hope someone could shed some light on trying to figure this out. I could also get into myphpmyadmin at http://ipaddress/phpmyadmin but not anywhere else.
Really appreciate any feedback. TQ
Updates
I found the solution for this and as I had expected, it can't be that hard. Just need to edit the host file inside windows host for it to refer to the virtualhost located inside the vmware linux client.
Here is the guide to edit your windows host file http://maximumpcguides.com/windows-vista/edit-the-windows-vista-hosts-file/
I ended up running this example with linuxmint instead of ubuntu(but they're based on the same distribution) so I can cheeck it inside linuxmint just to make sure.
OMG Thanks!
I was really stuk on this ... I am virtualizing ubuntu 8.10 server within vista ... I kept messing with the dns rig within ubuntu ...which gave me nothing, I couldnt get localhost to work. lol I didnt even realize there was a vista hosts file...Thanks for the tip off!
Just wanted to add that I
doh! .. I guess thats not it. inxnay that.. >_<
Set-up does not work as it should
I followed the above instructions to the letter to set up a development server on Ubuntu 8.1.
There are two problems:
When I browse either http://mydomain.localhost.drupal-6.9 or http://mydomain.drupal-6.9 as suggested above, I get an "Address not found error". But when I place drupal-6.9 in workspace/mydomain/drupal-6.9 and use http://mydomain.localhost/drupal-6.9/ then drupal runs.
Clean URLs are locked in the disabled mode. I cannot change it, and the instructions found at the clean URL instructions do not help much.
Any ideas?
Clean URLs disabled
I have the same problem with Clean URLs being disabled. Everything else seems to work fine for me so far. Also I am using Ubuntu 9.04.
Are Clean URLs working for everyone else?
Clean URLs issues revealed
I feel kinda silly but I figured out why Clean URLs weren't working for me. First, I didn't copy over the .htaccess files with the rest of the files. For a linux newbie like me this might trip some people up. In order to copy the hidden files I used the command
cp -R /from/dir/.??* /to/dir
. DON'T usecp -R /from/dir/.* /to/dir
because that will copy all the files from the parent directory as well.Secondly, if you are trying to use mod_rewrite in conjunction with a VirtualDocumentRoot (instead of a DocumentRoot) then you'll have to modify the root drupal .htaccess file. In that file uncomment the line
# RewriteBase /
so that it looks likeRewriteBase /
. This is right under the comments that explains VirtualDocumentRoot issues. This change is only required for sites under the localhost setup because that is the setup that uses VirtualDocumentRoot.Finally, I can verify that the this tutorial works great for Ubuntu 9.04 except for the .htaccess change that is also required for localhost setups.
.6 at the end?
From what I understand, this setup requires a .6 (or .5 or .4, etc) at the end of the url of every site you develop. It also requires a .6 at the end of each sites folder name, correct? This causes some problems when moving a locally developed site (example.6) to a live server (example.com), since any module that saves filepath info to the database (such as CCK's FileField) will have broken links. I'm guessing I must have misunderstood or there must be an obvious way around this.
symlink
Yes, it requires a .6 (or .5 or .4, etc) at the end of the url and at the site folders placed in /sites. But one obvoius circumvent is to use symlinks.
So I used to set up the folders with real site name like sites/www.example.com and then set a symlink to sites/example.d6 if I use Drupal 6.x. Later then I can move the sites/www.example.com folder to the live server, and can left the symlink at development server.
To set a symlink, switch to the site folder and:
ln -s www.example.com example.6
.6 at the end - solutions?
Hi,
mattgilbert, did you solve this issue? It is troubling me as well. For example, if I create thumbnails using imagecache on my development server, they won't be available when I move the site folder from my workspace to the production server because of path issues related to the .6 appended to the domain name (because it will be .com not .6). I tried doka's solution using symlinks but I think I misunderstood... Did you ever solve this problem to your satisfaction? Thanks,
Otosi
Forget ".6". Also forget "www."
The way i got around it is to make a symlink for "http://example.com" on my local setup instead of "http://www.example.com". URLs like:
"http://example.com/sites/example.com/files/imagecache/whathaveyou/image.jpg"
and
"http://www.example.com/sites/example.com/files/imagecache/whathaveyou/image.jpg"
cause no conflicts, so this works out fine. This may depend on having a host that resolves "http://example.com" to http://www.example.com", but this seems to be common practice. (Can anyone verify?)
As a bonus, when I'm at my development computer, whenever I go to a page at "http://example.com" I get my local version, but if I go to "http://www.example.com" I get the live version from "out there". Pretty handy if you want to compare a live site to a local development version quickly. I'm guessing if your site has subdomains like http://subdomain.example.com, there might be an issue, but I never mess with those.
I hope this helps.
Thanks for the Tip
Thanks mattgilbert for getting back with a response, I appreciate it. Yes, I too have used the "no www for dev approach" - I agree that it's very useful. I think there can sometimes be a conflict depending on your drupal .htaccess configuration to rewrite all traffic from www. to no subdomain, or vice versa - take a look at your .htaccess file to see what I mean.
Seems like a shame to not follow this tutorial to the letter, but for me it's more important that I can build a site locally and then move it reliably to production without path problems, than it is to append .6xx to test different versions of drupal. Naturally, I would prefer to be able to do both! I tested, and it definitely does not work for me if I create a gallery with imagecache, for example. If I do so with the stock configuration from this tut, I end up with ".6xx" in the paths to the images. As soon as I move the file directory, there are considerable path problems. It's entirely possible (likely) I am missing a simple solution to this problem. Please, if any of you have solved a similar issue, I would really like to learn how you did it. Thank you for this great tutorial, by the way. I still learned quite a bit from it.
Otosi
Instructions not good for real sites
These instructions shouldn't be followed if you want to develop a real site for others to visit.
Instead check out drupal's multi-site feature. That uses the same drupal codebase for multiple
virtual domains.
You create subfolders under /sites/domain1.edu /sites/domain2.edu etc., and create a separate mysql database for each sub-site to store data:
http://drupal.org/getting-started/6/install/multi-site
real site
yes, it is for development purposes, as stated in its title :)
yep
I know, I'm the one who changed the title :)
@dugh: What are you talking
@dugh: What are you talking about! Did you read the instructions? I have set up multiple sites in this way in my local development environment and have no problems moving them to live server where thousands of real people access them daily.
--
Tom
www.systemseed.com - drupal development. drupal training. drupal support.
Modules Like Imagecache
In particular, I'm referring to modules like imagecache. Do you use it on any of your sites?
Can you explain why this is not good for real sites?
Why can't you use above instructions for a real site that others visit?
You said instead to use drupal's multisite feature. However, isn't that exactly what these instructions are setting you up for? I suppose there may be other reasons not to use this for live sites?
thanks
I am getting the following
I am getting the following output
* Restarting web server apache2
[Sat Jul 04 11:55:31 2009]
[warn]
The Alias directive in /etc/apache2/conf.d/phpmyadmin.conf at line 3 will probably never match because it overlaps an earlier Alias.
[Sat Jul 04 11:55:31 2009]
[warn] NameVirtualHost *:80 has no VirtualHosts
... waiting [Sat Jul 04 11:55:32 2009] [warn] The Alias directive in /etc/apache2/conf.d/phpmyadmin.conf at line 3 will probably never match because it overlaps an earlier Alias.
[Sat Jul 04 11:55:32 2009] [warn] NameVirtualHost *:80 has no VirtualHosts
How do I go about troubleshooting this? (newbie ere)
Can you explain why this is not good for real sites?
kdebass has a good question?
what are the top 3 differences that do not help making Drupal a deployable system?
Kind Regards,
Jorge.
there are some hints here:
there are some hints here: http://groups.drupal.org/node/24230
Doka
Bash scripts to create/remove sites
I wrote some quick bash scripts to automate the process of adding/removing new sites. This script assumes you have followed the above tutorial and setup at least one site successfully.
Once you have your setup working you can use this script as follows:
/usr/bin/createsite
, being sure to change the username variable at the topusername="nicholas"
to whatever your username is.#!/bin/bash
username="nicholas"
sitename=${1}
fdata="<VirtualHost *>\n ServerName ${sitename}\n ServerAlias ${sitename} *.${sitename}\n DocumentRoot /home/${username}/workspace/${sitename}/\n</VirtualHost>"
sudo sed -i "s/127.0.0.1 localhost/127.0.0.1 localhost\n127.0.0.1 ${sitename}.localhost/" /etc/hosts
sudo mkdir /home/${username}/workspace/${sitename}
sudo chmod 777 /home/${username}/workspace/${sitename}
sudo sh -c "echo \"${fdata}\" >> /etc/apache2/sites-available/${sitename}"
sudo a2ensite ${sitename}
sudo /etc/init.d/apache2 restart
chmod 777 /usr/bin/createsite
createsite yoursitename
from the command line.That's it, everything gets taken care of for you.
Here is another version for removing a site. Be careful as this one removes the entire directory that the site you are removing is in.
Repeat steps in previous script but with the file removesite
/usr/bin/removesite
, being sure to change the username variable at the topusername="nicholas"
to whatever your username is.#!/bin/bash
username="nicholas"
sitename=${1}
sudo sed -i "/127.0.0.1 ${sitename}/d" /etc/hosts
sudo rm -rf /home/${username}/workspace/${sitename} /etc/apache2/sites-available/${sitename}
sudo a2dissite ${sitename}
sudo /etc/init.d/apache2 restart
chmod 777 /usr/bin/removesite
removesite yoursitename
from the command line.Los Angeles web design for Drupal
Not working no my side
for me script is not creating the new entry in /etc/hosts
i have vanilla setup, just with the tutorial entry and ip6 stuff in there.
BTW: is it safe to chmod 777 the site dir ?
does your /etc/hosts file
does your /etc/hosts file have a line that says:
127.0.0.1 localhost
? If not you will need to change that to match something that you would like to insert the new line after. Something likesudo sed -i "s/YOUR NEW LINE/YOUR NEW LINE REPEATED\n127.0.0.1 ${sitename}.localhost/" /etc/hosts
That would be the most likely reason it wouldn't work.
For the chmod, yes a 750 would probably be better. But it is on localhost and really shouldn't matter IMO.
Los Angeles web design for Drupal
could someone clean this up?
I'm trying to get this running on a clean virtualbox ubuntu 9.04 desktop. So far it is going fine, but this tutorial is kinda messy.
My goal was to quickly get a vm ready and copy a live site so I can toy with it.This tutorial is already a great step, perhaps I'll edit it myself if I get some more experience. Maybe when 9.10 is there.
Currently I seem to have everything running, but there is something wrong with the sessions. I get all these &token=fffcfa5725217dcae70304627cd80405 urls, which are not there in the live site (and I can't login..).
Too complex
I agree. These instructions are far too complex and user-specific (i.e. they work for a few users only). Besides, they are outdated. They don't work for me on newer versions. I use the instructions in the main Drupal website (multi-site) instructions instead.
Ubuntuguide.org and Kubuntuguide.org
What about migration from this dev config to a production system
I was hoping to see how folks were developing on one system, and then moving it over to the prod system.
I'll admit, I have a multi-site setup already going on my development system (I didn't use the above instructions, as I only saw this thread today - but they seem valid).
My largest concern in using Drupal, is the work-flow. I'm a bit of an 'old-school' web hacker, who started using notepad and Mosaic a long time ago... well I guess - perhaps - I'm just old (by the new standards) ;) I'm still young by the old standards. :)
Anywho...
These days I usually develop on a dev box, and then copy the files onto the live box after (hopefully) sufficient testing. Since I have a split between files and MySQL data in my drupal dev site, I'm wondering if there is a quick formula for exporting and importing a site from my dev system to my prod system, respectively.
Since most of the content will be generated on the live system, as soon as I go live with a site; my dev system is out of date. It would almost seem like I would need to take my live system off-line (I know there is a feature to do this, I've experimented with it) copy my database down to my dev box (not sure if there is any way to do this other than some SQL wizardry) - make development changes, and reverse the process to get everything back up on the prod/live system.
The majority of changes I would be making are probably not even in the db. I imagine any/most changes would be to the layout via CSS and/or PHP. But without the previously live data to test against - I might find things don't line up the way I think they will, etc. I have information and tutorials for making all the changes I'll need to make. I'm just missing the workflow part of dev to live and back again.
If I was an old hand at Drupal, I would probably know exactly where everything is stored, but I'm still relatively new to this CMS.
I have no doubt I can come up with a solution - but I'm hoping someone else already has done this.
Any suggestions are welcome, and in fact, solicited.
Metajunkie
Dirty solution
You could edit your settings.conf in your dev drupal install to pull the sql data from the live server instead of the dev server. To ensure you don't accidentally make any changes to the live site, could set up a new user in the MySQL that can access but not write over the database.
Simplified Vhost entry
As an alternative, wouldn't it be simpler to just add this as a single virtual host entry?
<VirtualHost *>
ServerName localhost
ServerAlias localhost *.localhost
VirtualDocumentRoot /home/username/workspace/%-1/%-2/
</VirtualHost>
site1.head.mydomain == ~/workspace/mydomain/head
Which allows you to have multiple versions and multisite installs.
complete tutorial for Ubuntu 10.10
There is a complete tutorial on setting up LAMP server, enabling mod_rewrite and VirtualHosts is available at
http://amritbera.blogspot.com/2010/11/ubuntu-1010-lamp-installation-apac...
Thanks
both drupal 5 6 and 7
i want to upgrate a site from drupal 5 to 6 on my machine ,
drupal 5 needs php 5.2.x , drupal 6 needs php 5.3.x so what should i do if i need both php versions
i want to install php 5.2 , without removing php 5.3 , how do i do it ?
is there a way to set the php version to 5.2 just to one site ?
i have ubuntu 10.10 the machine has been installed with drubuntu script, php version is 5.3.3
I had the same problem with
I had the same problem with 10.04 and this is how I solved it.
http://webpagedeveloper.me/blog/ubuntu-1004-lucid-lamp-server-running-ph...
HI all, awesome script on the
HI all,
awesome script on the ubuntu forum
http://ubuntuforums.org/showthread.php?p=9201854#post9201854
I downgraded from ubuntu 11.10 server
thank you