Skip navigation


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


One Trackback/Pingback

  1. […] Artigo técnico  completo […]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: