How To

PHP Ubuntu 26.04 Installation Guide for Apache and Nginx

Setting up PHP Ubuntu 26.04 is essential for developers who want to run modern web applications, CMS platforms, or dynamic websites on Linux servers. PHP continues to power major platforms like WordPress, Laravel, and Magento because of its flexibility and broad ecosystem.

Ubuntu 26.04 includes PHP 8.5 in its default repositories, making installation quick and straightforward. Whether you use Apache or Nginx, Ubuntu offers reliable tools for deploying PHP applications efficiently.

Why Use PHP on Ubuntu 26.04?

PHP remains one of the most trusted server-side scripting languages for web development. Combined with Ubuntu 26.04, it creates a stable environment suitable for production servers, cloud deployments, and development machines.

The latest PHP release introduces better performance, improved memory handling, and updated security enhancements. In addition, Ubuntu’s package management system makes maintaining PHP installations simple.

Install PHP on Ubuntu 26.04 with Apache

If your server uses Apache, installing PHP requires only a few commands. First, update the package index:

sudo apt update

Next, install PHP along with the Apache integration module:

sudo apt install php libapache2-mod-php

Once the installation completes, restart Apache to load the PHP module properly:

sudo systemctl restart apache2

Apache can now process PHP files directly through the integrated module.

Configure PHP on Ubuntu 26.04 with Nginx

Unlike Apache, Nginx does not process PHP files natively. Instead, it uses PHP-FPM (FastCGI Process Manager).

Install PHP-FPM using:

sudo apt updatesudo apt install php-fpm

After installation, verify the service status:

sudo systemctl status php8.5-fpm

Next, update your Nginx server block to forward PHP requests through the FastCGI socket. Restart Nginx afterward:

sudo systemctl restart nginx

This setup provides better performance and resource efficiency for high-traffic environments.

Install Common PHP Extensions

Most PHP applications require additional modules for database access, image processing, or API communication.

Install commonly used extensions with:

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

These packages add support for MySQL databases, image rendering, ZIP handling, and multibyte string processing.

To list all installed modules:

php -m

Test PHP Processing

To confirm PHP works correctly, create a test file inside your web root:

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

Open the file in your browser:

http://your_server_ip/info.php

If everything is configured properly, you will see the PHP information page showing active modules and server details.

After testing, remove the file for security reasons:

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

Manage Multiple PHP Versions

Ubuntu also supports multiple PHP versions using third-party repositories. This is useful when hosting applications that depend on different PHP releases.

You can switch between installed versions with:

sudo update-alternatives --config php

This allows administrators to manage compatibility without reinstalling the operating system.

Final Thoughts on PHP

Deploying PHP Ubuntu 26.04 is a simple process whether you choose Apache or Nginx. Ubuntu’s package repositories provide fast access to PHP 8.5, essential extensions, and PHP-FPM for optimized performance.

With the right configuration, PHP on Ubuntu 26.04 delivers a reliable foundation for hosting websites, APIs, and enterprise-grade web applications securely and efficiently.

Cyber Defence

Recent Posts

Install Apache Cassandra on Ubuntu 18.04: NoSQL Setup Guide

Apache Cassandra is a free, open-source NoSQL database designed for high availability and linear scalability with…

2 hours ago

Install Rocket.Chat on Ubuntu 18.04 with Nginx and Let’s Encrypt

Rocket.Chat is a free, open-source team communication platform built with the Meteor framework. It is a…

2 hours ago

Install MySQL on Ubuntu 18.04: Setup, Security, and Root Access

MySQL is the most popular open-source relational database management system. It is fast, reliable, and scales…

2 hours ago

Install Apache on Ubuntu 18.04: Web Server Setup and Config

Apache is the most widely used web server in the world. It is free, open-source, and…

2 hours ago

Install NetBeans IDE on Ubuntu 18.04 with Snap and OpenJDK 8

NetBeans is a free, open-source, cross-platform IDE developed by the Apache Software Foundation. It was one…

2 hours ago

Install Pip on Ubuntu 18.04: Python 3 and Python 2 Setup Guide

Pip is the official package manager for Python and the standard way to install libraries from…

5 days ago