Anime-Sanctuary

Your first website with Apache

Your server is running, but nobody can see a page on it. Let's install Apache, the program that serves websites, and publish a first page at your domain name.

Course
Tutorial 17 of 35
Time
30 min to read
Tested with
Commands: tested on Debian 13.7 (Apache 2.4.69)
What you will be able to do
  • Install Apache and see its default page.
  • Open port 80 in ufw so the whole world can knock.
  • Publish a page of your own in /var/www/exemple with a VirtualHost.
  • Check the configuration before reloading it, and read the logs.

Before you start: A firewall with ufw, Updates and packages with apt.

Contents
  1. What a web server is
  2. Install Apache
  3. Open port 80
  4. Write your first page
  5. Create a VirtualHost for exemple.fr
  6. Read the logs
  7. If it fails
  8. What's next
  9. Sources

How do you install Apache on Debian and publish a first website? Your server is installed, updated and protected, but it doesn't answer any browser yet. In half an hour, we will install Apache, open the right door, put a page of your own in it and read what Apache has to say. At the end, an address like exemple.fr will show your text.

What a web server is

A web server is a program that waits for a browser to ask for a page, then sends it back. Think of a bookseller: you ask for a book, they pick it off the shelf and hand it over. The request travels in a language called HTTP. It knocks on the server's door number 80, the one for websites (see The words: IP, DNS, domain, port, firewall).

There are several web servers. We pick Apache, one of the most widespread: it installs with one command, it is very well documented, and its settings live in readable files. Let's install it and see if it answers.

1Install Apache

Apache is a Debian package like any other (see Updates and packages with apt), named apache2, and it starts by itself.

On the server
sudo apt install -y apache2

The installation scrolls by for a few seconds. Let's see if Apache answers, using curl, a small browser with no window that prints the answer in the terminal. The address localhost means the machine itself: here, the server talks to itself.

On the server
curl -sI http://localhost/ | head -1
Expected output
HTTP/1.1 200 OK

The code 200 means "all good, here is the page". Let's also read the title of that page, which Debian prepared for you.

On the server
curl -s http://localhost/ | grep -o "<title>[^<]*</title>"
Expected output
<title>Apache2 Debian Default Page: It works</title>

"It works": Apache is serving Debian's default page. But only the server sees it for now, because the firewall keeps door 80 closed.

2Open port 80

For the rest of the world to reach Apache, tell ufw to let port 80 through, over TCP. It's the same rule as for SSH in A firewall with ufw, with a different number.

On the server
sudo ufw allow 80/tcp
Expected output
Rule added
Rule added (v6)

The two lines are the IPv4 version and the IPv6 version of the same rule. Now let's try from your computer, with the server's IP address, the number that identifies it on the network.

On your computer
curl -sI http://203.0.113.10/ | head -1
Expected output
HTTP/1.1 200 OK

You can also type this address in your browser: the "Apache2 Debian Default Page" should appear. The server is reachable. But port 80 isn't encrypted, so put no password on this site until the article on HTTPS. You still need a page of your own, and a folder to keep it in.

3Write your first page

Each site has its own folder. By habit, they live under /var/www, and ours will be called /var/www/exemple. It's the "site root": Apache looks there for the files to send.

On the server
sudo mkdir -p /var/www/exemple

Let's write the index.html file in it, the name every web server looks for first when someone asks for a folder. A web page is text wrapped in tags: h1 marks a big heading, title the name of the tab. The tee command copies everything that follows into the file, up to the EOF line, which marks the end of the text.

On the server
sudo tee /var/www/exemple/index.html > /dev/null <<EOF
<!DOCTYPE html>
<html lang="fr">
<head>
  <meta charset="UTF-8">
  <title>Bonjour</title>
</head>
<body>
  <h1>Bonjour depuis exemple.fr</h1>
</body>
</html>
EOF

The command prints nothing, which is a good sign. Let's check that the file is there, with its permissions. Apache runs under an account named www-data and must be able to read the file (see Users, sudo and file permissions).

On the server
ls -l /var/www/exemple
Expected output
total 4
-rw-r--r-- 1 root root 158 Nov  5 01:43 index.html

The r letters in -rw-r--r-- say that everyone can read the file, www-data included. The date and size will be your own. Still, Apache doesn't know about this folder yet: let's introduce your site to it.

4Create a VirtualHost for exemple.fr

A VirtualHost is a site's block of settings: its name, its folder, its logs. A single Apache can carry as many as you like, and it picks the right one from the domain name the browser asks for. Picture an apartment building with one mailbox per tenant.

VirtualHosts live in /etc/apache2/sites-available/, one file per site. Here is ours, setting by setting:

  • ServerName: the site's domain name. ServerAlias adds a second one, here with www.
  • DocumentRoot: the site's folder, the one from step 3.
  • ErrorLog and CustomLog: the site's two logs, one for errors, the other for every visit. The ${APACHE_LOG_DIR} variable stands for /var/log/apache2.
