How to Install PHP on Ubuntu Linux
Installing PHP on Ubuntu Linux lets you run dynamic websites and web applications like WordPress on your server. PHP is a server-side scripting language that turns static text files into interactive web pages with real-time data.
Most modern web projects run best on PHP 8.0 or newer to get speed boosts and security updates. Setting up PHP takes a few terminal commands and links the language to your web server, usually Apache or Nginx, so your browser can read and display PHP pages correctly.
Install PHP on Ubuntu by opening your terminal and running `sudo apt update` followed by `sudo apt install php libapache2-mod-php` for Apache or `sudo apt install php-fpm` for Nginx. Restart your web server afterward.
How to install PHP on Ubuntu with Apache support
To install PHP Ubuntu with Apache support, open your terminal and run the update command followed by the package installation command for PHP and the Apache module. This process sets up the scripting language on your web server so you can run dynamic websites. Once the command finishes, restart the Apache web server to load the new modules properly.
sudo apt update sudo apt install php libapache2-mod-php
PHP is tightly integrated with Apache. If you change PHP and want the changes to apply, restart or reload Apache.
To do that, run the commands below.
To install PHP on Ubuntu for Nginx, you must set up PHP-FPM (FastCGI Process Manager). PHP-FPM (FastCGI Process Manager) acts as a bridge between the Nginx web server and PHP. Nginx does not handle PHP files directly, so PHP-FPM processes those requests. The commands install PHP and configure it to work with your Nginx server.
Unlike Apache, Nginx does not natively process PHP files. Run the commands below to install PHP-FPM (FastCGI Process Manager), which handles these requests.
Run the commands below to set that up.
sudo apt update sudo apt install php-fpm
Since PHP is not as integrated with Nginx, you need to restart or reload both PHP and Nginx separately whenever you make PHP changes.
You need to add lines to your Nginx server block configuration to process PHP files. Ensure the correct PHP version appears in the highlighted line, for instance, `fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;`. This action allows Nginx to communicate with the PHP processor.
PHP installation includes optional extensions that improve performance and add features. Common extensions include `php-mysql` for database access and `php-curl` for transferring data with URLs. You can install these extensions by running the `apt install` command.
To install a newer PHP version on Ubuntu Linux when the newest PHP version is not available in Ubuntu's default software sources, you can add an extra repository. This process involves adding a tool to manage software sources and then a specific PPA (Personal Package Archive) that contains newer PHP versions. The commands below demonstrate how to set up the extra repository.
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.
sudo apt install software-properties-common sudo add-apt-repository ppa:ondrej/php
After adding the repository above, you can then install another PHP version.
sudo apt install php8.0 php8.0-common php8.0-cli php8.0-gd php8.0-curl php8.0-mysql
Was this guide helpful?
About the Author
Richard
Tech Writer, IT Professional
Richard is a writer at Geek Rewind who turns complex IT tasks into clear, step-by-step guides. He draws on years of hands-on experience in system administration and enterprise IT operations, focusing on Windows, Linux and WordPress: the problems people actually run into, and the fixes that work. His server and WordPress guides come from systems he runs himself. Richard builds and maintains the platform behind Geek Rewind, from its Ubuntu servers and Nginx configuration to its custom WordPress plugins. Many new tutorials start with readers' questions, and he's always glad to answer them in the comments.
Thanks,
Very simple and very clear!
Best wishes.
[…] How to install PHP on Ubuntu Linux […]
[…] How to install PHP on Ubuntu Linux […]
[…] How to install PHP on Ubuntu Linux […]
[…] How to install PHP on Ubuntu Linux […]
[…] How to install PHP on Ubuntu Linux […]
[…] How to install PHP on Ubuntu Linux […]
[…] How to install PHP on Ubuntu Linux […]
[…] How to install PHP on Ubuntu Linux […]
[…] How to install PHP on Ubuntu Linux […]
[…] How to install PHP on Ubuntu Linux […]
[…] How to install PHP on Ubuntu Linux […]
[…] How to install PHP on Ubuntu Linux […]
[…] How to install PHP on Ubuntu Linux […]
[…] How to install PHP on Ubuntu Linux […]
[…] How to install PHP on Ubuntu Linux […]
[…] How to install PHP on Ubuntu Linux […]
[…] How to install PHP on Ubuntu Linux […]
[…] How to install PHP on Ubuntu Linux […]
[…] How to install PHP on Ubuntu Linux […]
[…] How to install PHP on Ubuntu Linux […]
[…] How to install PHP or PHP-FPM on Ubuntu Linux […]
[…] How to install PHP on Ubuntu Linux […]
[…] How to install PHP on Ubuntu Linux […]
[…] How to install PHP on Ubuntu Linux […]
[…] How to install PHP on Ubuntu Linux […]
[…] How to install PHP on Ubuntu Linux […]
[…] How to install PHP on Ubuntu Linux […]
[…] How to install PHP on Ubuntu Linux […]
[…] How to install PHP on Ubuntu Linux […]
[…] How to install PHP on Ubuntu Linux […]
[…] How to install PHP on Ubuntu Linux […]
[…] How to install PHP on Ubuntu Linux […]
[…] How to install PHP on Ubuntu […]
[…] How to install PHP on Ubuntu Linux […]
[…] common Nginx reverse proxy to non-HTTP hosts is done using PHP-FPM. An example is how Nginx serves PHP […]
[…] common Apache reverse proxy to non-HTTP hosts is done using PHP-FPM. An example is how Apache serves PHP […]
[…] use Memcached as a caching database for your PHP application, such as WordPress, Drupal, Joomla, or Magento, you need to install […]
[…] How to install PHP on Ubuntu Linux […]
[…] How to install PHP on Ubuntu Linux […]
[…] How to install PHP on Ubuntu Linux […]
[…] and MariaDB using apt, then create a SilverStripe database with `CREATE DATABASE` and `GRANT ALL`. Install PHP-FPM and its required modules using `apt install php-fpm php-intl php-mysql php-curl php-cli php-zip […]
[…] How to install PHP on Ubuntu Linux […]