Monday, 18 February 2019

RPi install Apache/PHP WEB-server

Updated 2019-02-18 !

As a part of one of my project, the ultimate Weather site ?? Weather34, I needed a WEB-host with PHP.

I started up with a fresh Raspbian Lite SD Card with Samba installed.

Update the OS with 

sudo apt-get update
sudo apt-get upgrade
sudo apt-get clean

Log on, with ssh, to the RaspberryPi(RPi), with in this case hostname "pws01", and start to install the Apache server with

$ sudo apt-get install apache2

Check that the Apache server works with a WEB-browser and the URL


And the default Apache2 page will show (See picture)

Apache log files is available at /var/log/apache2 and documentation at

Install PHP 7.2 on Raspbian "Stretch"

Maybe You already have a PHP installation ? Then run 

$ sudo apt-get remove '^php.*'

to remove it.

Set the scene with 

wget -q -O- | sudo apt-key add -
echo "deb stretch main" | sudo tee /etc/apt/sources.list.d/php.list

Install PHP 7.2 and 2 additional packages with

$ sudo apt install php7.2 php7.2-curl php7.2-mbstring

Check the install

$ php -v 

And something like this will show

$ php -v
PHP 7.2.11-2+0~20181015120859.6+stretch~1.gbp8105e0 (cli) (built: Oct 15 2018 12:08:59) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.11-2+0~20181015120859.6+stretch~1.gbp8105e0, Copyright (c) 1999-2018, by Zend Technologies

Create a Samba share for the default Apache document root which will make it very simple to add and edit files on the RPi from Your Mac or PC.

$ sudo nano /etc/samba/smb.conf

add this at the end of the file

   comment = Apache folders   
   read only = no
   locking = no
   path = /var/www/html/    
   guest ok = no

and restart the Samba server.

$ sudo /etc/init.d/samba restart

Add the default Apache user 

$ sudo smbpasswd -a www-data
New SMB password:
Retype new SMB password:
Added user www-data.

Log on to the RPi, from Your PC/Mac, and create a file "phpinfo.php" with following text


and place it in the RPi folder 


In Your browser use the URL below to check that everything works


and the information about PHP and the server will show.

If there is a need for restarting the Apache server use 

$ sudo service apache2 restart

Now You can move on to install the Weather34 project or use the WEB-server to something else.