Apr
23

Ubuntu Production Setup on VPS/Server for Drupal - Part 1

We've moved forDrupal to Linode VPS to serve you better. Since we just setup a server over there, we thought it would be nice to share it with you the process and served as a note for ourselves.

The following steps are conducted under Ubuntu 8.10 on a VPS. However it should be the same for newer version of Ubuntu or if you are setting up a dedicated server or a virtual machine.

Update: Linode just released Ubuntu 9.04 today, the steps here should be the same.

Installing Ubuntu Server

If you are on a VPS, your hosting company would have prepared the Ubuntu image that they maintain. Therefore, you can skip this section if you are using a VPS.

Choosing between 32 bits and 64 bits server depending on your server specification. If your server is low in memory, 32 bits Ubuntu is the way to go as the kernel consumes less memory compare to 64 bits version.

Once you have decided on the OS. Follow the installation instructions on Ubuntu's web site to install Ubuntu normally. Since we are setting up the server for production, try to minimize your server installation packages, we only enabled the OpenSSH server. For LAMP, we will handle it manually to control what get installed.

Update the Server

It is a good practice to get your newly install up-to-date before continue with other software installation.

# apt-get update && apt-get dist-upgrade

If there is new kernel version, reboot the server.

# shutdown -r now

Note that you can use either aptitude or apt-get, install aptitude if needed. Remember we did not install other software packages previously.

# apt-get install aptitude

Install Apache, MySQL & PHP

Let's get all in one shot

# aptitude install apache2 mysql-server php5 php5-gd php5-mysql

You will be asked to set MySQL root password, set a secure password.

Configure Apache
Enable some modules, rewrite for clean url support, deflate for gzip content serving

# a2enmod rewrite deflate

Disable some modules to reduce the apache memory size

# a2dismod cgi autoindex

Edit /etc/apache2/sites-available/default, change the line AllowOverride from None to All

    <Directory /var/www/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            Allow from all
    </Directory>

Configure PHP
Edit /etc/php5/apache2/php.ini, this works for us, adjust to your need accordingly

max_execution_time = 300
max_input_time = 300
memory_limit = 96M

Restart Apache for all changes to take effect

# /etc/init.d/apache2 restart

Optional - Postfix, Cron
We prefer Postfix over Sendmail, if you want simpler SMTP instead of full fledged MTA like Postfix, you can search and check out msmtp, ssmtp or drupal's smtp module.

# aptitude install postfix

Edit /etc/postfix/main.cf to customize it to your domain.

Get cron up and running

# aptitude install cron wget

When your Drupal is setup

# crontab -e
# m h  dom mon dow   command
0 * * * * wget -O - -q http://tld.domain.com/cron.php

Install Drupal

Well, we will bypass this part, there are already a lot of fine resources on that, see references bellow.

Part 2 of this tutorial covers Performance, Security, Monitoring and Backup.
Continue with Part 2

References