Behind the curtain, your web server uses http to display files located on a machine. In our example, Apache is showing a file called
index.html located in a subdirectory of our Apache installation. It would be better if we could work in whatever directory we please. (The file’s actually called
index.html.en because of language switching, but let’s stick to
index.html for now.)
Let’s create a directory and point our web server to the directory:
- Create a directory called
htdocsin your home directory, namely at
/home/username/htdocs, where username stands for your user account’s real user name.
- Open your Apache configuration file, located at
Provide administrator credentials as needed. (If you aren’t using a recent version of Ubuntu or another Debian-based distro, try looking under
- Within the file, find the following line:
DocumentRoot /var/www/html. Change this line so that it points to your own
- At this point you should add some file access restrictions. Add the following lines under the
DocumentRootline, substituting your name for
<Directory /> Options FollowSymLinks AllowOverride None Require all denied </Directory> <Directory /home/USERNAME/htdocs/> Options Indexes FollowSymLinks MultiViews AllowOverride None Require all granted </Directory>
- Save the file.
- Restart Apache with this terminal command:
sudo apachectl restart. Provide your administrative password when prompted.
localhostin your browser. If all went according to plan, you’ll see the directory’s index (as pictured below). By default the index is a list of all the files in the directory, but we’ll show you next how to customize the index page.