How to Install and Configure PHP on Ubuntu 26.04

PHP remains one of the most widely deployed server-side scripting languages on the web, powering everything from simple scripts to large-scale applications like WordPress and Laravel. If you plan to run dynamic websites or web applications on your Ubuntu 26.04 server, learning how to install and configure PHP is an essential step. In this guide, you will walk through the complete process to php install configure ubuntu 26.04, including PHP-FPM for Nginx, the Apache module, common extensions, multiple PHP versions, and php.ini tuning.

In this tutorial you will learn:

  • How to install the default PHP version from Ubuntu 26.04 repositories
  • How to set up PHP-FPM to work with Nginx
  • How to enable PHP processing with Apache
  • How to install and manage common PHP extensions
  • How to run multiple PHP versions side by side
  • How to locate and tune the php.ini configuration file
Installing and configuring PHP on Ubuntu 26.04

Software Requirements

Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Ubuntu 26.04 Resolute Raccoon
Software PHP 8.5, PHP-FPM, Nginx or Apache
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

PREREQUISITE

This tutorial assumes you have already installed and configured Nginx on your Ubuntu 26.04 system if you plan to use PHP-FPM with Nginx. Complete that guide first before proceeding with the PHP-FPM sections. Alternatively, if you prefer Apache, you can install and configure Apache instead.

TL;DR
Install PHP and PHP-FPM on Ubuntu 26.04 with a few commands, then configure your web server to process PHP files.

Quick Steps to Install and Configure PHP on Ubuntu 26.04
Step Command/Action
1. Install PHP and PHP-FPM sudo apt install php php-fpm nginx
2. Install common extensions sudo apt install php-mysql php-curl php-mbstring php-xml php-zip php-gd
3. Configure Nginx for PHP Add fastcgi_pass block to your Nginx server block
4. Test PHP processing Create a phpinfo() test page and open it in a browser

Installing PHP on Ubuntu 26.04

Ubuntu 26.04 ships with PHP 8.5 in its default repositories, so you can get started without adding any third-party sources. Begin by updating your package index and installing the core PHP package:

$ sudo apt update
$ sudo apt install php

This installs the PHP CLI interpreter along with common default modules. Once the installation completes, verify the installed version:

$ php -v

You should see output similar to:

Terminal output showing PHP 8.5.4 version information after installation on Ubuntu 26.04Terminal output showing PHP 8.5.4 version information after installation on Ubuntu 26.04
Verifying the installed PHP version with the php -v command on Ubuntu 26.04

It is important to understand that the php package alone only provides the command-line interpreter. To process PHP through a web server, you need either PHP-FPM (for Nginx) or the Apache PHP module. The following sections cover both approaches.

Installing PHP-FPM for Nginx on Ubuntu 26.04

PHP-FPM (FastCGI Process Manager) is the recommended way to run PHP with Nginx. Unlike Apache, Nginx does not have a built-in PHP module, so it relies on PHP-FPM as a separate process to handle PHP requests. Consequently, you need to install the PHP-FPM package and then configure Nginx to forward PHP requests to it.

Install and Start PHP-FPM

Install the PHP-FPM package:

$ sudo apt install php-fpm nginx

After installation, PHP-FPM starts automatically as a systemd service. Verify that it is running:

$ sudo systemctl status php8.5-fpm

The output should show the service as active (running). Additionally, PHP-FPM listens on a Unix socket by default, which Nginx will use to communicate with it. You can confirm the socket file exists:

$ ls /run/php/

You should see a socket file named php8.5-fpm.sock.

Terminal showing PHP 8.5 FPM service active and running with socket file listing on Ubuntu 26.04Terminal showing PHP 8.5 FPM service active and running with socket file listing on Ubuntu 26.04
Verifying that PHP 8.5 FPM is active and the php8.5-fpm.sock socket file exists

Configure Nginx to Process PHP Files

To serve PHP through Nginx, you need a server block that includes a location directive for PHP-FPM. Create a new server block configuration file:

