Setting up a LAMP (Apache, MySQL, PHP) development environment on Ubuntu 11.04 (Natty) / 11.10 (Oneiric) 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-admin mysql-query-browser mysql-client mysql-navigator 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 127.0.1.1 for ServerName

FIX:

sudo gedit /etc/apache2/httpd.conf

By default apache's httpd.conffile will be blank. Now, simply add the following line to 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
"http://www.example.com/?q=node/83".

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

Changes:

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
        </Directory>
    </IfModule>

so that the file now looks like this:

<IfModule mod_php5.c>
    <FilesMatch "\.ph(p3?|tml)$">
    SetHandler application/x-httpd-php
    </FilesMatch>
    <FilesMatch "\.phps$">
    SetHandler application/x-httpd-php-source
    </FilesMatch>
    # 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>
    #</IfModule>
</IfModule>

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
                </Limit>
                <LimitExcept GET POST OPTIONS>
                        Order deny,allow
                        Deny from all
                </LimitExcept>
        </Directory>
</IfModule>
 

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.)

Comments

Thanks for the cool post.

Everything worked perfect for me. But when I copied a Drupal core installation to the public_html folder, I am unable to view it when I enter http://localhost in my browser. I get this message

"It works!

This is the default web page for this server.

The web server software is running but no content has been added, yet."

Please help.

Mubashir,
Please try the following URL instead:
http://localhost/~mubashir/
where mubashir is your username (please modify accordingly as per your linux username).
Cheers,
Anto

Add new comment

randomness