Besides its success on the desktop, Ubuntu has become a popular server distribution as well. With the release of Hardy Heron 8.04, Canonical is making this release a Long Term Support (LTS) version, with 5 years support on servers.
Many hosting companies offering dedicted and virtual private servers (VPS) offer Ubuntu as an option. That is not a surprise, because Ubuntu provides all the benefits that Debian provides: community maintained, vast repository of software packages, and superior dependency management, with more up to date packages.
Drupal runs best on the LAMP stack (Linux, Apache, MySQL, PHP). This article describes how to setup Ubuntu Server 8.04 LTS for use with Drupal, making sure all the required software is configured, with special tweaks for performance and development.
The article assumes that this is either a dedicated server, or a VPS. The usage of the server can be either a live server, or a development machine.
Installing Ubuntu Server
If you are on a VPS provided by a hosting company, they would have installed Ubuntu for you from images they maintain. Therefore, you can skip this section if you are using a VPS.
Install Ubuntu normally using the installation instructions on Ubuntu's web site.
When you reach the stage of selecting a Package Task, only select OpenSSH server. Do not select LAMP server nor Mail server. We will do those manually later, in order to control exactly what gets installed.
Configuring a Static IP address
Note: If you are on a VPS, skip this section. In fact, you can lose access to your server inadverently if you make a mistake here.
When the system reboots, you need to assign a static address to it if it is a live server.
Edit the file /etc/network/interfaces to be as follows. Replace the IP address in the address and gateway with the correct values.
auto eth0 iface eth0 inet static address 192.168.0.240 netmask 255.255.255.0 gateway 192.168.0.1
Restart the networking stack.
# /etc/init.d/networking restart
If this is a remote server, with no console access, then it is best if you double check the settings and reboot instead of restarting the network.
Update to the latest packages
If you are installing from a CD, then the repository would have updated packages that are more recent than the ones on your CD. Before we install any software, let us make sure that we have the latest packages
# aptitude update && aptitude dist-upgrade
If the upgrade includes new kernel versions, we need to reboot now, so that we don't have to do it later.
# shutdown -r now
Install Apache, MySQL and PHP5
We now proceed with installing Apache, MySQL and PHP5 (the AMP part of the LAMP software stack). This configuration assumes that you will be using mod_php to run PHP as an Apache module. This is suitable for most regular traffic sites. For a more high performance option for higher traffic sites, you may want to run Apache with PHP as fcgid.
For a mail server, we first install postfix as a personal preference. Ubuntu provides exim4 by default. If you are more comfortable with exim4 as a mail server, then skip this step. Ubuntu will install exim4 as part of the LAMP stack automatically.
# aptitude install postfix
When prompted, select "Internet site".
Then we install Apache2:
# aptitude install apache2 apache2-threaded-dev
After that we install the MySQL database server:
# aptitude install mysql-server
When asked for a root password for MySQL, just hit Enter.
And then we follow that by PHP5, PHP5's image handling (gd) and its connection to MySQL:
# aptitude install php5 php5-gd php5-mysql
Finally, we install a few packages that would allow us to install things from PHP's PECL and PEAR repositories. This would make installing apc and xdebug far easier than doing that from source.
# aptitude install php5-dev php-pear make
Optional: Install APC
If this is a live server, it is recommended that you install APC to boost PHP's performance.
# pecl install apc
Create a config file for it named /etc/php5/conf.d/apc.ini and put the following lines in it:
Optional: Install XCache
Alternatively, you can use the XCache op-code cache.
# aptitude install php5-xcache
For more details check our article on configuring XCache.
Optional: Install Xdebug
If this is a development server, you may want to install Xdebug if you are using a development environment that supports it. It helps with debugging and profiling PHP applications.
Different IDEs like Komodo, Eclipse and even vim have support for Xdebug.
# pecl install xdebug
We have an article on using vim and Xdebug for debugging Drupal that you may want to check.
Increase the memory for PHP
Ubuntu has changed the default for PHP's maximum memory size for scripts often. It used to be 8MB, then was pushed to 128MB with 7.10, and now with 8.04, it is back to 16MB. While this is adequate for Drupal's core, installing several contributed modules will often exhaust that. So start with 32MB by creating a new file /etc/php5/conf.d/local.ini and put the following memory_limit line to:
memory_limit = 32M
Configure Apache's mod_rewrite
Drupal's Clean URLs are a very useful feature. It requires the Apache mod_rewrite.
First, enable the Apache module by executing this command:
# a2enmod rewrite
Then, edit the file /etc/apache2/sites-enabled/000-default, and change this section:
<Directory /var/www/> Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny Allow from all </Directory>
So the line will be:
More Apache Configuration
There are a few Apache modules that are not really needed. We better disable them to save some memory.
# a2dismod cgi # a2dismod autoindex
We may also get better performance if we compress the HTML before we send it to the browser. For this we enable the deflate module.
# a2enmod deflate
Finally, restart Apache
# /etc/init.d/apache2 restart
Download and Extract Drupal
First download Drupal by doing this:
# cd /tmp/ # wget http://ftp.osuosl.org/pub/drupal/files/projects/drupal-6.14.tar.gz
Then extract the tarball
# cd /var/www/ # tar xzf /tmp/drupal-6.14.tar.gz
Move the files to the web root of the server
# mv drupal-6.14/* /var/www
And don't forget the hidden file ...
# mv drupal-6.14/.htaccess /var/www
Remove the file index.html, so Drupal's index.php will be the one that is executed by Apache
# rm index.html
Then change the permissions of all the Drupal files to be owned by something other than the user Apache runs as: www-data
# chown -R root:root /var/www
Then, create a files directory that is owned by the www-data user, so Drupal can write images, pictures and uploaded files there. Note that if you have a multi site install, you will need to create one files directory for each site, e.g. /var/www/sites/example.com/files:
# mkdir /var/www/sites/default/files # chown -R www-data:www-data /var/www/sites/default/files
Create the Drupal database
The following command will create a database for Drupal:
# mysqladmin create db
Then grant privileges to it:
Then enter the following two lines at the MySQL prompt:
GRANT ALL PRIVILEGES ON db.* TO user@localhost IDENTIFIED BY 'something'; FLUSH PRIVILEGES;
We are now ready to install Drupal.
Point your browser to the server (e.g. http://example.com) and you should be greeted by Drupal's installer.
You will need to use the following values:
Database name: db
Database user name: user
Database password: something