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.
1 2 3 4 5 6 |
# Install yum install httpd # Run on start chkconfig httpd on # Start/Restart the daemon service httpd restart |
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)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
#install mysql #if you don't have php, install it as well, it will be needed yum install mysql-server php php-mysql #start the mysql daemon, set it to run on boot chkconfig mysqld on #or use specific levels, example: chkconfig --level 2345 mysqldon service mysqld restart #login as root mysql -u root #delete all other users DELETE FROM mysql.user WHERE NOT (host="localhost" AND user ="root"); FLUSH PRIVILEGES; #change root password (recommended for security) #after this, you need to login with mysql -p -u root SET PASSWORD FOR 'root'@'localhost' = PASSWORD('new_password_here'); FLUSH PRIVILEGES; #if you want, change the root user username #UPDATE mysql.user SET user="root_user_name" WHERE user="root"; #FLUSH PRIVILEGES; #disallow anonymous access to the database DELETE from mysql.user where user=''; FLUSH PRIVILEGES; #all done exit |
2.2 Create a wordpress database and user
1 2 3 4 5 6 7 8 9 10 |
#login to the mysql server mysql -p -u root #create the database (name it wordpress for example) CREATE DATABASE wordpress; FLUSH PRIVILEGES; #add a new user(name it wpuser for example), and assign it with full access to the new database GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost' IDENTIFIED BY 'enter_password_here'; FLUSH PRIVILEGES; #all done exit |
2.3. Setup wordpress
1 2 3 4 5 6 7 8 9 10 11 12 |
#Install wget and unzip if you don't have them yum install wget unzip #go to the parent directory where wordpress will be installed #the default apache html directory is in /var/www/html, so /var/www/wordpress will be used here cd /var/www wget http://wordpress.org/latest.zip unzip latest.zip rm latest.zip cd wordpress # some directories that wordpress need to be able to write to mkdir wp-content/uploads wp-content/cache chown apache:apache wp-content/uploads wp-content/cache |
Now, the configuration for wordpress needs to be entered. Copy and open the wp-config:
1 2 3 |
cp wp-config-sample.php wp-config.php #edit with vi or gedit if present vi wp-config.php |
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:
1 2 3 4 5 6 7 |
#Edit the apache configuration file vi /etc/conf/httpd/httpd.conf #uncomment the NameVirtualHost line: NameVirtualHost *:80 #Save and close |
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
#add a virtual host config file cd /etc/httpd/conf.d vi vh_blog.conf #fill this data in the conf file #use your domain and desired subdomain <VirtualHost *:80> DocumentRoot /var/www/wordpress ServerName blog.something.com ServerAlias blog </VirtualHost> #Save and closee #Restart httpd service httpd restart |
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
1 2 3 4 5 6 7 8 9 10 11 |
#Install subversion binaries yum install mod_dav_svn subversion #check to see if the apache config is done right for subversion vi /etc/conf/httpd/httpd.conf #uncomment/add the following lines LoadModule dav_svn_module modules/mod_dav_svn.so LoadModule authz_svn_module modules/mod_authz_svn.so #Save and close |
In order to have private, password protected repositories, create one or several passwords first:
1 2 3 4 5 6 |
#For the first user: #replace username_here with the desired username htpasswd -cm /etc/svn-auth-conf username_here #for any other user sharing the same repositories: htpasswd -m /etc/svn-auth-conf another_username_here |
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
cd /var/www mkdir svn cd svn mdkir public mkdir private #Create sample repositories cd public svnadmin create example chown -R apache.apache example cd .. cd private svnadmin create example chown -R apache.apache example |
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# go to the additional config directory for apache cd /etc/httpd/conf.d #create a new config file which will be processed after the blog config vi vh_subversion.conf #paste the contents: <VirtualHost *:80> DocumentRoot /var/www/svn ServerName svn.something.com ServerAlias svn <Location /private> DAV svn SVNParentPath /var/www/svn/private AuthType Basic AuthName "Subversion repos" AuthUserFile /etc/svn-auth-conf Require valid-user </Location> <Location /public> DAV svn SVNParentPath /var/www/svn/public </Location> </VirtualHost> #Save and close #Restart httpd service httpd restart |
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:
http://centoshelp.org/servers/database/installing-configuring-mysql-server/
http://codex.wordpress.org/Installing_WordPress
http://blog.adlibre.org/2010/03/10/how-to-install-wordpress-on-centos-5-in-five-minutes-flat/
http://httpd.apache.org/docs/2.2/vhosts/
http://wiki.centos.org/HowTos/Subversion/
http://schwuk.com/articles/2004/08/28/using-subversion-with-apache-virtual-hosts/