$ sudo nano /etc/nginx/sites-available/linuxconfig.conf

Add the following complete server block. This is a minimal but fully functional configuration that serves both static files and PHP scripts:

server {
    listen 80;
    server_name linuxconfig.org www.linuxconfig.org;
    root /var/www/linuxconfig.org/html;
    index index.php index.html index.htm;

    location / {
        try_files $uri $uri/ =404;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php8.5-fpm.sock;
    }

    location ~ /\.ht {
        deny all;
    }
}

The key sections of this configuration are the index directive, which prioritizes index.php so that Nginx serves PHP index files by default, the location ~ \.php$ block, which matches any request ending in .php and forwards it to the PHP-FPM socket, and the location ~ /\.ht block, which denies access to hidden files such as .htaccess for security.

Now create the document root directory and enable the server block:

$ sudo mkdir -p /var/www/linuxconfig.org/html
$ sudo chown -R $USER:$USER /var/www/linuxconfig.org/html
$ sudo ln -s /etc/nginx/sites-available/linuxconfig.conf /etc/nginx/sites-enabled/

Test the Nginx configuration for syntax errors and reload:

$ sudo nginx -t
$ sudo systemctl reload nginx

Test PHP Processing with Nginx

INSTALLATION TIPS

If you do not have a domain name pointing to your server, you can test the server block locally by adding an entry to your /etc/hosts file:

$ echo "127.0.1.1 linuxconfig.org" | sudo tee -a /etc/hosts

This maps the domain to your local machine, allowing you to access in your browser for testing purposes. Remove or comment out this line once you configure proper DNS.

Create a test PHP file in your web root to verify that Nginx correctly processes PHP:

$ echo "<?php phpinfo(); ?>" | sudo tee /var/www/linuxconfig.org/html/info.php

Open your browser and navigate to . You should see the PHP information page displaying the full PHP configuration. This confirms that Nginx is correctly forwarding PHP requests to PHP-FPM.

Terminal showing Nginx server block creation and PHP-FPM configuration with browser displaying PHP 8.5.4 phpinfo page on Ubuntu 26.04Terminal showing Nginx server block creation and PHP-FPM configuration with browser displaying PHP 8.5.4 phpinfo page on Ubuntu 26.04
Nginx configured with PHP-FPM serving the phpinfo() page confirming PHP 8.5.4 with FPM/FastCGI Server API

SECURITY ALERT

Remove the info.php file after testing. The phpinfo page exposes sensitive server configuration details that should never be publicly accessible on a production server:

$ sudo rm /var/www/linuxconfig.org/html/info.php

Installing PHP for Apache on Ubuntu 26.04

If you use Apache instead of Nginx, PHP integration is handled through the libapache2-mod-php module. This approach embeds PHP directly into the Apache process, so no separate service is required.

Install the Apache PHP module:

$ sudo apt install libapache2-mod-php

Apache automatically enables the PHP module during installation. You can confirm it is active:

$ apache2ctl -M | grep php

The output should include a line like php_module (shared), confirming that Apache is ready to process PHP files.

INSTALLATION TIPS

If you see the warning AH00558: apache2: Could not reliably determine the server's fully qualified domain name, suppress it by setting a global ServerName directive:

$ echo "ServerName localhost" | sudo tee /etc/apache2/conf-available/servername.conf
$ sudo a2enconf servername
$ sudo systemctl reload apache2

To test PHP processing, create a test file in your Apache document root:

$ echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php

Open in your browser. If you see the PHP information page, Apache is processing PHP correctly. Remove the test file afterward:

$ sudo rm /var/www/html/info.php

INSTALLATION TIPS

Do not install both libapache2-mod-php and php-fpm on the same server unless you have a specific reason. Running both can lead to confusion about which PHP handler is active. Choose one approach based on your web server.

Terminal showing apache2ctl confirming php_module loaded and browser displaying PHP 8.5.4 phpinfo page via Apache 2 Handler on Ubuntu 26.04Terminal showing apache2ctl confirming php_module loaded and browser displaying PHP 8.5.4 phpinfo page via Apache 2 Handler on Ubuntu 26.04
Apache serving the phpinfo() page confirming PHP 8.5.4 with Apache 2 Handler Server API

