PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used open source general-purpose scripting language that is especially suited for web development and can be embedded into HTML. Show Most of the popular PHP frameworks and applications including WordPress , Laravel , Drupal and Nextcloud are compatible with PHP 7.2. PrerequisitesBefore starting with this tutorial, make sure you are logged in as a user with sudo privileges . Installing PHP 7.2 with ApacheIf you are using Apache as your web server to install PHP and Apache PHP module run the following command:
Once the packages are installed restart the Apache service:
Installing PHP 7.2 with NginxUnlike Apache, Nginx doesn’t have a built in support for processing PHP files so we need to install a separate application such as PHP FPM (“fastCGI process manager”) which will handle PHP files. To install the PHP and PHP FPM packages run the following command:
Once the packages are installed you can check the status of the PHP FPM service with:
You can now edit the Nginx server block and add the following lines so that Nginx can process PHP files:
Do not forget to restart the Nginx service so that the new configuration take effect:
Installing PHP extensionsTo extend the core functionality of PHP you can install some additional extensions. PHP extensions are available as packages and can be easily installed with:
For example if you want to install MySQL and GD PHP extensions you would run the following command:
After installing a new PHP extension do not forget to restart the Apache or the PHP FPM service, depending on your setup. Testing PHP ProcessingTo test whether your web server is configured properly for PHP processing, create a new file called info.php inside the 8 directory with the following code:/var/www/html/info.php
Save the file, open your browser of choice and visit 9The 0 function will print information about your PHP configuration as shown on the image below:Installing PHP 7.3 on Ubuntu 18.04PHP 7.3 is the latest stable release of PHP. Perform the steps below to install PHP 7.3 on on Ubuntu 18.04.
Installing PHP 7.1 on Ubuntu 18.04Use PHP 7.1 only if you’re going to install applications that is not compatible with PHP 7.2. Follow the steps below to install PHP 7.1:
ConclusionYou have successfully installed PHP on your Ubuntu 18.04 server. You can also read about how to How to Install and Set up a PHP Project with Composer . |