1 minute reading time (241 words)

Install PHP 8.1 for Nginx on Debian 11

How to install PHP 8.1 for Nginx web server on Debian 11

Add repository for PHP 

curl -sSL https://packages.sury.org/php/README.txt | sudo bash -x
sudo apt update 

Install PHP 8.1

apt install php8.1

Check php version

php -v

List installed php modules

dpkg -l | grep php8

Install PHP FastCGI and PHP MySQL 

apt install php-fpm php-mysql

Install PHP extensions

In this example, we are installing Joomla 4 which requires these PHP extensions

apt install php8.1-zip php8.1-intl php8.1-xml  php8.1-curl php8.1-mbstring php8.1-gd 

Find php.ini configuration file 

php -i | grep "Loaded Configuration File"

Enable PHP extensions

Edit php.ini and uncomment these lines to enable the extensions

nano /etc/php/8.1/fpm/php.ini


Restart PHP FPM

service php8.1-fpm restart

Restart Nginx

service nginx restart

Add PHP to Nginx Server block

Edit Nginx server block

nano /etc/nginx/sites-available/yourdomain.com.conf

# php config
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        # fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include /etc/nginx/fastcgi.conf;

Test Nginx configuration

nginx -t 

Reload Nginx

service nginx reload

Related Posts



No comments made yet. Be the first to submit a comment
Already Registered? Login Here
Saturday, 23 September 2023
You can help support this website by buying me a coffee!
Buy Me A Coffee