Installing WordPress Step 4: Deciding the Site Root Directory and Moving Files there on Linux (CentOS 6)

This post is part of a step-by-step series on installing WordPress on Linux (CentOS 6)

Requirements

  1. MySQL has been installed and secured
  2. WordPress Directory has been Installed
    1. Using yum
    2. Without yum
  3. MySQL database for WordPress has been made
  4. wp-config.php has been appropriately configured with database settings and security keys

Now that our WordPress site has been installed and configured we just need to put it somewhere Apache can find it.

Knowing the Root Directory of your Site

If you already have a site up and running you should know where the root directory of that site is.

Default root directory of Apache

If you have left Apache with its default configuration then the root directory will probably look something like this on CentOS:

/var/www/html/

For other OSes it may vary a bit.

Custom root directory

If, however, for example, you have multiple sites being served by Apache then they can’t all have the same root directory. In that case we will have to modify Apache’s configuration. First let’s choose/make a place to put our WordPress blog:

[ahmed@amayem ~]$ sudo mkdir /var/testblog

Check here to see how to give a linux user sudo powers.

Let’s make sure its permissions are the same as /var/www/html.

[ahmed@amayem ~]$ ls -l /var/www
drwxr-xr-x 12 root  root  4096 Aug 29 17:59 html
[ahmed@amayem ~]$ ls -l /var
drwxr-xr-x  2 root root  4096 Sep  2 18:42 testblog
drwxr-xr-x  7 root root  4096 Mar 28 18:54 www

Looks like it is the same.

Knowing the WP Base Directory

This is where all the WP files are. When installing using yum we found it at the following directory:

/usr/share/wordpress

If you installed it directly without yum then it is where you unzipped your WP file.

Moving the WP Base Directory Contents to Root Directory of your Site.

Now that we have decided where our site root directory will be let’s move the WP files there:

[ahmed@amayem ~]$ sudo mv /usr/share/wordpress/* /var/testblog/
[ahmed@amayem ~]$ ls /var/testblog/
index.php             wp-config-sample.php  wp-login.php
wp-activate.php       wp-content            wp-mail.php
wp-admin              wp-cron.php           wp-settings.php
wp-blog-header.php    wp-includes           wp-signup.php
wp-comments-post.php  wp-links-opml.php     wp-trackback.php
wp-config.php         wp-load.php           xmlrpc.php

Looks like we have success.

Configuring Apache if Using a Custom Site Root Directory

Go to the Apache configuration and open it for editing using vi or your favourite editor:

[ahmed@amayem ~]$ sudo vi /etc/httpd/conf/httpd.conf 

Go to the bottom by entering G. If NameVirtualHost *:80 is commented (has a # at the beginning of a line), then uncomment it by removing the #. Then add the following with your information. For more on copy pasting in vi check here:

<VirtualHost *:80>
        ServerName test.amayem.com
        ServerAlias www.test.amayem.com
        DocumentRoot /var/testblog/
</VirtualHost>

Note that if you had a site running previously on the default root then you should also put another one with the info for your original site with the DocumentRoot pointing to the default Apache root so that the original site is unaffacted.

Exit insert mode using Esc or ctrl+c then save by entering :x. Now we need to restart apache:

[ahmed@amayem ~]$ sudo apachectl restart

Done!

Next Steps

  1. Running the WordPress php Install Script

Ahmed Amayem has written 90 articles

A Web Application Developer Entrepreneur.