razzi.abuissa.net

Razzi's guide to apache

Install apache:

$ sudo apt install apache2

It’s running!

razzi@lima-default:~$ curl -I localhost
HTTP/1.1 200 OK
Date: Fri, 03 Jan 2025 23:20:52 GMT
Server: Apache/2.4.58 (Ubuntu)

Opening http://localhost will show the iconic “it works” page:

That kinda gives you instructions. Namely you want to to replace the file at /var/www/html/index.html. Here’s how I back it up to my home directory in case I want to look at it later:

$ mkdir tmp
$ sudo mv /var/www/html/index.html tmp/

However you’ll notice I had to use sudo to do that. In fact the /var/www/html folder is owned by root:

razzi@lima-default:~$ ls -lh /var/www/
total 4.0K
drwxr-xr-x 2 root root 4.0K Jan  3 17:37 html

You could edit a file in your home directory and sudo cp it to /var/www/html, but I’d prefer to have the changes reflected immediately.

So I make a /srv/ directory owned by the user which will edit the files, then make the config use that.

The main config options that you’ll need to make this work (I also use a higher port, 5000, for local development):

Listen 5000

DocumentRoot "/srv"

<Directory "/srv">
  Require all granted
</Directory>

Remember to restart your server after you make changes to have them applied:

$ httpd -k restart