How to install PHP 7.2 on Ubuntu 18.04
How to install PHP 7.2 on Ubuntu 18.04
Install PHP on Ubuntu 18.04
PHP is currently one of the most popular programming languages ββin the world. PHP has different versions 5.6, 7.0, 7.1, and 7.2. Currently, PHP 7.2 is the latest version of PHP that supports various frameworks such as WordPress, Laravel, Code-Igniter. Ubuntu 18.04 comes with default PHP 7.2 support, so you can easily install PHP 7.2 on Ubuntu 18.4. Ubuntu 18.04 is the current latest version of Ubuntu. This tutorial outlines how to install PHP 7.2 on Ubuntu 18.04.
Precondition
Before installing PHP 7.2 on Ubuntu 18.04. Requires non-root user account on server with sudo privileges
1. Install PHP using Nginx
Nginx does not support native PHP processing. Must be installed “FastCGI Process Manager” Also known as php-fpm
Execute the following command to install php-fpm on the server. The following command installs php-fpm7.2
sudo apt install php-fpm
You can check if it is installed correctly with the following command
systemctl status php7.2-fpm
You can check the PHP version by running the following command:
php -v
2. Install PHP using Apache
If you are running Apache on the backend, you need to install PHP and the Apache PHP module on your server. To install PHP 7.2 and Apache modules, type the following command and press Enter:
sudo apt install php libapache2-mod-php
After installing PHP and the apache-php module, you need to restart the Apache server by entering the following command:
sudo systemctl restart apache2
3. Install the PHP extension
To run a framework-like WordPress on a server, you need to install some basic PHP extensions. To install any of the PHP extensions on the server, you need the following basic format:
sudo apt install php-[name_of_the_extension]
You can install the curl extension for PHP by running the following command:
sudo apt install php-curl
Below are the basic PHP extensions that need to be installed on the server.
sudo apt install php7.2-curl php7.2-mysql php7.2-common php7.2-cli php7.2-gd php7.2-opcache
You can use the above format to install more extensions.
4. Testing PHP processing
To test if PHP is properly configured on the server, you need to create a file test.php in the directory var/www/html/
With the following code.
If you see the following output, you have successfully installed PHP.
Conclusion
In this tutorial, you learned and successfully tested how to successfully install PHP 7.2 on Ubuntu 18.04, using some basic extensions to help with the framework. If you have any questions about this, you can comment below.
Related tutorials
- How to install Nginx on Ubuntu 18.04
- How to protect SSL by encrypting SSL on Ubuntu 18.04