Installing Common PHP Extensions on Ubuntu 26.04

A base PHP installation includes only core functionality. Most web applications require additional extensions for database connectivity, string handling, image processing, and more. Therefore, installing the right extensions is a critical part of setting up PHP on Ubuntu 26.04.

Install the most commonly needed extensions in one command:

$ sudo apt install php-mysql php-curl php-mbstring php-xml php-zip php-gd php-intl

Here is what each extension provides:

Common PHP Extensions and Their Purpose
Extension Purpose
php-mysql MySQL and MariaDB database connectivity (mysqli and PDO drivers)
php-curl HTTP client library for API requests and remote file fetching
php-mbstring Multibyte string handling for UTF-8 and internationalization
php-xml XML parsing and manipulation (DOM, SimpleXML, XMLReader)
php-zip ZIP archive creation and extraction
php-gd Image creation and manipulation (JPEG, PNG, GIF, WebP)
php-intl Internationalization functions (number formatting, date formatting, collation)

To search for all available PHP extensions in the repositories, use:

$ apt search php- | grep "^php8.5"

You can also list all currently installed PHP modules:

$ php -m

After installing new extensions, remember to restart your PHP handler so the changes take effect:

$ sudo systemctl restart php8.5-fpm

Or for Apache:

$ sudo systemctl restart apache2

Installing Multiple PHP Versions on Ubuntu 26.04

Some projects require a specific PHP version that differs from the default. For instance, a legacy application might need PHP 8.1, while the Ubuntu 26.04 repositories provide PHP 8.5. To run multiple PHP versions side by side, you can use the Ondrej Sury PPA, which is the most widely trusted third-party PHP repository for Ubuntu.

Add the Ondrej PPA

$ sudo add-apt-repository ppa:ondrej/php
$ sudo apt update

Install an Alternate PHP Version

For example, to install PHP 8.1 alongside the default version:

$ sudo apt install php8.1 php8.1-fpm php8.1-mysql php8.1-curl php8.1-mbstring php8.1-xml

Both PHP versions now coexist on the system. Each version has its own FPM service, configuration directory, and CLI binary.

Switch the Default CLI Version

Use update-alternatives to change which PHP version the php command points to:

$ sudo update-alternatives --set php /usr/bin/php8.1

Verify the switch:

$ php -v

To switch back to the default version:

$ sudo update-alternatives --set php /usr/bin/php8.5

IMPORTANT

Switching the CLI version does not change which PHP-FPM version your web server uses. To switch the web server’s PHP version, update the socket path in your Nginx configuration or disable/enable the appropriate Apache module.

Switch PHP-FPM Version for Nginx

Edit your Nginx server block and change the fastcgi_pass socket path:

    fastcgi_pass unix:/run/php/php8.1-fpm.sock;

Then reload Nginx:

$ sudo systemctl reload nginx

Switch PHP Version for Apache

Disable the current module and enable the desired one:

$ sudo a2dismod php8.5
$ sudo a2enmod php8.1
$ sudo systemctl restart apache2

Configuring php.ini on Ubuntu 26.04

The php.ini file controls PHP’s runtime behavior. On Ubuntu 26.04, PHP maintains separate php.ini files for each SAPI (Server API), meaning the CLI, FPM, and Apache each have their own configuration. Consequently, changes you make to one php.ini do not affect the others.

Locate Your php.ini Files

Find the active php.ini for the CLI:

$ php --ini | grep "Loaded Configuration"
Loaded Configuration File:         /etc/php/8.5/cli/php.ini

For PHP-FPM, check the phpinfo output or look directly:

$ ls /etc/php/8.5/fpm/php.ini

For Apache:

$ ls /etc/php/8.5/apache2/php.ini

Key php.ini Directives

Open the appropriate php.ini file for your web server. For PHP-FPM:

