When hosting Magento, the PHP version and configuration play a critical role in performance and compatibility. Starting with PHP-FPM 8.3 on Ubuntu 24.04 ensures you are running a modern, secure, and optimized PHP environment. This guide will walk you through installing PHP-FPM 8.3 and configuring it correctly for Magento 2.
Why PHP-FPM 8.3 Is Important for Magento 2
Magento 2 relies heavily on PHP to render pages, process requests, and handle backend logic. Using PHP-FPM 8.3 provides better performance, improved memory management, and long-term security updates compared to older versions. PHP-FPM (FastCGI Process Manager) is specifically designed to handle high-traffic sites, making it the perfect companion for Magento.
Prerequisites Before Installing PHP-FPM 8.3
Before you begin this tutorial, make sure you already have Nginx installed on Ubuntu 24.04, since PHP-FPM works together with Nginx to process PHP requests. Without Nginx (or another web server), PHP-FPM alone cannot serve your Magento store.
If you haven’t installed Nginx yet, follow our step-by-step guide here:
👉 How to Install and Configure Nginx on Ubuntu 24.04 for Magento 2
This will prepare your server with a properly configured Nginx environment so you can seamlessly continue with the PHP-FPM installation for Magento 2.
Updating Ubuntu 24.04 Before Installing PHP-FPM
Before installing PHP, update your package list to ensure you have access to the latest stable versions:
sudo apt update
This guarantees Ubuntu retrieves the newest PHP 8.3 packages and dependencies.
Installing PHP-FPM 8.3 on Ubuntu
To install PHP-FPM 8.3, run:
sudo add-apt-repository ppa:ondrej/php sudo apt update sudo apt install php8.3-fpm -y
This installs the FastCGI Process Manager service. You can verify the installation with:
php -v
You should see PHP 8.3 listed as the active version.
Installing Required PHP Extensions for Magento 2
Magento 2 requires several PHP extensions to run properly. Install them alongside PHP-FPM:
sudo apt install -y php8.3-mcrypt php8.3-gd php8.3-curl php8.3-mysql php8.3-zip php8.3-xml php8.3-soap php8.3-intl php8.3-mbstring php8.3-bcmath
These extensions support MySQL connections, XML processing, image manipulation, encryption, internationalization, and more.
Configuring PHP-FPM 8.3 for Magento 2
Once installed, PHP-FPM runs as a service. Its pool configuration file is located in:
/etc/php/8.3/fpm/pool.d/www.conf
Open it for editing:
sudo nano /etc/php/8.3/fpm/pool.d/www.conf
Find the user
and group
directives and change them to your Magento system user:
user = magencode # www-data group = magencode # www-data listen.owner = magencode # www-data listen.group = magencode # www-data
This ensures Magento has the correct permissions to interact with PHP processes.
Find the
user
runwhoami
in your terminal. The command will return the active user (for example:magencode
). Use this username whenever you configure ownership, permissions, or set the user in Apache2 or Nginx configurations.
Adjusting PHP Settings for Magento Performance
Magento requires increased values for memory and execution time. Edit the main PHP configuration file:
sudo nano /etc/php/8.3/fpm/php.ini
Update these recommended values:
memory_limit = 2048M max_input_vars = 10000 max_execution_time = 3600 max_input_time = 3600 display_errors = On error_reporting = E_ALL post_max_size = 2024M
Save the changes and restart PHP-FPM:
sudo systemctl restart php8.3-fpm
Configuring Nginx to Work with PHP-FPM 8.3
After installing PHP-FPM, you need to configure Nginx so it can process .php
files using the PHP-FPM service. Open the default Nginx site configuration file:
sudo nano /etc/nginx/sites-enabled/default
- Add
index.php
to the list of index files so Nginx knows to serve it by default:
index index.php index.html index.htm index.nginx-debian.html;
- Scroll down to the PHP block and uncomment the relevant lines:
location ~ \.php$ { include snippets/fastcgi-php.conf; # uncomment this line # With php-fpm (or other unix sockets): fastcgi_pass unix:/run/php/php8.3-fpm.sock; # uncomment and make sure to use your PHP version # With php-cgi (or other tcp sockets): # fastcgi_pass 127.0.0.1:9000; }
Save and close the file, then restart Nginx:
sudo service nginx restart
Now Nginx will correctly pass PHP requests to PHP-FPM 8.3.
Setting Up a Magento 2 Virtual Host in Nginx
If you want to configure a dedicated Virtual Host for Magento 2 in Nginx, you should follow our separate guide, which covers the process step by step, including domain configuration, root paths, and Magento-specific rules:
👉 Configure a Nginx Virtual Host on Ubuntu 24.04 for Magento 2
Conclusion: Magento 2 Optimized with PHP-FPM 8.3
By installing and configuring PHP-FPM 8.3 on Ubuntu 24.04 for Magento 2, you set up a fast, secure, and reliable environment for your store. With the right PHP extensions, tuned configuration, and integration with Nginx, your Magento installation will be ready to handle high traffic and deliver strong performance.
Leave a Reply