Install, Configure & Optimise MySQL on Debian

Step 1 : Adding the Dotdeb repository

You can skip this step if you have already added the Dotdeb repository while installing NGINX and PHP-FPM on your Debian Squeeze Server. We need to grab the latest version of MySQL to benefit from all new updates and bug fixes. Read this article for information on adding the Dotdeb repository to your Rackspace Cloud Server.

Step 2 : Install the MySQL server and client

Installation is simple. Just use the following command.

[shell]apt-get install mysql-server mysql-client[/shell]

You will be prompted to key in the MySQL ‘root’ password during the installation. Make sure the password is hard to crack. Once the install is over, you can run


to remove the ‘test’ database and test users. MySQL should be up and running by now!

Step 3 : Configuring and optimising the MySQL Server

MySQL can get resource hungry. There are many articles around the web that talk about MySQL optimisation. The few settings that I have shown here will help free up some memory (RAM). Edit the following MySQL configuration file.


The settings that are already in the MySQL configuration file are pretty decent. You can add just the following to free up some additional memory.

key_buffer = 8M

You can use the Perl script found at to further optimise the database server.

Step 4 : Creating a new database user and database

We will need to create a new database and user for the WordPress installation. The following command should do that.
[shell]mysql -h localhost -u root -pPassword[/shell]
GRANT USAGE ON *.* TO ‘newuser’@’localhost’ IDENTIFIED BY ‘password’
GRANT ALL PRIVILEGES ON `newdbname`.* TO ‘newuser’@’localhost’

This command will create a newuser with a password and assign the user to the new database with the name newdbname.

Step 5 : Restart the MySQL server

[shell]service mysql restart[/shell]

That’s it! You now have a working MySQL database server.


Install, Configure & Optimise PHP5 with PHP5-FPM

PHP-FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation with some additional features useful for sites of any size, especially busier sites.
Source : PHP-FPM Website

PHP-FPM is far better than the standard mod_php implementation of PHP and also easier to implement that spawn-fcgi. PHP-FPM works like an application that loads and kills PHP instances as needed. Of all the benefits that it offers, reduced memory usage is the most attractive one.

Step 1 : Add the Dotdeb repository

You can skip this step if you have already added the Dotdeb repository while installing NGINX on your Rackspace Debian Cloud Server. The version of PHP and PHP-FPM in the Dotdeb repository is up-to-date and stable. We need to grab the latest version of PHP to benefit from all new updates and bug fixes. Read this article on adding the Dotdeb repository to your Debian Squeeze Server.

Step 2 : Installing PHP and PHP-FPM

The following command will do it all for you. I have included some popular PHP modules. You can choose and install the modules that you require.
sudo apt-get install php5-cgi php5-cli php5-common php5-curl php5-dev php5-fpm php5-gd php5-idn php5-imagick php5-imap php5-json php5-mcrypt php5-memcache php5-mhash php5-ming php5-mysql php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-suhosin php5-tidy php5-xcache php5-xmlrpc php5-xsl php-pear php-soap
This command will install PHP-FPM and auto start the service. PHP-FPM will get added to the startup.

Step 3 : Configuring and Optimising PHP

As you will be using PHP-FPM to process PHP scripts, edit the php.ini file that can be found at /etc/php5/fpm/php.ini. There are a lot of PHP settings that you can configure to optimise PHP for performance, speed and security. The following three are a good starting point.
memory_limit = 64M
expose_php = Off
display_erros = Off

Step 4 : Configuring and Optimising PHP-FPM

Remember, we are setting up a low-end (256MB) web server on Rackspace. We need to conserve as much memory as possible. Edit the file /etc/php5/fpm/pool.d/www.conf
pm = dynamic
pm.max_children = 10
pm.start_servers = 1
pm.min_spare_servers = 1
pm.max_spare_servers = 4
pm.max_requests = 500
This will bring down the number of children processes and free up some RAM.

Step 5 : Restart PHP-FPM

service php5-fpm restart
This command will restart PHP-FPM.


Install, Configure & Optimise NGINX on Debian Squeeze

nginx (pronounced “engine-x”) is a Web server and a reverse proxy server for HTTP, SMTP, POP3 and IMAP protocols, with a strong focus on high concurrency, performance and low memory usage. According to BuiltWith, it is used on 9.92% of the top 1 million websites, and its growth within the top 10k, 100k and 1 million segments is increasing.

The purpose of this tutorial is to install and configure NGINX (to host WordPress sites) on a low end cloud server (256MB instance from Rackspace).

Step 1 : Add the Dotdeb repository

The version of NGINX in the Debian repository is slightly outdated. We need to grab the latest version of NGINX to benefit from all new updates and bug fixes. Read this article on Adding the Dotdeb repository to your Rackspace Cloud (Debian Squeeze) Server.

Step 2 : Install NGINX

