Install PHP Scripting Language

PHP is the scripting language upon which Drupal is built. Drupal 7 requires PHP version 5.2 or greater, however these instructions will install PHP version 5.3. Note that, as of this writing, many Drupal modules have not been upgraded to work with version 5.3. It may be necessary to back-grade to version 5.2.

You can learn more in the PHP5 Scripting Language section of the Ubuntu Server Guide. The following will walk you through installing all of the PHP packages you need for your Drupal environment. The PHP configuration is stored in /etc/php5/apache2/php.ini.

Install PHP version 5.3:

sudo apt-get -y install php5 libapache2-mod-php5 php5-mysql
sudo apt-get -y install php-pear php5-gd php5-dev php5-cli

Install the uploadprogress PECL library to support Drupal's lovely upload progress bar:

sudo pecl install uploadprogress

Enable the uploadprogress extension in php.ini:

echo "extension=uploadprogress.so" | sudo tee -a /etc/php5/apache2/php.ini

Depending on your requirements, you may need to adjust a few limits in php.ini. Increase PHP's memory limit from 128M to 256M:

sudo sed -i '/memory_limit/s/128/256/' /etc/php5/apache2/php.ini

Increase the maximum post size from 8M to 128M:

sudo sed -i '/post_max_size/s/8/128/' /etc/php5/apache2/php.ini

Increase the maximum upload filesize from 2M to 128M:

sudo sed -i '/upload_max_filesize/s/2/128/' /etc/php5/apache2/php.ini

Finally, let's restart Apache to enable the configuration changes:

sudo /etc/init.d/apache2 restart

Find an error? Know a better way? Please leave a comment and help improve this cookbook.