July 4, 2022 . 2 MIN READ
Before you begin, ensure your Ubuntu server has the latest packages installed:
This updates the package index and upgrades all installed packages to their latest versions.
To install PHP 8.1 and required extensions, add the ondrej/php PPA:
Once added, you can install PHP 8.1.
Verify the installation:
Verify PHP-FPM installation:
PHP extensions can be installed using:
For commonly used extensions, run:
php.ini:Apache:
Nginx (PHP-FPM):
Search (F6) and update these values for better performance:
Restart the service after changes:
Apache:
PHP-FPM (Nginx):
PHP-FPM allows you to set the user and group that PHP runs under:
Replace www-data with your preferred username:
Save changes (CTRL+X, Y) and restart PHP-FPM:
Disable the old PHP module and enable PHP 8.1:
Update the PHP-FPM socket in your Nginx configuration (inside the location ~ \.php$ block):
Change the line:
to:
Test the configuration:
Restart Nginx:
You have successfully installed PHP 8.1 on your Ubuntu server, configured it for both Apache and Nginx, and upgraded your web server to use the latest PHP version.
If you encounter any issues or have feedback, feel free to leave a comment below.