Skip navigation

Category Archives: Web Hosting


In the last screencast we configured a server to host the popular CMS software, WordPress. In this tutorial we’ll be creating a reverse-proxy that can be used to sit in front of our web server, in order to increase performance, security and eventually to load balance between multiple back-end web servers – though the configuration for this won’t be covered until later tutorials.

So why Nginx and what it Nginx? Well, Nginx is a reasonably new web server for Linux which has gained a lot of traction in recent years, mainly because it runs a lot leaner in terms of hardware requirements and is much faster when compared to other web hosting software. For these reasons, it’s now being used by some of the largest websites on the internet including HowToForge, WordPress and, the biggest player of them all, Facebook.

“Apache is like Microsoft Word, it has a million options but you only need six. Nginx does those six things, and it does five of them 50 times faster than Apache.” – Linux Journal.

The Test Network

Before installing and configuring Nginx as an RPS (reverse-proxy server) it’ll help just to have a look a where the RPS is going to sit in our network and how it will work. The diagram below shows how a client connecting from the internet will actually have their connection terminated at the RPS which will then establish a connection to the back-end server in order to request the content before finally sending it back to the requesting client.

Installing the Software

Nginx isn’t included in the RHEL 6 mirrors so, in order to get Nginx installed we’re going to add the EPEL repository first. To do this, fire up a webbrowser and head over to Here you’ll find a link to the latest EPEL rpm under the section titled “How can I use these extra packages”. Select the “newest version of ‘epel-release’ for EL6″ and then copy the link address of the link to the EPEL package.

SSH on to your newly installed Linux server and install the EPEL package using RPM by typing “rpm -Uvh” and pasting the URL that you copied for the package:

rpm -Uvh

Once the EPEL repository is available we can install Nginx using the following:

yum install nginx

Configuring Nginx

With the software installed we now need to create our configuration file which will tell Nginx to proxy all requests through to the server hosting our wordpress website. To do this, start by changing to the Nginx configuration directory under /etc/nginx/conf.d. Move the file containing the default Nginx website config to default.conf.disabled and then edit a new file called wordpress-proxy.conf.

cd /etc/nginx/conf.d
mv default.conf default.conf.disabled
emacs wordpress-proxy.conf

In to this file we’ll paste the following configuration which tells Nginx to proxy all HTTP requests for wordpress.castix.local to the server at the IP address 1921.68.122.10. Other configuration directives such as the proxy_connection_timeout setting, should be configured to match the timeouts defined on the back-end server. Take a look at these settings if you encounter intermittent errors.

