How to Install PHP 8.3 with Nginx on Ubuntu 22.04?

By Hardik Savani May 14, 2024 Category : PHP Ubuntu

Hi Dev,

In this short tutorial, we will cover a install php 8.3 nginx ubuntu 22.04. We will use install php nginx ubuntu 22.04. I’m going to show you about install php-fpm 8.3 ubuntu 22.04. We will look at an example of install php 8.3 ubuntu 22.04 nginx.

let's go through the steps to install PHP 8.3 with Nginx on Ubuntu 22.04, and configure the `php.ini` file with the specified values. Additionally, I'll provide a sample configuration for the default Nginx site.

You can install php 8.3 with nginx on ubuntu 22.04, ubuntu 23.03 and latest version ubuntu 23.10 as well.

1. Update System Packages

Run following commands to upgrade system software.

sudo apt update

sudo apt upgrade

2. Install Nginx

Run following command to install nginx in ubuntu server.

sudo apt install nginx

3. Add PHP Repository and Install PHP 8.3

Run following commands to install php8.3-fpm on ubuntu.

sudo add-apt-repository ppa:ondrej/php

sudo apt update

sudo apt install php8.3-fpm php8.3-cli php8.3-mysql php8.3-curl php8.3-gd php8.3-mbstring php8.3-xml

4. Configure PHP-FPM

Edit the PHP-FPM configuration file:

sudo nano /etc/php/8.3/fpm/php.ini

Adjust the following settings:

upload_max_filesize = 32M

post_max_size = 48M

memory_limit = 256M

max_execution_time = 600

max_input_vars = 3000

max_input_time = 1000

Save and close the file. Then, restart PHP-FPM:

sudo systemctl restart php8.3-fpm

5. Configure Nginx to Use PHP-FPM

Edit the default Nginx site configuration:

sudo nano /etc/nginx/sites-available/default

Replace the existing configuration with the following:

server {

listen 80 default_server;

listen [::]:80 default_server;

root /var/www/html;

index index.php index.html index.htm;

server_name _;

location / {

try_files $uri $uri/ =404;

}

location ~ \.php$ {

include snippets/fastcgi-php.conf;

fastcgi_pass unix:/var/run/php/php8.3-fpm.sock;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

include fastcgi_params;

}

error_page 404 /404.html;

location = /404.html {

root /usr/share/nginx/html;

internal;

}

error_page 500 502 503 504 /50x.html;

location = /50x.html {

root /usr/share/nginx/html;

internal;

}

}

Save and close the file. Restart Nginx:

sudo systemctl restart nginx

6. Test PHP

Create a test PHP file in your web root directory:

echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php

Visit `http://your_server_ip/info.php` in your web browser to check if PHP is configured correctly.

Note

Please replace `your_server_ip` or `localhost` with your actual server's IP address.

Always adapt these commands based on the actual release of Ubuntu 22.04 and the corresponding PHP and Nginx versions available at the time of your installation. Ensure that you follow security best practices and keep your system and software up to date.

I hope it can help you...

Tags :
Shares