The following command will do it all. It will also start the NGINX service and add it to the server startup.
[shell]apt-get install nginx[/shell]

Step 3 : Configure & optimise NGINX

The NGINX package from Dotdeb comes bundled with all the key modules. The configuration file is pretty good too. We’ll still need to make some changes as our cloud server instance is just 256MB. Open
[text]/etc/nginx/nginx.conf[/text] using your preferred editor. The following are some settings that you can change / add.
worker_processes 2
worker_connections 1024
server_tokens off;

# Timeout Settings

client_body_timeout 10;
client_header_timeout 10;
keepalive_timeout 5 5;
send_timeout 10;

# Gzip Settings – For improving (SEO) page speed

gzip on;
gzip_static on;
gzip_comp_level 6;
gzip_disable "msie6";
gzip_vary on;
gzip_types text/plain text/css text/xml text/javascript application/json application/x-javascript application/xml application/xml+rss;
gzip_proxied expired no-cache no-store private auth;
gzip_buffers 16 8k;
gzip_http_version 1.1;
The above are just a few critical ones. You can refer to the NGINX documentation if you would like to further optimise NGINX.

Step 4 : Create virtual hosts for multiple domains

Create the following folders to store the website’s files, scripts and logs. The third command will make NGINX (www-data user) own the website files.
mkdir -p /var/www/domain/httpdocs
mkdir /var/www/domain/logs
chown -R www-data:www-data /var/www/
Create a domain vhost configuration file at this location.
The filename can be anything. e.g. domainname.conf, domainname, domainname.tld, etc. Create a symlink to this domain’s vhost configuration file from [text]/etc/nginx/sites-enabled/[/text] using the following command.
[shell]ln -s /etc/nginx/sites-available/filename /etc/nginx/sites-enabled/filename[/shell]
The following content should go into the domain’s vhost configuration file.
server {
# This redirects the non-www version of the domain name to the www version
rewrite ^ $scheme://$request_uri? permanent;
server {
root /var/www/domain/httpdocs;
index index.html index.htm index.php;

access_log /var/www/domain/logs/access.log;
error_log /var/www/domain/logs/error.log;

location ~ \.php$ {
# The next two lines address a security flaw in NGINX.
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini

include /etc/nginx/fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/domain/httpdocs$fastcgi_script_name;

# Disable index.php and make WordPress permalinks work
location / {
try_files $uri $uri/ /index.php?$args;

# Expires header to improve SEO (Google Page Speed)
location ~* \.(ico|css|js|gif|jpg|jpeg|png|xml|pdf)$ {
expires 1w;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
log_not_found off;

location = /favicon.ico {
log_not_found off;
access_log off;

location = /robots.txt {
allow all;
log_not_found off;
access_log off;

# Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store
location ~ /\. {
deny all;
access_log off;
log_not_found off;

# Don’t log and deny access to files which end with ~, as these are usually backup files.
location ~ ~$ {
access_log off;
log_not_found off;
deny all;
The above settings should be sufficient to run a WordPress based website. We have also taken care of some key page speed improvements that Google recommends.

Step 5 : Restart NGINX

Once you have completed the above steps, you will have to restart NGINX for the new settings to take effect. You can use the following command to restart NGINX.
[shell]service nginx restart[/shell]

Step 6 : Point the domain’s A record to the server’s IP address

For the domain and the hosting to work together, you need to edit your domain’s DNS records and point the A records (@ and www) to your server’s IP address. Once the DNS change gets propagated around the web, you will be able to enter your domain name in the address bar of the browser and reach your website stored under the folder (/var/www/domain/httpdocs).


How to Add the Dotdeb Repository to Debian Squeeze

Dotdeb is a repository containing packages to turn your Debian boxes into powerful, stable and up-to-date LAMP servers
– Dotdeb About Page

The Dotdeb repo for Debian based Linux servers contains the latest stable versions of NGINX, PHP and MySQL. All three of these packages combined can provide us with a powerful yet light weight web server to host static and dynamic websites. The aim of this tutorial is to setup NGINX, PHP5-FPM and MySQL on a Rackspace Cloud Server to host a WordPress based website.

To add the Dotdeb repository to any Debian Squeeze server, edit the file


and add these two lines

deb stable all
deb-src stable all

at the bottom of the file. You will now need to fetch the GnuPG key for this repository. You can download the GnuPG key using wget and then add it to the server.

cat dotdeb.gpg | sudo apt-key add –

Run [text]apt-get update[/text] to complete the repository addition.

Source : Dotdeb Website. Please visit the Dotdeb website for instructions on setting up the repository for Debian Lenny servers and updates on all the available packages.


How to Launch a New Rackspace Cloud Server Instance

In this tutorial I will demonstrate how to setup a Rackspace Cloud Server instance. The intended use of this sever is to host a low traffic WordPress website. All settings and configuration detailed in this tutorial are tailored for a 256MB Rackspace Cloud Server slice.