How to Install PHP on Ubuntu Linux
You install PHP on Ubuntu Linux to run server-side web development scripts.
PHP is a popular open-source scripting language vital for dynamic websites and web applications.
This guide shows you exactly how to get PHP running on your Ubuntu machine, focusing on configurations for the Apache or Nginx web servers. These servers are commonly used for hosting PHP applications like WordPress.
We’ll help you install a specific version, such as the stable PHP 8.0 release, ensuring it integrates smoothly with your web server setup.
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
Installing PHP on Ubuntu with Apache is straightforward using just a few commands.
sudo apt update sudo apt install php libapache2-mod-php
After installing PHP, restart the Apache web server so the PHP modules apply. 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.
sudo systemctl restart apache2
How to install PHP on Ubuntu Linux with Nginx support
To install PHP on Ubuntu for Nginx, you’ll need to set up PHP-FPM, a helper tool that lets Nginx work with PHP files.
Nginx doesn’t natively handle PHP files like Apache does. To get PHP working with Nginx, you’ll need to install and use PHP-FPM (FastCGI process manager), which is a tool that helps manage PHP requests.
Run the commands below to set that up.
sudo apt update sudo apt install php-fpm
Since PHP isn’t as integrated with Nginx, you’ll need to restart or reload both PHP and Nginx separately whenever you make PHP changes.
sudo systemctl restart php-fpm sudo systemctl restart nginx
You’ll also need to add a few lines to your Nginx server block to allow it to read PHP files. Make sure you use the correct PHP version in the highlighted line below.
server {
location ~ .php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.0-fpm.sock;
}
}How to install PHP modules on Ubuntu Linux
You’ve now installed PHP, but there are many additional modules (also called extensions) that can boost its performance and add more features. Here are some common ones you might want to install:
php-common php-cli php-gd php-curl php-mysql
How to install the latest version of PHP on Ubuntu Linux
You can install the latest PHP version on Ubuntu by adding a special software source if it’s not in the standard list.
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
That should do it!
Conclusion:
That’s how you install PHP on Ubuntu Linux with support for either Apache or Nginx. If you notice any errors or have anything to add, please let us know in the comments below.
Was this guide helpful?
About the Author
Richard
Tech Writer, IT Professional
Richard, a writer for Geek Rewind, is a tech enthusiast who loves breaking down complex IT topics into simple, easy-to-understand ideas. With years of hands-on experience in system administration and enterprise IT operations, he’s developed a knack for offering practical tips and solutions. Richard aims to make technology more accessible and actionable. He's deeply committed to the Geek Rewind community, always ready to answer questions and engage in discussions.
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 […]