Read in 2 minutes
How to Install Apache Web Server on Raspberry Pi
Apache HTTP server is one of the most popular web servers in the world. It is an open-source and cross-platform HTTP server that powers a large percentage of the Internet’s websites. Apache provides many powerful features that can be extended through additional modules.
In this tutorial, we will explain how to install Apache Web server on Raspberry Pi. We’re assuming that you have Raspbian installed on your Raspberry Pi.
Apache is available in the default Raspbian repositories and the installation is pretty straightforward.
First, update the package index and afterward install the
apache2 package by running the following commands:
sudo apt update sudo apt install apache2
That’s it,at this point you have Apache web server installed on your Raspberry Pi.
To verify that everything works as expected, open your browser, type your Raspberry Pi IP address
http://PI_IP and you will see the default Apache welcome page as shown on the image below:
The page includes some basic information about Apache configuration files, helper scripts, and directory locations.
This default Apache web page is named
index.html and it is stored in the
/var/www/html directory. If you want to modify this page you need to edit the file as a sudo user. You can also remove the file and add your own HTML files.
Apache log files
error.log are located in the
/var/log/apache directory. If you experience any issue the log files should tell you what went wrong.
If you want to serve dynamic PHP files on your Raspberry Pi you’ll need to install PHP and PHP Apache module:
sudo apt install php libapache2-mod-php
Once the packages are installed to enable the PHP module, restart the Apache service:
sudo systemctl restart apache2
To test whether your Apache web server is configured properly for PHP processing, create a new file called
info.php inside the
/var/www/html directory with the following code:
Save the file, open your browser of choice and visit
http://PI_IP/info.php. This page will show information about your PHP configuration.
You have successfully installed Apache and PHP on your Raspberry Pi board. You can now start using Apache as a web or proxy server.
If you have any question or feedback, feel free to leave a comment.