Sunday, 1 July 2018

RPi install Apache/PHP WEB-server


Updated 2018-10-16 !

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.

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

http://pws01/

And the default Apache2 page will show (See picture)

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

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 https://packages.sury.org/php/apt.gpg -O- | sudo apt-key add -
echo "deb https://packages.sury.org/php/ 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

[Apache_folder]
   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

<?php
 phpinfo();
?>

and place it in the RPi folder 

var/www/html

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

http://pws01/phpinfo.php

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.


No comments:

Post a Comment