Installing WordPress – Apache web server configuration
In this part of the Installing WordPress series we look at the WordPress Apache web server configuration files necessary to get your WordPress site on the Internet.
WordPress Apache web server configuration
A basic wordpress apache web server configuration file is shown in the section below. In most apache installations on Linux there will be a configuration directory in /etc/apache2/
which will contain a sites-available
and a sites-enabled
directory. To create a virtual server configuration for apache, create a new file in the sites-available
directory.
As a convention, I would tend to call the file the name of the site, so for example my-site-name.co.uk.conf.
<VirtualHost *:80> DocumentRoot /usr/local/sites/my-site-name.co.uk/wordpress ServerName my-site-name.co.uk ServerAlias www.my-site-name.co.uk DirectoryIndex index.html, index.php ErrorLog /var/log/apache2/my-site-name.error.log CustomLog /var/log/apache2/my-site-name.access.log combined <Directory /usr/local/sites/my-site-name.co.uk/wordpress> Options Indexes FollowSymLinks AllowOverride All require all granted </Directory> </VirtualHost>
As with the sample nginx configuration file I posted in the last article on Installing WordPress, there are other options which you may want to configure in your configuration file, particularly if you want to hide the site from the public whilst you are preparing content.
The parts of the config shown above which will definitely need to be changed are highlighted:
DocumentRoot
This, as the name suggests, points at the root of the install directory. In the example above I’ve used the directory which I used in the first part of this installing wordpress series but obviously, you need to set this to the correct directory for your instalation.
ServerName
The server name directive is set to the url that you are intending the site to be available on.
ServerAlias
The server alias directive is used to provide other urls which the site will also be available on. In this example I’ve added the www version of the site as an alias, but you need to make sure that the www version actually redirects to the non www version, or the other way round if you prefer. The important thing is to make sure the site isn’t actually visible to users on more than one URL because that will affect the site’s SEO.
ErrorLog and CustomLog
These two directives set the location and name of the error log file and the access log file. The location is probably what you want but the file name would be better set to something more appropriate for your site.
Installation Directory
The other part of the file which needs to be changes is to change the Directory directive to be correct for your installation directory.
Applying the configuration
To apply the configuration there are some commands which the apache installation provides to make the process slightly easier than under nginx.
Assuming the file above is called my-site-name.co.uk.conf and is in the sites-available directory the command
sudo a2ensite my-site-name.co.uk.conf
will create a link from the file into the sites-enabled directory. Then we need to reload the apache web server to make the configuration live, but before that I tend to test that the configuration is valid by using the command
sudo apachectl -t
Assuming that command reports no errors in the config file, we can apply the configuration with the command
sudo apachectl graceful
which will restart the server and apply the new configuration.
In the next part of this series we will continue the WordPress install and configure the DNS so our chosen host names / urls work.