Setting up a LAMP (Apache, MySQL, PHP) development environment on Ubuntu 13.04 (Raring) / 12.10 (Quantal) / 12.04 (Precise) for Drupal/Wordpress development

Setting up a LAMP (Apache, MySQL, PHP) development environment on Ubuntu 11.04 (Natty) / 11.10 (Oneiric) for Drupal/Wordpress development

Package Installation
From Terminal, execute the following command to install the required packages:

sudo apt-get install apache2 mysql-server mysql-client php5 libapache2-mod-php5 php5-gd php5-mysql php5-cli  php5-curl kcachegrind  php5-ffmpeg php5-mcrypt php5-imagick php5-xdebug phpmyadmin

Additional Configuration

1. To fix the Fully Qualified Domain Name issue for Apache

After the installation, apache might show the following error (Try restarting the apache server):

sudo /etc/init.d/apache2 restart
apache2: Could not reliably determine the server's fully qualified domain name, using for ServerName


sudo gedit /etc/apache2/apache2.conf

Now, simply add the following line to the end of the file.

ServerName localhost

Save the file and exit from gEdit.
Now restart the apache server for the change to take effect:

sudo /etc/init.d/apache2 restart

2. To enable the mod_rewrite apache module (for "Clean URLs")

By default, Drupal uses and generates URLs for your site's pages that look like

This style of URLs can be hard to read, and can prevent some search engines from indexing all the pages of your site.

To facilitate easy readability, and to improve search engine friendliness, it is generally advisable to enable the Clean URL functionality. Drupal supports Clean URLs and requires that the web server also includes support for the same. Apache needs the mod_rewritemodule enabled, to allow Clean URLs.

To enable the apache mod_rewritemodule, issue the following set of commands at the terminal:

sudo a2enmod rewrite
sudo /etc/init.d/apache2 restart

3. Change some common php.iniSettings

You might want to make the following change in /etc/php5/apache2/php.ini:

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


Change upload_max_filesize = 2Mto upload_max_filesize = 100M

Save the file and exit from gEdit.

Restart apache for the changes to take effect:

sudo /etc/init.d/apache2 restart

4. Changing Document Root from /var/wwwto /home/username/public_html

If you would like to change the apache Document Root from /var/www/to ~/public_html/, you need to use the mod_userdirmodule for Apache, otherwise you need to set up symlinks from /var/www/. We prefer to go the mod_userdirway, which seems a more well defined solution.

To enable mod_userdir,

sudo gedit /etc/apache2/mods-available/php5.conf

Comment out the following lines from /etc/apache2/mods-available/php5.conf:
    <IfModule mod_userdir.c>
        <Directory /home/*/public_html>
            php_admin_value engine Off

so that the file now looks like this:

<IfModule mod_php5.c>
    <FilesMatch "\.ph(p3?|tml)$">
    SetHandler application/x-httpd-php
    <FilesMatch "\.phps$">
    SetHandler application/x-httpd-php-source
    # To re-enable php in user directories comment the following lines
    # (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it
    # prevents .htaccess files from disabling it.
    #<IfModule mod_userdir.c>
    #    <Directory /home/*/public_html>
    #        php_admin_value engine Off
    #    </Directory>

Next, make some changes to userdir.conf:
sudo gedit /etc/apache2/mods-available/userdir.conf

Comment out
AllowOverride FileInfo AuthConfig Limit Indexes
And below that write:
AllowOverride All
so that the file now looks like this:

<IfModule mod_userdir.c>
        UserDir public_html
        UserDir disabled root

        <Directory /home/*/public_html>
                #AllowOverride FileInfo AuthConfig Limit Indexes
        AllowOverride All
                Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
                <Limit GET POST OPTIONS>
                        Order allow,deny
                        Allow from all
                <LimitExcept GET POST OPTIONS>
                        Order deny,allow
                        Deny from all

Then, issue the following commands in terminal:
sudo a2enmod userdir
sudo /etc/init.d/apache2 restart

Now create the public_htmlfolder:

mkdir -p ~/public_html/test
echo "<?php phpinfo(); ?>" > ~/public_html/test/info.php
sudo mkdir /etc/skel/public_html

That should do it. To test whether things are ok,
in your web browser, Browse to the URL: http://localhost/~USERNAME/test/info.php
(Note: replace USERNAME with the actual username.)


Thank you Anto for this wonderful content. It helped me alot. Thanks again.

Add new comment