Basics
In order to install recent versions of PHP you have to add a repository to your system. Ondrej Sury maintains that repository which is why in most tutorials you have to add his repository.
To see which versions are available to your current repositories you can use the command:
Please note that the following instructions are for Linux.
To see which php modules are available, you should first find which version of Ubuntu you have. You can do that with the following command:
cat /etc/os-release
Then you can navigate to https://packages.ubuntu.com, select your version and then search for PHP. For example for Bionic, you should go here.
Alternatively you can use apt:
sudo apt-cache search php | grep ^php8.0
As PHP evolves many modules are moved to core PHP which means that you do not have to install them separately in spite of the fact that many tutorials try to do so.
Install prerequisites
System prerequisites
sudo apt install ca-certificates apt-transport-https software-properties-common
System required PPA
Add the Ondrej Sury PPA to have access to more recent versions of PHP:
sudo add-apt-repository ppa:ondrej/php
Update the system repositories:
sudo apt update
Laravel listed requirements
Laravel 8.0 defines the following modules are requlred:
Documentation | Action needed |
---|---|
BCMath | Requires installation |
CType | Already included in PHP 8.0 commons |
Fileinfo | Already included in PHP 8.0 commons |
JSON | Already included in PHP 8.0 commons |
MbString | Requires installation |
OpenSSL | Requires installation |
PDO PHP | |
Tokenizer | Already included in PHP 8.0 commons |
XML | Requires installation |
Composer requirements
You can list the composer requirements with the following command:
php composer.phar check-platform-reqs
All In One command
The following command installs all of those mentioned above. Use it at your own risk:
sudo apt install openssl php8.0 php8.0-bcmath php8.0-mbstring php8.0-xml php8.0-curl php8.0-zip php8.0-mysql
Install PHP core
Install PHP core:
sudo apt install php8.0
Install modules
Required Modules
BCmath
sudo apt install php8.0-bcmath
Ctype
No need to install it separately.
FileInfo
No need to install it separately. For more info read here.
JSON
No need to install it after version 8. For more info read here.
Mbstring
sudo apt install php8.0-mbstring
OpenSSL
sudo apt install openssl
Tokenizer
No need to install it separately.
XML
sudo apt install php8.0-xml
Optional Modules
Curl
Although it is not listed on Laravel server requirements it is needed for composer.
sudo apt install php8.0-curl
ZIP
Useful for composer:
sudo apt install php8.0-zip
MySQL
Required for MySQL only:
sudo apt install php8.0-mysql