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

git fetch vs git pull: How They Work and When to Use Each

Both git fetch and git pull talk to a remote repository, but they do very different things to your…

4 days ago

git cherry-pick Command: Apply Commits from Another Branch

Sometimes the change you need already exists, just on the wrong branch. A hotfix lands…

4 days ago

Best Email APIs for Secure Business Email: Why Developers Are Moving Beyond SMTP

Email is still one of the most important communication channels inside modern applications. Password resets,…

5 days ago

Nginx Commands in Linux: Start, Stop, Reload, Test, and Log

Nginx is a high-performance web server and reverse proxy trusted by some of the largest…

1 week ago

ufw Command in Linux: Manage Firewall Rules with Examples

ufw (Uncomplicated Firewall) sits on top of iptables (or nftables on newer systems) and replaces…

1 week ago

who Command in Linux: Show All Logged-In Users and Sessions

When you share a server with a team or investigate unexpected activity, the first question…

1 week ago