Install LAMP web server and Drupal 7 in Ubuntu

Install LAMP web server and Drupal 7 in Ubuntu

Installing a web server is very easy in Ubuntu, just enter a few lines in the terminal: There is no need to install and configure each part of a LAMP (Linux-Apache-MySQL-PHP) installation individually. You can also install other programs this way. The downside is that all components are installed automatically, and not reviewed by you. But as long as you only use the web server locally (localhost or, and don't open up for access from the Internet, it should be safe.

Install Ubuntu and LAMP web server

First, install Ubuntu, if you haven't already. There is a good guide over at HowtoForge Just follow the guide ("The Perfect Desktop - Ubuntu 10.04" is the latest), do the update on page 3, and then return here.

To install a LAMP web server, enter this in a terminal and enter your password:

sudo tasksel install lamp-server

After a while the installation process will prompt you for a password for the MySQL server. Make sure that the CAPS Lock button is not activated! If all goes well, the installation will return to the terminal, and the web server is installed. Test this by going to your browser and enter http://localhost/ in the address bar. If the installation was successful, you will see an "It works!" message.

Update php.ini - allow big files, avoid memory issues

To allow importing large sql dumps through phpmyadmin, and avoiding time outs during demanding requests, it is also necessary to update the php.ini file of the Apache server. To open up the php.ini in gedit, enter this in your terminal:

gksudo gedit /etc/php5/apache2/php.ini

...and update the values five places, where it says:

max_execution_time = 120
max_input_time = 90
memory_limit = 96M
post_max_size = 150M
upload_max_filesize = 150M
session.gc_maxlifetime = 14400

Fix Apache Error "Could not reliably determine the server’s fully qualified domain name, using for ServerName"

Open the httpd.conf file:

sudo gedit /etc/apache2/httpd.conf

The httpd.conf file is blank, so add the following to the file, and then save it:

ServerName localhost

Create a MySQL database

To create a database in the MySQL database, log in to the MySQL shell:

mysql -u root -p

Create a database, for a Drupal installation in this example, type in the MySQL shell:

create database drupal7;

Create a new user and grant all permissions, substitute "newuser" and "password" with your values:

grant all on drupal7.* to 'newuser'@'localhost' identified by 'password';

and leave the shell:


If you typed in the password(in this example, "ROOT") accidentally with caps lock on, this is how you change it to something safer. "root" is NOT recommended as password. From the terminal:

mysqladmin -u root -p'ROOT' password 'yournewpassword'

Install phpmyadmin

You can also create and administer your MySQL databases through phpmyadmin:

sudo apt-get install phpmyadmin

Administer your databases at http://localhost/phpmyadmin/

Install and enable mod_rewrite

Install mod_rewrite, to get nice URL's:

sudo a2enmod rewrite

Enable mod_rewrite:

gksudo gedit /etc/apache2/sites-available/default

...and change "AllowOverride None" to "AllowOverride All", around line 11:

<Directory /var/www/\>
Options Indexes FollowSymLinks MultiViews
AllowOverride All

Restart the Apache web server:

sudo /etc/init.d/apache2 restart

Install Drupal 7

1. Start nautilus up with this command:

gksudo nautilus

...and navigate to the /var folder, right-click on the www folder, click 'Permissions' and set owner and group to your own user name. This will prevent problems with automatically created folders in the future.

2. Download and extract Drupal 7 from Rename the folder to drupal7 and move it to /var/www/ where the web sites of the Apache web server reside. Result: /var/www/drupal7

3. Create the files folder, like this: /var/www/drupal7/sites/default/files. Right-click the 'files' folder, select 'Properties' -> 'Permissions' and under 'Others', set 'Folder Access' to 'Create and delete files'

4. Make a copy of the default.settings.php file in /var/www/drupal7/sites/default and rename it to settings.php. Right-click settings.php, select 'Properties' -> 'Permissions' and under 'Others', set 'Folder Access' to 'Create and delete files'

NOTE: Add an exception in Firefox, if you have disabled "Accept cookies from sites" and unblock the new site if you have a script blocker activated in your browser.

If all went well, you should now be able to enter http://localhost/drupal7 and install Drupal.

Install Drupal 7 from the command line

In stead of pointing and clicking with the mouse, you can do the above from the command line, much faster.

Download, un-tar the Drupal files, and delete the tarball. To find the latest version of Drupal, go to :

tar -zxvf drupal-7.4.tar.gz
rm drupal-7.4.tar.gz

Move and rename the downloaded Drupal folder to your localhost directory, normally /var/www/, create a settings.php file and make it writable, as well as the sites/default folder.

sudo mv drupal-7.4/ /var/www/drupal7
cd /var/www/drupal7
cp sites/default/default.settings.php sites/default/settings.php
chmod a+w sites/default/settings.php
chmod a+w sites/default

If all went well, you should now be able to go to http://localhost/drupal7 and install Drupal.

Next, secure your site with these commands. Make sure you are in the right directory (your Drupal folder), otherwise you can mess up your entire file system. Substitute "ras" with your username.

From the Drupal root directory:

cd /var/www/drupal7
sudo chown -R ras:www-data .
find . -type d -exec chmod u=rwx,g=rx,o= {} \;
find . -type f -exec chmod u=rw,g=r,o= {} \;

Permissions for the "files" directories in the sites:

cd /var/www/drupal7/sites

Copy and paste the next 5 lines into the terminal, they will all be executed after the "done" line:

for d in ./*/files
find $d -type d -exec chmod ug=rwx,o= {} \;
find $d -type f -exec chmod ug=rw,o= {} \;

From these two pages:
Quick install for developers (command line)
Securing file permissions and ownership

Install PHP APC, to speed up the server

On Ubuntu 10.04 Lucid:

sudo apt-get install php-apc

On Ubuntu 9.10 Karmic:
Install apache2-threaded-dev:

sudo apt-get install apache2-threaded-dev

Install APC:

sudo pecl install apc


gksudo gedit /etc/php5/apache2/php.ini

...and paste in the file:

and save it.

Restart the Apache web server:

sudo /etc/init.d/apache2 restart

Place a file called info.php in /var/www -- containing:

<?php phpinfo(); ?>

Visit http://localhost/info.php, and verify that APC is enabled.

Setting up a virtual host

To set up a virtual host, allowing you to enter just http://drupal7/ in stead of http://localhost/drupal7/:

sudo gedit /etc/hosts

...and add: drupal7

To define where the Apache web server should be looking for the files:

gksudo gedit /etc/apache2/httpd.conf

...and add:

<VirtualHost *:80>
DocumentRoot /var/www/drupal7
ServerName drupal7

As always, when you change the set up of the Apache server, restart it:

sudo /etc/init.d/apache2 restart

Move apache webroot from /var/www to your /home directory and move MySQL folder

For back up reasons and to have a more "normal" work flow when adding files to your web site, you can move the apache webroot from /var/www to /home/USERNAME/.www -- the .www folder will be hidden until you press Ctrl+H to unhide it:

gksu gedit /etc/apache2/sites-available/default

Change DocumentRoot /var/www to DocumentRoot /home/USERNAME/.www

If you have set up a virtual host:

gksudo gedit /etc/apache2/httpd.conf

...and change to: DocumentRoot /home/USERNAME/.www

Likewise, to move MySQL from /var/lib/mysql to /home/USERNAME/.mysql follow this guide:

Install Drush

With Drush you can install modules and update Drupal from the command-line:

tar xvzf drush-6.x-3.3.tar.gz
sudo chmod 555 drush/drush
sudo chown -R root:root drush
sudo mv drush /usr/local/
sudo ln -s /usr/local/drush/drush /usr/local/bin/drush
sudo drush dl drush_make

If you get an "exec: 53: php: not found" error after running the last line ("sudo drush dl drush_make") you might have to install the PHP command line interface, with

sudo apt-get install php5-cli


Extra: Programs and fonts to install after Ubuntu installation

You can install programs very easily in Ubuntu, from the command line. These are some nice programs to install after an Ubuntu install, copy and paste in the terminal:

sudo apt-get install audacious dia epiphany-browser filezilla gparted gqview k9copy klinkstatus lm-sensors sensors-applet macchanger meld regexxer thunar thunderbird unetbootin unrar vim-gnome vlc

Install Multimedia Codecs:
To play file types, like mp3, avi and mov, you need to install some extra tools and codecs. To install them, paste in the terminal:

sudo apt-get install ubuntu-restricted-extras

After that, go to Applications > Add/Remove..., select Show: "All available applications", search for "gstreamer" and install them.

For a more thorough walk through of how to set up a fresh Ubuntu installation: The Perfect Desktop - Ubuntu 9.10 (Karmic Koala)

Audio CD Extractor (Sound Juicer) settings for a bitrate of 256 kbps:
Edit > Preferences > Output Format: Edit Profiles > New
Profile Name: CD Quality, better
Gstreamer Pipeline: audio/x-raw-float,rate=44100,channels=2 ! vorbisenc name=enc quality=0.8 ! oggmux
File extension: ogg

Install fonts:

sudo apt-get install ttf-sil-gentium ttf-dustin ttf-georgewilliams ttf-sjfonts sun-java6-fonts ttf-larabie-deco ttf-larabie-straight ttf-larabie-uncommon

Enable firewall and open up port for Transmission:

sudo ufw enable


sudo ufw allow 53484


Thanks for a great 'how to'!

"3. Create the files folder, like this: /var/www/drupal7/sites/default/files, right-click the files folder, select 'Properties' -> 'Permissions' and set 'Others' to 'Create and delete files'"

When I right click the files folder I just made, I don't have the option 'Others' in my drop down menu. I can choose nobody or my own name.

Do you have a suggestion why this is?

Sorry, I forgot to write where you have to change the permissions. I have updated the text:
"3. Create the files folder, like this: /var/www/drupal7/sites/default/files. Right-click the 'files' folder, select 'Properties' -> 'Permissions' and under 'Others', set 'Folder Access' to 'Create and delete files'"

Hi there nice startup guide i had a little problem with getting phpmyadmin to work

I needed to run the following command

ln -s /usr/share/phpmyadmin/ /var/www

hope this helps !!

Thanks for the very well written instruction. Can you make recommendations as to how to edit config files on a Ubuntu server install. Should I edit them on a different computer then copy to the server and overwrite the files with my modified versions or is there a method I am unfamiliar with having just took the plung into the no-gui deep end?

The instructions on this page are mostly geared towards setting up a local LAMP environment with a GUI, but I can recommend the info found at Linode's library:

You typically use an editor like nano, which runs in the terminal, to edit text files, like config files, for example:
'sudo nano /etc/apache2/sites-available/default'

The instructions at Linode's library are very detailed and can be used for setting a server up at any hosting service. It might look a bit complicated at first, but after a while it gets easier and almost second nature to use the terminal in stead of a GUI, good luck!

!!!!!1 Great, detailed, Granular step by step and proactive explanation ..... !!!!