For those who also want to know how to install a specific version of PHP on Ubuntu Linux, the steps below will also show them how to do that. The steps will also include options to find out what modules are installed with PHP on Ubuntu Linux as well. For those who don’t know what PHP is, here’s an overview: PHP is one of the most used server-side programming languages. Chances are many of the websites you visit today most likely are running PHP. And if you’re thinking of running a website, you find yourself using PHP server-side scripting language as well. To get started with finding out what version of PHP you’re running, or installing a specific PHP version on Ubuntu Linux, continue below.
How to find out what version of PHP you are running in Ubuntu Linux
Installing PHP on Ubuntu Linux is easy. Simply run the apt-get install php commands to get it installed. On the Ubuntu Linux command console, run the commands below to check the PHP version. Once you run the command above, it should output similar lines as below: As you can see, version number 7.4.3 is the latest version currently available in the Ubuntu repository, however, it doesn’t mean that it is the latest version of PHP available to be installed. You may also be able to find more info on the PHP version installed by running the commands below: When you run the commands above, it should list similar lines as below: The most reliable way of finding out what version of PHP is used for that specific website is to use the phpinfo() function, which prints various information about the PHP server, including its version. To use this step to find the PHP version, create a file called phpinfo.php in the web server’s root directory. Typically at the location below: In the file, copy and paste the line below, then save the file and exit. Next, open your browser, go to localhost/phpinfo.php or your domain name (example.com/phpinfo.php) and the version of the PHP server will be displayed on your screen:
How to find out what PHP modules are currently installed in Ubuntu Linux
Now that you know how to find out what version of PHP is installed on your system, the commands below show you how to list all the modules that are currently loaded with PHP. Once you run the commands above, it should output similar lines as below. Depending on your environment, the list above may be long or short. To list modules compiled with PHP, run the commands below:
How to install a specific version of PHP on Ubuntu Linux
By default, the Ubuntu repository contains the latest stable version of PHP. When you install PHP from the Ubuntu repository, it will only install that specific version available at that time.
If you need to install a specific version not available in Ubuntu Linux, you may have to add a third-party repository to your system.
Run the commands below to add a repository to Ubuntu Linux that will allow you to install specific versions.
First, install the necessary commands below:
Next, run the commands below to add the repository.
After that, you can search for and install a specific version of PHP.
Install a specific version by running the command format below:
Replace the x with the PHP minor version number and