Install PHP on Ubuntu Linux
Overview
In this tutorial, we’ll be going through the steps to install PHP on Ubuntu Linux machine. PHP is one of the component in the LAMP stack.
Apache Install
https://www.testingdocs.com/install-apache-http-server-on-ubuntu-linux/
MySQL Install
https://www.testingdocs.com/install-mysql-server-on-linux/
In this series of installing LAMP ( Linux, Apache, MySQL server and PHP) stack components, the last step is to install PHP. PHP is an open-source server-side scripting language. The latest version pf PHP is 7.4. We will install the latest version in this article. So, let’s get started!
Environment: Ubuntu Linux Server LTS.
Install PHP
Log in to the Linux box with a user having sudo privileges.
Open command line Terminal window.
Issue the following command
$ sudo apt install php
Install PHP extensions
PHP extensions are available as packages and can extend the functionality of PHP instance. To install a new PHP extension, we can run the command in the terminal window as shown.
$ sudo apt install <php extension name>
For example, if we want to install MySQL extension, we can run the following command in the terminal window:
$ sudo apt install php-mysql
Verification
Open a terminal window and type the following PHP version command.
$ php -version
That’s it! We are done with the PHP installation on Ubuntu.
Test PHP on Apache Server
Create a PHP file with the following command. Place the folder under the Apache serving directory.
Access the page from the web browser. The page should display the PHP information.
Sample Test File
<?php /************************************************************************* * This is to test PHP 7 configuration with Apache2 * www.TestingDocs.com *************************************************************************/ echo "If you see this PHP Configuration with Apache is OK!- www.TestingDocs.com"; echo phpinfo(); ?>