PHP is a popular general-purpose scripting language especially suited to web development. Fast, flexible and pragmatic, PHP powers everything from your blog to the most popular websites in the world.
How to Install
The method of installing MySQL may vary per Linux distribution.
Debian & Ubuntu
sudo apt update
sudo apt install php-fpm php-mysql
Optionally, you can install additional PHP extensions
sudo apt install php-curl php-gd php-mbstring php-xml php-zip -y
AlmaLinux & CentOS
This is a little bit more extensive as we need to install a package manager and enable PHP before installing it
sudo dnf install epel-release -y
sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm -y
sudo dnf module reset php
sudo dnf module enable php:remi-8.1 -y
sudo dnf install php php-mysqlnd -y
Verify Installation
To verify you have PHP installed you can run the below command to have the output returned.
Note; you may need to restart your terminal application to run the command
php -v
The verification output may look like the below, which will also show the version you installed
PHP 8.3.3-1+ubuntu20.04.1+deb.sury.org+1 (cli) (built: Feb 15 2024 18:38:21) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.3, Copyright (c) Zend Technologies
with Zend OPcache v8.3.3-1+ubuntu20.04.1+deb.sury.org+1, Copyright (c), by Zend Technologies