Loading Web server software.
Referance: How to Setup a Raspberry Pi Apache Web Server – Pi My Life Up
1. Before we install Apache to our Raspberry Pi, we must first ensure the package list is up to date by running the following two commands.
sudo apt-get update
sudo apt-get upgrade
2. First, we will need to install the Apache2 package on our Raspberry Pi.
For those who don’t know what Apache is, it is a server software that serves the HTML files from a computer to the web browser.
To install apache2 on your Raspberry Pi, enter the following command into the terminal.
sudo apt install apache2 -y
3. With Apache2 installed to our Raspberry Pi, we now have an extremely basic web server up and running. The server will be able to provide non-dynamic content such as HTML files.
In the next section, we will be extending this basic Apache web server by installing PHP to the Raspberry Pi.
To check that Apache is up and running on your Raspberry Pi, you can enter the Raspberry Pi’s IP address into a web browser. The server should return a webpage with some simple text on it.
If you forgot the IP address run the following command:
“ifconfig”
ifconfig wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.1.249 netmask 255.255.255.0 broadcast 192.168.1.255 inet6 fe80::9192:b666:669c:285e prefixlen 64 scopeid 0x20<link> ether dc:a6:32:08:09:5c txqueuelen 1000 (Ethernet) RX packets 317686 bytes 439240333 (418.8 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 117089 bytes 8392171 (8.0 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
If you do not know the IP, you can enter the hostname command into the terminal to retrieve it.
hostname -I
192.168.1.249
same as ip address.
4. In a web browser, enter your Raspberry Pi’s IP Address, it should connect and load a page like the one below.

5. The web page files are in this directoy. /var/www/html
type cd /var/www/html the line command ls will list the files in that directory. this will put you in the webpage direcoty
Firstly, we add the user pi (our user) to the www-data group, the default group for Apache2.
Secondly, we give ownership to all the files and folders in the /var/www/html directory to the www-data group.
sudo usermod -a -G www-data aranet
sudo chown -R -f www-data:www-data /var/www/html
sudo chmod 775 /var/www/html
sudo chown aranet /var/www/html
Setting up PHP7 for Apache
To start this section, we will need to go ahead and install php7.3 and several other packages to our Raspberry Pi. The additional packages we are installing are ones that are commonly used by PHP applications.
Lucky for us installing all the packages we need is a simple process as PHP 7.3 is available in the Raspbian package repository.
sudo apt install php -y
Run the following command to install all the PHP packages to your Raspberry Pi. Now that PHP is installed to our
Raspberry Pi, we can test it to make sure it’s working.
We can test to see PHP is working by creating a PHP file within the /var/www/html/ directory. Creating a file in this directory will allow it to be processed and displayed when you open it in a web browser.
For our example, we will be creating a PHP file called index.php. We can create this file by issuing the following command.
sudo nano /var/www/html/index.php
3. In this file, we need to add the following lines on PHP code.
<?php
echo "Today's date is ".date('Y-m-d H:i:s');
?>
Now lets delete the index.html. We don’t need it anymore.
sudo rm /var/www/html/index.html
The code above is just an incredibly simple PHP script that prints out today’s date retrieved using PHP’s date() function. It will be enough to tell us that PHP is, in fact, up and running.
4. Now save the file by pressing Ctrl + X then pressing Y and hitting ENTER.
5. In your web browser, go to http://the ip address of your aranet raspberry pi.
Going to the following URL should display something like the following.
Today's date is 2019-06-28 21:30:45
If you see the current date and time we are good to go to the next step.