HTTPD - Apache2 Web Server. Apache is the most commonly used Web server on Linux systems. Web servers are used to serve Web pages requested by client computers. Clients typically request and view Web pages using Web browser applications such as Firefox, Opera, Chromium, or Internet Explorer. The Apache HTTP Server ('httpd') was launched in 1995 and it has been the most popular web server on the Internet since April 1996. It has celebrated its 25th birthday as a project in February 2020. The Apache HTTP Server is a project of The Apache Software Foundation. Apache httpd 2.4.46 Released 2020-08-07 ¶. HTTPD - Apache2 Web Server Apache is the most commonly used Web server on Linux systems. Web servers are used to serve Web pages requested by client computers. Clients typically request and view Web pages using Web browser applications such as Firefox, Opera, Chromium, or Internet Explorer.
Apache is a popular web server application you can install on the Raspberry Pi to allow it to serve web pages.
On its own, Apache can serve HTML files over HTTP, and with additional modules can serve dynamic web pages using scripting languages such as PHP.
Install Apache
First, update the available packages by typing the following command into the Terminal:
Then, install the apache2
package with this command:
Test the web server
By default, Apache puts a test HTML file in the web folder. This default web page is served when you browse to http://localhost/
on the Pi itself, or http://192.168.1.10
(whatever the Pi's IP address is) from another computer on the network. To find the Pi's IP address, type hostname -I
at the command line (or read more about finding your IP address).
Apache Httpd Web Server Port
Browse to the default web page either on the Pi or from another computer on the network and you should see the following:
This means you have Apache working!
Changing the default web page
This default web page is just an HTML file on the filesystem. It is located at /var/www/html/index.html
.
.svg/1200px-Apache_HTTP_server_logo_(2019-present).svg.png)
Navigate to this directory in a terminal window and have a look at what's inside:
This will show you:
This shows that by default there is one file in /var/www/html/
called index.html
and it is owned by the root
user (as is the enclosing folder). In order to edit the file, you need to change its ownership to your own username. Change the owner of the file (the default pi
user is assumed here) using sudo chown pi: index.html
.
You can now try editing this file and then refreshing the browser to see the web page change.
Your own website
If you know HTML you can put your own HTML files and other assets in this directory and serve them as a website on your local network.
Apache Httpd Documentation
Additional - install PHP
To allow your Apache server to process PHP files, you'll need to install the latest version of PHP and the PHP module for Apache. Type the following command to install these:
Now remove the index.html
file:
and create the file index.php
:
Put some PHP content in it:

Now save and refresh your browser. You should see 'hello world'. This is not dynamic but still served by PHP. Try something dynamic:
or show your PHP info:
Further - WordPress

Now you have Apache and PHP installed you can progress to setting up a WordPress site on your Pi. Continue to WordPress usage.
Error Log
Related Modules | Related Directives |
---|

The server error log, whose name and location is set by the ErrorLog
directive, is the most important log file. This is the place where Apache httpd will send diagnostic information and record any errors that it encounters in processing requests. It is the first place to look when a problem occurs with starting the server or with the operation of the server, since it will often contain details of what went wrong and how to fix it.
The error log is usually written to a file (typically error_log
on Unix systems and error.log
on Windows and OS/2). On Unix systems it is also possible to have the server send errors to syslog
or pipe them to a program.
The format of the error log is defined by the ErrorLogFormat
directive, with which you can customize what values are logged. A default is format defined if you don't specify one. A typical log message follows:
[Fri Sep 09 10:42:29.902022 2011] [core:error] [pid 35708:tid 4328636416] [client 72.15.99.187] File does not exist: /usr/local/apache2/htdocs/favicon.ico
The first item in the log entry is the date and time of the message. The next is the module producing the message (core, in this case) and the severity level of that message. This is followed by the process ID and, if appropriate, the thread ID, of the process that experienced the condition. Next, we have the client address that made the request. And finally is the detailed error message, which in this case indicates a request for a file that did not exist.
A very wide variety of different messages can appear in the error log. Most look similar to the example above. The error log will also contain debugging output from CGI scripts. Any information written to stderr
by a CGI script will be copied directly to the error log.
Putting a %L
token in both the error log and the access log will produce a log entry ID with which you can correlate the entry in the error log with the entry in the access log. If mod_unique_id
is loaded, its unique request ID will be used as the log entry ID, too.
During testing, it is often useful to continuously monitor the error log for any problems. On Unix systems, you can accomplish this using:
