How to install / set up Apache, PHP 5.2, MySQL (LAMP) Development Environment for Drupal on Ubuntu 10.04 Lucid Lynx
Downgrading PHP to version 5.2
Why Downgrade?
Ubuntu 10.04 repositories, by default, have PHP version 5.3.
PHP 5.3 comes with a lot many improvements. But there are still many Drupal Third Party Modules which are yet to be ported to PHP 5.3, and so happens that Drupal 6 is not yet ready for PHP 5.3.
Till that is done (would take quite some time to happen), we would have to resort to downgrade to PHP 5.2.
How to Downgrade?
Of many known methods on the internet, I find the following method to work without much issue:
The following repository contains a set of PHP 5.2 .debs compiled specifically for Ubuntu 10.04.
Issue the following command at the command line prompt (terminal).
sudo add-apt-repository ppa:txwikinger/php5.2
Now, we have to 'pin' the package manager to use PHP version 5.2.
For that, first, create the file /etc/apt/preferences.d/php as follows:
sudo gedit /etc/apt/preferences.d/php
Next, copy-paste the following content:
Package: libapache2-mod-php5
Pin: version 5.2.10*
Pin-Priority: 991
Package: libapache2-mod-php5filter
Pin: version 5.2.10*
Pin-Priority: 991
Package: php-pear
Pin: version 5.2.10*
Pin-Priority: 991
Package: php5
Pin: version 5.2.10*
Pin-Priority: 991
Package: php5-cgi
Pin: version 5.2.10*
Pin-Priority: 991
Package: php5-cli
Pin: version 5.2.10*
Pin-Priority: 991
Package: php5-common
Pin: version 5.2.10*
Pin-Priority: 991
Package: php5-curl
Pin: version 5.2.10*
Pin-Priority: 991
Package: php5-dbg
Pin: version 5.2.10*
Pin-Priority: 991
Package: php5-dev
Pin: version 5.2.10*
Pin-Priority: 991
Package: php5-gd
Pin: version 5.2.10*
Pin-Priority: 991
Package: php5-gmp
Pin: version 5.2.10*
Pin-Priority: 991
Package: php5-ldap
Pin: version 5.2.10*
Pin-Priority: 991
Package: php5-mhash
Pin: version 5.2.10*
Pin-Priority: 991
Package: php5-mysql
Pin: version 5.2.10*
Pin-Priority: 991
Package: php5-odbc
Pin: version 5.2.10*
Pin-Priority: 991
Package: php5-pgsql
Pin: version 5.2.10*
Pin-Priority: 991
Package: php5-pspell
Pin: version 5.2.10*
Pin-Priority: 991
Package: php5-recode
Pin: version 5.2.10*
Pin-Priority: 991
Package: php5-snmp
Pin: version 5.2.10*
Pin-Priority: 991
Package: php5-sqlite
Pin: version 5.2.10*
Pin-Priority: 991
Package: php5-sybase
Pin: version 5.2.10*
Pin-Priority: 991
Package: php5-tidy
Pin: version 5.2.10*
Pin-Priority: 991
Package: php5-xmlrpc
Pin: version 5.2.10*
Pin-Priority: 991
Package: php5-xsl
Pin: version 5.2.10*
Pin-Priority: 991
Save the file and exit from the text editor.
Then, reload the package information using the following command:
sudo apt-get update
Package Installation
First, install the following set of packages:
sudo apt-get install apache2 mysql-server php5 libapache2-mod-php5 php5-gd php5-mysql mysql-admin mysql-query-browser mysql-client mysql-navigator php5-cli php5-curl kcachegrind php5-ffmpeg
During the installation of the above packages, you will be prompted to enter the password for the 'root' user for configuring MySQL.
New password for the MySQL "root" user: <-- yourrootsqlpassword
Repeat password for the MySQL "root" user: <-- yourrootsqlpassword
Next, when prompted to select the 'Web Server reconfigured', select apache2.
To install phpMyAdmin, we would also need the php5-mcrypt extension.
Since the above repository doesn't have php5-mcrypt, we would have to download the package from packages.ubuntu.com/hu/karmic/i386/php5-mcrypt/download, and then install it manually as follows:
wget http://mirrors.kernel.org/ubuntu/pool/universe/p/php-mcrypt/php5-mcrypt_...
sudo dpkg -i ./php5-mcrypt_5.2.6-0ubuntu2_i386.deb
Now, we can install phpMyAdmin.
sudo apt-get install phpmyadmin
(Note: php5-xdebug, php5-imagick packages require some additonal dependency satisfaction, and if not required specifically, it would be better to leave them uninstalled).
Starting, Stopping and Restarting the Apache2, MySQL daemons (services/"servers")
Keep the following commands handy to control your Apache, MySQL daemons.
To start the apache service:
sudo /etc/init.d/apache2 start
To stop apache service:
sudo /etc/init.d/apache2 stop
To restart the apache service:
sudo /etc/init.d/apache2 restart
Similarly, the equivalents for the MySQL daemon are as follows:
sudo /etc/init.d/mysql start
sudo /etc/init.d/mysql stop
sudo /etc/init.d/mysql restart
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.conf file 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_rewrite module enabled, to allow Clean URLs.
To enable the apache mod_rewrite module, issue the following set of commands at the terminal:
cd /etc/apache2/mods-enabled
sudo ln -s ../mods-available/rewrite.load
sudo /etc/init.d/apache2 reload
3. Change some common php.ini Settings
You might want to make the following changes in /etc/php5/apache2/php.ini:
sudo gedit /etc/php5/apache2/php.ini
Changes:
Change memory_limit = 16M to memory_limit = 128M
Change upload_max_filesize = 2M to 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/www to /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_userdir module for Apache, otherwise you need to set up symlinks from /var/www/. We prefer to go the mod_userdir way, which seems a more well defined solution.
To enable mod_userdir, issue the following commands in terminal:
sudo a2enmod userdir
sudo /etc/init.d/apache2 reload
Now create the public_html folder under your home folder, and restart apache services.
mkdir ~/public_html
sudo /etc/init.d/apache2 restart
Next, make the following changes in /etc/apache2/sites-available/default:
sudo gedit /etc/apache2/sites-available/default
CHANGES:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
# DocumentRoot /var/www ---->> changed to
DocumentRoot /home/ENTER_YOUR_USERNAME_HERE/public_html
<Directory />
Options FollowSymLinks
# AllowOverride None ---->> changed to
AllowOverride All
</Directory>
# <Directory /var/www/> ---->> changed to
<Directory /home/ENTER_YOUR_USERNAME_HERE/public_html/>
Options Indexes FollowSymLinks MultiViews
# AllowOverride None ---->> changed to
AllowOverride All
Restart the apache service to effect the changes:
sudo /etc/init.d/apache2 restart
That should do the job for you.
Happy Computing!!!
TODO: Find some way to make this looooong document a bit easier to browse through.
- 214232 reads
Comments
Anonymous (not verified)
Wed, 07/14/2010 - 09:26
Permalink
Thank You!
Very useful post.
Thank You!
Anonymous (not verified)
Wed, 07/14/2010 - 13:33
Permalink
Aliya kido
Aliya very useful post. Nice work
Mustafa Ashraf ... (not verified)
Thu, 04/28/2011 - 17:26
Permalink
Its rocking! To the point
Its rocking!
To the point document. I only want to add that in case you encounter error while running "sudo add-apt-repository ppa:txwikinger/php5.2" don't worry.
Run the following command to install it"sudo apt-get install python-software-properties"
Thanks,
Ashraf
ZEOXE (not verified)
Fri, 05/13/2011 - 16:54
Permalink
Very Useful post
Very Useful post
Thanks Dude!
Add new comment