$ sudo nano /etc/php/8.5/fpm/php.ini

The following directives are the most commonly adjusted for web applications:

Key php.ini Directives for Web Applications
Directive Default Recommended Purpose
memory_limit 128M 256M Maximum memory a single script can consume
upload_max_filesize 2M 64M Maximum size of an uploaded file
post_max_size 8M 64M Maximum size of POST data (must be >= upload_max_filesize)
max_execution_time 30 60 Maximum time in seconds a script can run
max_input_vars 1000 3000 Maximum number of input variables per request

INSTALLATION TIPS

Always set post_max_size to a value equal to or greater than upload_max_filesize. If post_max_size is smaller, file uploads will silently fail even when the file is within the upload limit.

After editing php.ini, restart the relevant service for changes to take effect:

$ sudo systemctl restart php8.5-fpm

Or for Apache:

$ sudo systemctl restart apache2

You can confirm your changes are active by checking specific values from the command line:

$ php -i | grep memory_limit
memory_limit => 256M => 256M

IMPORTANT

The CLI php -i output reflects the CLI php.ini, not the FPM or Apache one. To verify web server values, use a phpinfo() page or check the specific php.ini file directly.

Conclusion

You have successfully installed and configured PHP on Ubuntu 26.04. This guide covered the CLI installation, PHP-FPM setup for Nginx, the Apache PHP module, common extensions, running multiple PHP versions with the Ondrej PPA, and tuning the php.ini configuration. With PHP properly configured, your Ubuntu 26.04 server is ready to host dynamic web applications. For more in-depth information on PHP configuration directives, consult the official PHP documentation.

Frequently Asked Questions

  1. What PHP version does Ubuntu 26.04 include by default? Ubuntu 26.04 ships with PHP 8.5 in its official repositories. You can check the exact point release at any time by running php -v after installation.
  2. Should I use PHP-FPM or the Apache PHP module? If you are running Nginx, PHP-FPM is your only option since Nginx has no built-in PHP module. If you are running Apache, you can use either approach, but PHP-FPM generally offers better performance under heavy load because it manages PHP processes independently from Apache.
  3. How do I know which php.ini file my web server is using? Create a temporary phpinfo() page and look for the “Loaded Configuration File” row. This shows the exact path to the php.ini that your web server’s PHP handler loads. Remember to delete the file after checking.
  4. Can I run multiple PHP versions simultaneously on Ubuntu 26.04? Yes. After adding the Ondrej PPA, you can install additional PHP versions alongside the default one. Each version runs its own PHP-FPM service, and you can point different Nginx server blocks or Apache virtual hosts to different PHP versions.
  5. Why are my php.ini changes not taking effect? The most common reason is editing the wrong php.ini file. PHP maintains separate configuration files for CLI, FPM, and Apache. Ensure you are editing the file that matches your web server’s SAPI. Additionally, you must restart the PHP-FPM service or Apache after making changes.

PakarPBN

A Private Blog Network (PBN) is a collection of websites that are controlled by a single individual or organization and used primarily to build backlinks to a “money site” in order to influence its ranking in search engines such as Google. The core idea behind a PBN is based on the importance of backlinks in Google’s ranking algorithm. Since Google views backlinks as signals of authority and trust, some website owners attempt to artificially create these signals through a controlled network of sites.

In a typical PBN setup, the owner acquires expired or aged domains that already have existing authority, backlinks, and history. These domains are rebuilt with new content and hosted separately, often using different IP addresses, hosting providers, themes, and ownership details to make them appear unrelated. Within the content published on these sites, links are strategically placed that point to the main website the owner wants to rank higher. By doing this, the owner attempts to pass link equity (also known as “link juice”) from the PBN sites to the target website.

The purpose of a PBN is to give the impression that the target website is naturally earning links from multiple independent sources. If done effectively, this can temporarily improve keyword rankings, increase organic visibility, and drive more traffic from search results.

Jasa Backlink

Download Anime Batch

Leave a Reply

Your email address will not be published. Required fields are marked *