server {
   listen 80;
   server_name wordpress.castix.local;
   access_log off;
   error_log off;
   location / {
      proxy_redirect off;
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_max_temp_file_size 0;
      client_max_body_size 10m;
      client_body_buffer_size 128k;
      proxy_connect_timeout 90;
      proxy_send_timeout 90;
      proxy_read_timeout 90;
      proxy_buffer_size 4k;
      proxy_buffers 4 32k;
      proxy_busy_buffers_size 64k;
      proxy_temp_file_write_size 64k;

With Nginx configured, we have only two remaining things left to do. Firstly we need to ensure that clients can access our server by adding an allow rule to the local firewall using the following:

iptables -I INPUT 5 -m state --state NEW -p tcp --dport 80 -j ACCEPT
service iptables save

Don’t forget to save the firewall rules otherwise these will be lost when the server is next rebooted. Finally we need to start the Nginx service and to run chkconfig to set it to start when the server boots:

service nginx start
chkconfig nginx on

Once you’ve updated the DNS records for your server to point to the reverse-proxy, you’ll be able to view the wordpress website. You may even notice a slight performance increase due to the fact that Nginx is caching a lot of the content and generally loads the site faster than Apache.




Your manager has come to you to say that upper management have decided to revamp the company website. The new website, you’ve been told, has been created using WordPress and the company would like to host this on a Linux VM on their existing infrastructure. With these requirements in mind you’re now thinking to your self.. how do I install and configure WordPress?

What is Required?

To begin following along with the tutorial, you’ll need a freshly installed copy of Linux. For this tutorial I’m going to be using RHEL 6.3 but the process will be identical for anyone following along with either CentOS or Scientific Linux. If you’re using another distribution such as Ubuntu or Debian, you’ll probably still find this tutorial beneficial to get an idea of what must be done, but there are differences between using these distributions that would probably warrant going out and finding a tutorial specifically for your distribution.

Installing the Software

To begin with we’re going to install a few packages that are required in order to run WordPress:

yum install httpd mod_php mysql-server php-mysql
  • httpd is the name that RedHat has given to the package for Apache. This will, of course, listen for connections on port 80 and serve up pages as requested.
  • mod_php is the PHP package for Apache. WordPress is written in PHP and so the PHP interpreter is required in order to run the website.
  • mysql-server is the MySQL database software. This is where WordPress stores it’s configuration information, user accounts, page content and basically everything else that is entered in to the website.
  • php-mysql is the PHP libraries for MySQL which are used to generate content dynamically using data stored within the MySQL database.

Once the above packages have been installed, it’s important to configure both Apache and MySQL to start whenever the server is booted. I like to do this right after installing the software so that it’s not forgotten about.

chkconfig httpd on
chkconfig mysqld on

Configuring Apache

With the required software installed we can now proceed with configuring Apache. The first thing we need to do is to create a configuration file for the website in the Apache conf.d directory. Navigate to the /etc/httpd/conf.d/ directory and edit a new file called wordpress.conf.

cd /etc/httpd/conf.d
emacs wordpress.conf

The wordpress.conf file needs to contain the following configuration:

<VirtualHost wordpress.castix.local:80>
    ServerAdmin root@wordpress.castix.local
    ServerName wordpress.castix.local
    DocumentRoot /var/www/html/wordpress
    DirectoryIndex index.php index.html
    ErrorLog logs/wordpress.castix.local-error_log
    CustomLog logs/wordpress.castix.local-access_log common

Obviously you will want to substitute wordpress.castix.local with the fqdn (fully qualified domain name) of your own server, but the rest is all that is required in order to set up a new virtual host for the website. Only port 22 is allowed through the local firewall by default, so, before clients can connect to our server we need to add a rule to iptables. The following command will add an allow rule for clients connecting on port 80 to line 5 of the iptables INPUT table. Don’t forget to run “service iptables save” afterwards to ensure that this rule doesn’t get lost when the server is next rebooted. The final line below starts the Apache web service.

iptables -I INPUT 5 -m state --state NEW -p tcp --dport 80 -j ACCEPT
service iptables save
service httpd start

Note that you’ll receive a warning when starting Apache to say that the DocumentRoot for wordpress doesn’t exist. We’ll be downloading WordPress and installing it to this directory in the next section which will resolve this warning.

Configuring MySQL

At this point we have Apache configured and ready for when we download and install WordPress, next we must create a new database, and a MySQL user account, which WordPress can use to store its data. To do this, begin by starting the MySQL service and then configuring a root user password

service mysqld start
/usr/bin/mysqladmin -u root password 'my-password'

Now we’ll create a new database called ‘wordpress’ and assign a new user, also called ‘wordpress’, full access to that database:

mysql -u root -p
[enter your password here]
mysql> create database wordpress;
mysql> grant all on wordpress.* to 'wordpress'@'localhost'
       identified by 'my-password';

Downloading and Configuring WordPress

So, we’ve got our web server, we have our database and both are now configured and ready for WordPress. The first step in installing the WordPress site is to download the latest release of the software. This can be done by changing to the /var/www/html/ directory, running wget and then decompressing the package with tar. Note that wget isn’t installed by default, so we have to install this software first.

yum install wget
tar -xzvf latest.tar.gz

Lastly we need to edit wordpress’ wp-config.php file to tell it the username and password of the database that we have configured for it to use. To do this, change to the wordpress directory, copy the sample configuration file to wp-config.php and open wp-config.php in your favorite editor.

cd /var/www/html/wordpress/
cp wp-config-sample.php wp-config.php
emacs wp-config.php

Modify the file so that the correct settings are assigned to the DB_NAME, DB_USER and DB_PASSWORD variables:

// ** MySQL settings - You can get this info from your web host ** // 
/** The name of the database for WordPress */
define('DB_NAME', 'wordpress');
/** MySQL database username */
define('DB_USER', 'wordpress');
/** MySQL database password */
define('DB_PASSWORD', 'my-password');

WordPress Specific Setup

At this point we can now point our browser to http://wordpress.castix.local to have it load WordPress from our web server. I’ve added a static /etc/hosts entry to my local machine, seeing as I’m not using a real DNS name, in order to make this work. On the WordPress set up page, all we have to do now is to set a title for our website and create a username and password for the site’s admin user account. Once you’ve filled in the blank, hit the “Install WordPress” button which will initialise the database take you through to the login page.


 Subscribe in a reader

%d bloggers like this: