With Apache Web Server, PHP, and MySQL installed and running, you want to do more. It’s time to change that default page that you see, and replace it with your own content. When you place files inside something called the DocumentRoot, you can do just that! You can change the directory the default DocumentRoot uses, or even create more, however, that is for another article. Please remember, this tutorial doesn’t cover how to use web technologies to design content, or basic shell skills, but how to present content using Apache.
Introduction to the DocumentRoot
A DocumentRoot is a physical folder on your computer specified with the Apache configuration files. However, today we don’t need to worry about the configuration files, but instead we want to simply change some content found in the default DocumentRoot. This means that we don’t need to change the configuration, but only files. The DocumentRoot that Apache uses by default is found in
/var/www/html and will more than fit out needs.
Open the terminal, and type the following command then press
Before changing content, remember that the directory is by default owned by the
root user. Commands that might modify the directory’s contents must, as a result, be prefixed with
sudo in order to maintain functionality. Considering the fact that content is likely to be changed often, this is not very convenient. The easiest thing to do is to change both the owning user and the owning group to your username, but this means that if you implement PHP in the future that modifies files in this directory, it won’t work since PHP runs under the Apache user (
www-data). So, all we need to do is change the owner to your user (
<username>), and the group to
chown -R <username>:www-data .
This command recursively changes the owner of the directory, meaning that the owner is changed for every file rather than just the one specified. World Wide Web Data (
www-data) is the group which Apache using meaning that the server can read and write as well. Instead of using a complete path as the target directory, a period (
.) is used indicating the target is the current directory.
Putting it to Work
Now that we have full read and write access to the directory, it’s time to make some changes. When the contents of the
html directory is viewed, we can see that there is a file called
index.html. The index file is what loads whenever you open the website without specifying a different file (e.g endev.xyz/ vs endev.xyz/blog/). HTML is the file extension used by default, however, if your site will be using PHP you will need to have your files end with
The only thing left to do is delete the default index file or rename it using one of the commands below. Since you don’t need root privileges, you can use your favourite text editor to make further changes. Everything past this is up do you, directory structure, pages, and anything else.
Remove Index File:
Rename Index File:
mv index.html <name>.html
More About DocumentRoots
There is a lot more to know about the Apache DocumentRoot. You can create multiple different ones, much like you will find yourself doing when you make your website live and accessible through a custom domain name. However, this is past the scope of one article. Check back in a few days, though, to find out more about the DocumentRoot!