Installing PHP and PHP-FPM on Ubuntu 26.04
Source: Dev.to
Install PHP
PHP 8.5 is available in Ubuntu 26.04’s default APT repository.
1. Update the APT package index
sudo apt update
2. Install PHP
sudo apt install php -y
3. Verify the installed version
php --version
Install PHP Extensions
Extensions add capabilities like database connectivity, image processing, and archive handling.
1. Install common PHP extensions
sudo apt install php-mysql php-mbstring php-bcmath php-zip php-gd php-curl php-xml -y
What you just installed
php-mysql– MySQL and MariaDB database connectivityphp-mbstring– multi‑byte character encoding supportphp-bcmath– arbitrary precision mathematicsphp-zip– ZIP archive handlingphp-gd– image creation and manipulationphp-curl– HTTP client functionalityphp-xml– XML parsing and formatting
2. Verify extensions are loaded
php -m
Install PHP‑FPM
PHP‑FPM manages a pool of FastCGI worker processes that handle incoming PHP requests from the web server.
1. Install PHP‑FPM
sudo apt install php-fpm -y
2. Enable and start the service
sudo systemctl enable php8.5-fpm
sudo systemctl start php8.5-fpm
3. Check the service status
sudo systemctl status php8.5-fpm
4. Verify the socket exists
ls /run/php/php8.5-fpm.sock
Integrate with Nginx
1. Install Nginx
sudo apt install nginx -y
2. Create the web root directory
sudo mkdir -p /var/www/app.example.com
sudo chown -R www-data:www-data /var/www/app.example.com
3. Create the virtual host configuration
sudo nano /etc/nginx/sites-available/app.example.com.conf
server {
listen 80;
server_name app.example.com;
root /var/www/app.example.com;
index index.php index.html;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.5-fpm.sock;
}
}
4. Enable the site and reload Nginx
sudo ln -s /etc/nginx/sites-available/app.example.com.conf /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
Verify the Installation
1. Create a PHP info page
sudo nano /var/www/app.example.com/info.php
2. Open the page in a browser
Visit http://app.example.com/info.php. The PHP info page confirms PHP 8.5 is running through PHP‑FPM.
3. Remove the info page
sudo rm /var/www/app.example.com/info.php
Next Steps
PHP and PHP‑FPM are now installed and integrated with Nginx. From here you can:
- Configure PHP‑FPM pool settings in
/etc/php/8.5/fpm/pool.d/www.confto tune concurrency - Install Laravel or WordPress on the stack
- Add Composer for PHP package management
For the full guide with additional tips, visit the original article on Vultr Docs.