003 Install and setup PHP 7.x
PHP is a serverside programming language for web servers. We will be installing PHP for Apache2. At the time of this writing PHP, 8.2.0 is out, but it’s not yet supported in the main distribution path. Because of this, we will be installing PHP 7.4. There are ways of installing 8.2.0 on your Pi, but I don’t like to add a 3rd party distribution to my Raspberry Pi. If that Distro was from PHP.net I would happily add it.
Requirements:
- Raspberry Pi 3 or newer
- 001 Install the command-line-only version of Raspberry Pi OS – The Great Mojave Rover
- 002 Install and Setup up Apache Web Server – The Great Mojave Rover
- Your Raspberry Pi is connected to your network.
Installing the latest supported version of PHP on your Raspberry PI
sudo apt install php-common libapache2-mod-php php-cli
Once that is completed, it is a good idea to reboot your Pi.
sudo reboot
Hello World
As is tradition, let’s add a Hello World! page using PHP and test it from our PC or MAC.
From the command line type:
sudo nano /var/www/html/hello.php
Once in the nano text editor type:
<?php echo ('Hello World!') ?>
Then do a Control-X, then Y, then enter to save your file.
Now from your PC or Mac, navigate to the IP address and filename
Example: HTTP://172.16.42.197/hello.php
You should see this:
You now have the basic installation of PHP completed on your Pi.