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:

extension=apc.so
apc.shm_size=40

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:

AllowOverride All

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:

# mysql

Then enter the following two lines at the MySQL prompt:

GRANT ALL PRIVILEGES ON db.* TO user@localhost IDENTIFIED BY 'something';
FLUSH PRIVILEGES;

Installing Drupal

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

Enjoy ...

Comments

Fri, 2008/06/06 - 21:03

Certainly not "GRANT ALL PRIVILEGES".

Much better:

GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER
ON databasename.*
TO 'username'@'localhost' IDENTIFIED BY 'password';

Right?

Thu, 2008/12/18 - 16:37

no. Drupal is not going to work without 'lock' and 'create temporary tables' privileges. So 'grant all' is correct.

Tue, 2008/12/23 - 18:24

Please I need help, How can you configure a website without GUI? How can you use Drupal to set a website without GUI for it? Am I missing anything here? Or what?
please help
thanks

Mon, 2009/11/30 - 17:17

It's best to avoid using GRANT ALL PRIVILEGES for security reasons. Note that the CREATE TEMPORARY TABLE and LOCK TABLES permissions are no longer required for Drupal 6 since Nov 2007: http://drupalcode.org/viewvc/drupal/drupal/INSTALL.mysql.txt?view=log&r1=1.10&pathrev=DRUPAL-6#rev1.10

Sat, 2008/06/07 - 21:46

Thanks for great tutorial! I got through it first time installing linux server. Hell lot easier then doing it on the Windows or Mac OS X (10.3.9)! Wow, I haven't used a non GUI server for since college almost 15 years ago.. really brings back some old memories haha.

ok, I decided to use phpmyadmin b/c it was too much just command lining the thing.

I made a root password beforehand after installing MySQL.

(install phpmyadmin)
# aptitude install phpmyadmin

(note: phpmyadmin is installed in /usr/shared/phpmyadmin)
(make a symlink (symbolic link) to the web root folder: /var/www/)

# ln -s /usr/shared/phpmyadmin /var/www/phpmyadmin
(note: don't make a folder /var/www/phpmyadmin beforehand or the link will end up inside the folder. Also, you don't have to name it 'phpmyadmin')

there you go.. just point to the http://[yoursite.com]/phpmyadmin

ALSO, as far as permissions for database, make a separate user and give it these permissions:

GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER
according to drupal's tutorial:
http://drupal.org/getting-started/6/install/create-database

Tue, 2008/09/09 - 19:01

Great guide, it jogged my memory about something I needed to fix. Something I have found to be really important for speed is mysql query caching - and probably the single most effective speed fix out there for active sites.

Thanks again!

Todd
Systems and Development Team
InMotion Hosting, Inc.

Sun, 2008/10/19 - 12:15

Yes, you can make it too big. The default is 30MB, and that is sufficient in many cases. However, if you have many modules, and/or many sites that do NOT share the same code base (i.e. not a multi-site install), then 30MB may not be enough.

The best way is to use the apc.php that comes with APC, and see how your shared memory is used.
--
2bits -- Drupal and Backdrop CMS consulting

Pages

Is your Drupal or Backdrop CMS site slow?
Is it suffering from server resources shortages?
Is it experiencing outages?
Contact us for Drupal or Backdrop CMS Performance Optimization and Tuning Consulting