PHP supports and works with many types of web servers. You can use PHP with Apache, Nginx, and a few other open-source web servers. However, the vast majority of PHP implementations are integrated with Apache or Nginx web servers. Because of that, this post will only show you how to use PHP with Apache or Nginx on Ubuntu Linux. PHP is always constantly being updated, so don’t be surprised that the versions installed here aren’t the latest. As of this writing, the latest PHP version is PHP 8.0. If you’re a student or new user learning Linux, the easiest place to start learning is on Ubuntu Linux. Ubuntu is the modern, open-source Linux operating system for desktops, servers, and other devices. To get started with installing PHP on Ubuntu Linux, follow the steps below.
How to install PHP on Ubuntu with Apache support
As mentioned above, PHP supports many types of web servers, including Apache, Nginx, and a few others. If you’re using an Apache web server, then the commands below are used to install PHP. After installing PHP, restart the Apache web server for PHP modules to apply. PHP is tightly integrated with Apache. Anything you make changes to PHP and you want it to apply, simply restart or reload Apache. To do that, run the comments below.
How to install PHP on Ubuntu Linux with Nginx support
If you’re running an Nginx web server, then the commands below will install PHP with support for Nginx. Nginx doesn’t have built-in support for processing PHP files and is not tightly integrated as Apache. To add PHP support for Nginx, you will need to install and use PHP-FPM (FastCGI process manager) to handle the PHP files. To do that, run the commands below. Because PHP isn’t tightly integrated with Nginx, if you make changes to PHP, you must restart or reload PHP and Nginx separately for the changes to apply. Also, to allow Nginx to read PHP files, you must add these lines to the Nginx server block. Remember to use the version of PHP installed and reference it in the highlighted line shown below.
How to install PHP modules on Ubuntu Linux
You have installed PHP but there are many other modules available to support and enhance PHP performance and functionality. Below are some common PHP extensions and modules one can install.
How to install the latest version of PHP on Ubuntu Linux
As mentioned above, the current version of PHP is 8.0. However, you will not see that version in Ubuntu repositories at the moment. The current latest in Ubuntu repositories is 7.4. To install the latest of other versions of PHP that are not available in the Ubuntu repository, run the commands below to install a third-party PPA repository that includes multiple versions of PHP. After adding the repository above, you can then install another PHP version. That should do it! Conclusion: This post showed you how to install PHP on Ubuntu Linux with support for Apache or Nginx web servers. If you find any error above or have something to add, please use the comment form below.