[Solved] unit php8.1-fpm.service could not be found

unit php8.1-fpm.service could not be found fix

The error "unit php8.1-fpm.service could not be found" indicates that the systemd unit file for PHP-FPM version 8.1 is either missing or the service itself is not installed on your system. This guide walks you through troubleshooting and fixing the issue step by step.

What Causes This Error?

This error typically occurs when:

  • PHP-FPM 8.1 is not installed on the system
  • The systemd unit file is missing or corrupted
  • A different PHP version is installed but you're referencing 8.1
  • The service was not set up correctly after installation
Failed to start php8.1-fpm.service: Unit php8.1-fpm.service could not be found.

Step 1 — Check PHP-FPM Installation

First verify whether PHP-FPM 8.1 is installed on your system:

sudo apt list --installed | grep php8.1-fpm

If nothing is returned, PHP-FPM 8.1 is not installed. Install it using:

# Add PHP repository first (if not already added)
sudo apt install software-properties-common -y
sudo add-apt-repository ppa:ondrej/php -y
sudo apt update

# Install PHP-FPM 8.1
sudo apt install php8.1-fpm -y

Step 2 — Check the Unit File

Verify that the PHP-FPM service unit file exists for version 8.1. Unit files are located in /lib/systemd/system/ or /etc/systemd/system/:

ls /lib/systemd/system/ | grep php8.1-fpm
ls /etc/systemd/system/ | grep php8.1-fpm

If no unit file is found, the service was either not installed properly or you are running a different PHP version.

Step 3 — Check the Correct Service Name

The service name may differ depending on your Linux distribution and PHP version. List all PHP-related services to find the correct name:

systemctl list-units --type=service | grep php

Common service name variations:

Distribution Service Name
Ubuntu/Debian php8.1-fpm
CentOS/RHEL php-fpm
Amazon Linux php-fpm

Step 4 — Check PHP Version Installed

Confirm which PHP version is currently active on your system:

php -v

Also check all installed PHP versions:

update-alternatives --list php

Step 5 — Reload Systemd and Start the Service

After installing PHP-FPM 8.1, reload systemd and start the service:

# Reload systemd daemon
sudo systemctl daemon-reload

# Start PHP-FPM 8.1
sudo systemctl start php8.1-fpm

# Enable on boot
sudo systemctl enable php8.1-fpm

# Check status
sudo systemctl status php8.1-fpm

Quick Summary

Step Command
Check if installed sudo apt list --installed | grep php8.1-fpm
Install PHP-FPM 8.1 sudo apt install php8.1-fpm -y
Check unit file ls /lib/systemd/system/ | grep php8.1-fpm
List PHP services systemctl list-units --type=service | grep php
Start service sudo systemctl start php8.1-fpm
Enable on boot sudo systemctl enable php8.1-fpm

If you're still encountering the issue after these steps, check your Linux distribution's documentation or verify whether PHP 8.1 is supported on your current OS version.

Comments