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

Apache on Ubuntu 26.04 Installation Guide for Beginners

Setting up Apache Ubuntu 26.04 is one of the fastest ways to launch a reliable…

3 hours ago

How to Configure Static IP on Ubuntu Settings Easily

Setting up a Static IP on Ubuntu configuration is essential for servers, remote access systems,…

18 hours ago

How to Change Ubuntu Timezone Using Terminal or GUI

Keeping the correct system clock is important for servers, desktop systems, scheduled tasks, and application…

21 hours ago

How to Perform Ubuntu Hostname Change Without Rebooting

An Ubuntu Hostname Change is a common administrative task used to rename Linux servers, desktops,…

1 day ago

How to Add Ubuntu Swap Space for Better System Stability

Ubuntu Swap Space helps Linux systems stay responsive when physical RAM starts running low. Instead…

1 day ago

Install TeamViewer on Ubuntu 26.04: Complete Setup Guide

If you need secure remote desktop access on Linux, learning how to Install TeamViewer on…

2 days ago