Apache Web Server Raspberry Pi

Posted on  by admin

To create an Apache-based web server, using a common Ubuntu or Debian machine, proceed as follows. Install Apache sudo apt-get update sudo apt-get install apache2 To check if it’s correctly installed, go to the site localhost you should find ‘It works! Configuration All configuration files can be found in '/etc/apache2' this can be displayed via Install and configure Apache web.

Installing PHP/Apache

Install Rasbian software on the Raspberry Pi. I strongly suggest setting a password for the device. Once the Raspberry Pi has been loaded with software, update the software. At the prompt, type: sudo apt-get update. Install the apache web server. At the prompt type: sudo apt-get install apache2 –y. Check the configuration in the browser. You will want to associate the Raspberry Pi’s IP address so that it will receive all incoming requests on port 80 or whatever port you find most appropriate. The most secure web server is one that is not connected to the Internet;-) Second to that, we should limit the access in our apache conf file to allow ONLY our IP and those known to us.

This is based on the nifty webiopi guide here.

Install Apache and PHP
Apache Web Server Raspberry Pi

Nginx Web Server

Add Apache's user (www-data) to the sudoers if needed

This may be necessary if you want web pages to control IO pins etc. Note that by doing this you introduce the possibility of security vulnerabilities via apache. If you are using your RPi on a local network and this is not a concern then you may well not care about this but if you are using your RPi on a public network where security is a concern then you may want to skip this step and find an alternative solution if you hit security permission issues.

Add this line to the end of the file:

Press CTRL + X to save and exit.

Restart Apache

If you type your Raspberry Pi IP address into the web browser on a machine connected to the network you should see the apache default web page appear.

Adding Your HTML, PHP etc Files

Copy them into the '/var/www/html/' directory.

You will need root permission to write to this directory, so if you are using the GUI file manager use 'sudo su' to elevate yourself to the root user before starting the GUI with 'startx'

Restarting Apache

Change The Password!

If your RPi will be connected to the internet or a public network a priority is to make the Raspberry Pi more secure by not using the default username and password. To change the password for the pi user after logging in:

Apache Web Server Raspberry Pi

Performance Tuning

Web

If you are not using the HDMI out it is sensible to reduce the amount memory given to the RPi graphics to say 16MB using the config tool:

Server

Raspberry Pi Apache Web Server Gpio

The configuration file
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.