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
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.
sudo apt install -y apache2The 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.
curl -sI http://localhost/ | head -1HTTP/1.1 200 OKThe code 200 means "all good, here is the page". Let's also read the title of that page, which Debian prepared for you.
curl -s http://localhost/ | grep -o "<title>[^<]*</title>"<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.
sudo ufw allow 80/tcpRule 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.
curl -sI http://203.0.113.10/ | head -1HTTP/1.1 200 OKYou 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.
sudo mkdir -p /var/www/exempleLet'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.
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>
EOFThe 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).
ls -l /var/www/exempletotal 4
-rw-r--r-- 1 root root 158 Nov 5 01:43 index.htmlThe 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.ServerAliasadds a second one, here withwww.DocumentRoot: the site's folder, the one from step 3.ErrorLogandCustomLog: the site's two logs, one for errors, the other for every visit. The${APACHE_LOG_DIR}variable stands for/var/log/apache2.
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>
EOFThe *: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.
sudo a2ensite exemple.fr.confEnabling 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.
sudo apache2ctl configtestSyntax OKIf 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.
sudo systemctl reload apache2To test, let's ask for the page while giving the site's name with -H, as a browser visiting exemple.fr would.
curl -s -H "Host: exemple.fr" http://203.0.113.10/ | grep h1 <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.
sudo tail -n 3 /var/log/apache2/exemple-access.log127.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.
sudo tail -n 1 /var/log/apache2/exemple-error.log[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.htmlThe 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 saysAH00132: file permissions deny server access, check withls -l. When therletters are missing for everyone, give read access to all withsudo chmod 644 /var/www/exemple/index.html. Withsearch 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
ServerNamenorServerAlias. Check thatsudo a2query -slistsexemple.frand 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.htmlfile, 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.