WordPress, Linux Server and Database Options

in WordPress Tutorials

This is an advanced level tutorial for WordPress users who host their blog or website on a Linux web server. There are some things that WordPress server administrators need to know that are outside the scope of most general WordPress tutorials. Understanding the server environment is one of the big ones, so here I will go into detail about several Linux server operations that WordPress webmasters need to know if they have their WordPress installation on a Linux web server. Also in this tutorial, I will explain how you can use postgresql database with WordPress.

Setting the Document Root

The document root is the folder that holds the home page of a website. I ran into one instance recently where I had a website which I migrated to a new server and I had to rename the website’s document root folder from html to public_html to make many scripts function. Here is how you can rename your document root in a Linux web server environment:

Log in to a shell or command prompt to the server. I use Putty. Once in the server, change to root user using the following at the command line:

sudo su

After that, enter the root password if prompted for one

Migrate to your current document root folder. In my case it was named “html” and rename it to what you need it to be. In my case that was “public_html”. If you need to create a new folder from scratch try the following commands:

mkdir public_html

Next, change the owner to the same owner as the old public folder or document root so that it works online. In my case that owner was ec2-user, so I did this at the command prompt:

chown ec2-user public_html

Then restart the web server using the following command line command:

service httpd restart

Finally make sure your new document root folder has the correct permissions and test it by inserting a index.html page in it and visiting your URL. You should see your new page. If not, check over what you did and find where the mistake was made or contact your server administrator for assistance.

Changing a Directory Name

To change a directory name of any directory in a Linux environment use the following command line command:

mv old_dir_name new_dir_name

Using a Postgresql Database with WordPress

For any postgresql lovers reading, there is a way to use a postgresql database as a backend for WordPress. Unfortunately, there are some drawbacks however. First of all, you have to use a plugin. Secondly, it is going to be a bit slower than the default MySQL database because it has to do SQL rewriting for each page view. If you can get over those two drawbacks, then postgresql might be what you are looking for.

The most popular plugin that allows you to use postgresql is the PostgreSQL for WordPress (PG4WP) plugin. It can be downloaded from wordpress.org at http://wordpress.org/extend/plugins/postgresql-for-wordpress/. If you are a fan of both WordPress and postgresql databases, give it a try. There is an advantage to using the plugin if postgresql is what you know and you do not know MySQL. It could save you a lot of time because installing the plugin would take a lot less time than learning MySQL from scratch. If you don’t already have a postgresql database installation on your Linux server, read the next section to learn how to install one from the command line.

Adding a Postgresql database to Linux

First, log into a command shell as root and create a user for postgresql by typing at the command prompt:

Adduser postgresql

Add the Directory for pgsql like so:

Mkdir /var/pgsql

Next add the yum package to your server with:

yum install postgresql-libs postgresql postgresql-server

You will have to type “y” once to continue.

Then open the configuration file in the vi editor from the command line like this:

sudo vi /etc/init.d/postgresql

Find the lines that read:



And change to:



Then hit the escape key to get out of reinsert mod and type:


And press enter.

Next change to the postgresql user to continue and create your clusters:

su postgres

initdb -D /var/pgsql/data

When I did the above there was some directory permission errors because the directories were owned by the root user. I was able to fix it by executing the following commands, but you only need to do so if the last command above doesn’t work. You will need to change back to root user before doing this and change back to postgresql user when done. Here are the commands starting with the one to change to root user:

sudo su

chown /var/pgsql

chown /var/pgsql/data

Okay, whether or not you had to do the last three commands, continue like normal from here. The next think you need to do is start the postgresql database like this:

service postgresql start

Then, confirm it is running properly by doing a status check like in the following command line example:

service postgresql status

Finally, if the status check says that postgresql is running, you can add the following command to make postgresql start up with your server:

sudo chkconfig postgresql on

There you are, you should now have your postgresql database installed and fully operational. Congratulations.


In this WordPress tutorial we covered several things you can do with Linux and postgresql when it comes to WordPress. Almost all of what was in the tutorial has to do with the Linux command line, so if you are a Linux user and a WordPress enthusiast, then I hope what you have learned in this tutorial helped you to better manage your WordPress blog or website. Have fun with your WordPress site and if you are a postgresql fan, then you now have what you need to run it with WordPress as well.

Comments Closed