On the server
sudo tee /etc/apache2/sites-available/exemple.fr.conf > /dev/null <<'EOF'
<VirtualHost *:80>
    ServerName exemple.fr
    ServerAlias www.exemple.fr
    DocumentRoot /var/www/exemple
    ErrorLog ${APACHE_LOG_DIR}/exemple-error.log
    CustomLog ${APACHE_LOG_DIR}/exemple-access.log combined
</VirtualHost>
EOF

The *:80 at the start means "on all of the server's addresses, port 80". The file sits in sites-available, but Apache only reads sites-enabled. The a2ensite command ("apache2 enable site") links one to the other.

On the server
sudo a2ensite exemple.fr.conf
Expected output
Enabling site exemple.fr.

The answer then reminds you to reload Apache's configuration. Let's check it first: a typo reloaded live can bring all your sites down, while a test costs nothing.

On the server
sudo apache2ctl configtest
Expected output
Syntax OK

If an AH00558 line talks about a "fully qualified domain name", it's only a harmless warning: only Syntax OK counts. Now let's reload. This applies the configuration without cutting off the visitors already there.

On the server
sudo systemctl reload apache2

To test, let's ask for the page while giving the site's name with -H, as a browser visiting exemple.fr would.

On your computer
curl -s -H "Host: exemple.fr" http://203.0.113.10/ | grep h1
Expected output
  <h1>Bonjour depuis exemple.fr</h1>

That's your page. Without the site's name, Apache still serves the default page: it needs the name to pick the tenant. In a browser, http://exemple.fr will work as soon as that name points at the server's address, which is covered in Domain name and DNS. Apache wrote these visits down somewhere: let's go see where.

5Read the logs

Apache keeps two logs, stored in /var/log/apache2/: the access log notes every visit, the error log notes what went wrong. They are the two files named in the VirtualHost. Let's look at the last three visits.

On the server
sudo tail -n 3 /var/log/apache2/exemple-access.log
Expected output
127.0.0.1 - - [05/Nov/2026:01:45:44 +0000] "GET / HTTP/1.1" 200 409 "-" "curl/8.14.1"
127.0.0.1 - - [05/Nov/2026:01:45:44 +0000] "GET /absent.html HTTP/1.1" 404 473 "-" "curl/8.14.1"
127.0.0.1 - - [05/Nov/2026:01:45:44 +0000] "GET / HTTP/1.1" 403 476 "-" "curl/8.14.1"

The addresses, dates and programs will be your own. Each line reads in this order:

  • the visitor's address (here 127.0.0.1, the machine itself) then the date;
  • the request in quotes: GET / means "give me the home page";
  • the response code right after: 200 success, 404 page not found, 403 access denied;
  • the size of the response in bytes, then the visitor's browser.

To follow a log live during your tests, add -f to tail and quit with Ctrl+C. The third line shows what happens when Apache can no longer read the file: a 403 refusal, whose reason the error log gives.

On the server
sudo tail -n 1 /var/log/apache2/exemple-error.log
Expected output
[Thu Nov 05 01:45:44.961002 2026] [core:error] [pid 5529:tid 5533] (13)Permission denied: [client 127.0.0.1:43624] AH00132: file permissions deny server access: /var/www/exemple/index.html

The end of the line gives the reason: "file permissions deny server access". This case, and two others, have their fix right below.

If it fails

Three situations come up most often, with their cause:

  • A 403 error (Forbidden). Apache found the site but isn't allowed to read it. If the error log says AH00132: file permissions deny server access, check with ls -l. When the r letters are missing for everyone, give read access to all with sudo chmod 644 /var/www/exemple/index.html. With search permissions are missing on a component of the path, a folder is blocking: sudo chmod 755 /var/www/exemple.
  • A 404 error (Not Found). The requested address doesn't exist in the site's folder: check the spelling of the file, capital letters included. The access log notes it, the error log stays silent.
  • The "Apache2 Debian Default Page" instead of yours. Apache didn't recognize the site's name: the address was typed with no domain name, or matches neither ServerName nor ServerAlias. Check that sudo a2query -s lists exemple.fr and that you reloaded.
Two rarer cases
  • A 403 with AH01630: client denied by server configuration. The site's folder is outside /var/www, where Apache refuses everything by default. Keep your sites under /var/www.
  • An "Index of /" page. The site's folder has no index.html file, so Apache shows the list of its contents. Create the file in step 3.

And if configtest refuses? It names the file and the line. For example, <VirtualHost> was not closed points to a forgotten </VirtualHost>. Fix it, then run configtest again until you get Syntax OK.

What's next

Your page is online, but it travels in the clear: anyone on the way can read or change it, and browsers show "Not secure". The certificate that encrypts the connection and adds the padlock is free. The next article, HTTPS with Let's Encrypt, installs it on this same site.