The most reliable way to install PHP on ubuntu is using ondrej/php PPA repository.
At first, it makes sense to upgrade installed packages:
sudo apt update && sudo apt upgrade
Also, install software-properties-common
package to make add-apt-repository
command available.
sudo apt install software-properties-common
Next need to add ondrej/php PPA repository:
sudo add-apt-repository ppa:ondrej/php
Now we are ready to install PHP.
sudo apt install php8.0
Note that you can specify PHP version to be installed - just change 8.0
to any other version you need.
Installing php8.0
package will also install a module for apache2
. If you are going to use nginx as a webserver install php8.0-fpm
package than:
sudo apt install php8.0-fpm
Also you can install CLI version if you are not going to use any webserver:
sudo apt install php8.0-cli
To verify installation use the next command:
php -v
PHP 8.0.13 (cli) (built: Nov 22 2021 09:50:43) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.13, Copyright (c) Zend Technologies
with Zend OPcache v8.0.13, Copyright (c), by Zend Technologies
Popular knowhows
pubsub
gcloud
docker
3 years ago
go
golang
testing
2 years ago