
Today on the Moving Beyond SSH series, we’ll be going over some initial setup changes in our Apache configuration.
The way we’ll be configuring our web server is basically the standard in web hosting. Domain’s files will be located in /home and each domain will have its own public_html folder and logs. We’re using this structuring because we’re assuming that you’re going to host more than one domain on your server.
Let’s start by opening up our Apache configuration file:
nano /usr/local/apache2/conf/httpd.conf
Now, we’re going to change a few of the settings from the defaults:
- Find the line that starts with ServerAdmin and change the email address to a “webmaster” email. This is the email address that will appear on Apache error messages.
- Find the line that starts with ServerName and change it to your server’s IP address with :80 added to the end of it (eg. 127.0.0.1:80)
- Find the line
and change it to - In that
block, you may want to change AllowOverride None to AllowOverride All, but you can read more on that in the Apache docs - Find DirectoryIndex index.html and add index.php to it
- Find #Include conf/extra/httpd-vhosts.conf and uncomment it (remove the # from the beginning of it)
Now, you can save (Control-O) and close (Control-X) that file.
We’re now going to setup the configuration for our domain’s files. We’re going to first make a default for it, then you can make them for your domain. So, let’s first make our directories:
mkdir /home/default
mkdir /home/default/public_html /home/default/logs
Then, let’s create our log file:
touch /home/default/logs/error_log
You can do this for each of the domains you plan on hosting (obviously using different directory name in /home though). Okay, now let’s open our virtual hosts configuration file:
nano /usr/local/apache2/conf/extra/httpd-vhosts.conf
Now, find the line with #NameVirtualHost *:80 and remove the # from it. Get rid of the example
Our default virtual host is going to look like this (replace 127.0.0.1 with your server’s IP address):
DocumentRoot "/home/default/public_html"
ServerName 127.0.0.1:80
ServerAlias 127.0.0.1
ErrorLog "/home/default/logs/error_log"
For each of our domains, we need one like this:
ServerName example.com
ServerAlias www.example.com .example.com
DocumentRoot "/home/example/public_html"
ErrorLog "/home/example/logs/error_log"
You can also specify separate ServerAdmin email addresses for each virtual host, if you want. After you have added virtual hosts for all your domains, you can save and close that file and restart Apache (to load the new configuration files and check if there’s any errors in them).
Of course, you still can’t point domains towards your server, since we haven’t setup the DNS yet. We’ll be doing that in the next week or two.




