Apache virtual hosts: wordpress and subversion

A setup I made for my own needs: how to run wordpress and subversion server as virtual hosts on one Apache instance.

1. Install and configure Apache

If not included by default, you need to install and set the Apache HTTP server to run on boot.

Note: you should also take care of the configured runlevel. You can specify the runlevel for running httpd on boot by using chkconfig -level <runlevels> httpd on. To see if it’s fine, run chkconfig | grep httpd

Open a browser pointing to the IP (or domain if already configured, ‘localhost’ if working locally) of your web server. An example apache web page should appear.

2. Install and configure WordPress

2.1. Install and configure MySQL. (If you already have MySQL installed, skip this step)

2.2 Create a wordpress database and user

2.3. Setup wordpress

Now, the configuration for wordpress needs to be entered. Copy and open the wp-config:

Edit the following sections with the required data:

  • DB_NAME – the name of the created wordpress database (here is wordpress)
  • DB_USER – the username who has privileges for the database (here is wpuser)
  • DB_PASSWORD – the password for the user that you have entered previously
  • DB_HOST – if on remote host, the name of the host. Here, it’s localhost
  • DB_CHARSET and DB_COLLATE in most cases should remain unchanged.
  • Secret key values – use the generator here: https://api.wordpress.org/secret-key/1.1/salt/

2.4. Configure Apache first virtual host for wordpress

Edit the apache configuration file and enable virtual hosts:

I prefer to add separate config file for each virtual host. These files are added in the /etc/httpd/conf.d directory and are processed by Apache in alphabetical order.

Note that the first virtual host you configure, regardless of the path applied, is the default one which Apache will use if no recognizable path is found. This means that even if you configure the virtual host to be found at specific sub-domain, say blog.something.com, every address of this sub-domain will be also legal without the subdomain. Example: blog.something.com/something can be accessed also via something.com/something.

The configuration is now complete. Open a browser and point to the online configuration: something.com/wp-admin/install.php

3. Install and configure subversion

In order to have private, password protected repositories, create one or several passwords first:

Create two different repositories parent directories. One will be used for public repos, while the other one will be for the private, password protected ones:

In future, in order to create new repositories, just repeat the svnadmin and chown commands.

The final step here, is to configure the second apache virtual host dedicated for subversion. To do so:

The configuration is now all done, restart the httpd service once more and point to: svn.something.com/public/example or svn.something.com/private/example (the second one should prompt for username and password).

Useful links: