Skip to content

Quickstart commands for setting up PHP 8.3 with Nginx on Ubuntu Server 22.04

Posted by author

Introduction

So I'm setting up another server and I thought I should write down the steps for the next time i do so in order to have a convenient document with everything. So in this post is a super to the point list of commands to get a server up and running with PHP 8.3 and Nginx on ubuntu server 22.04.

This guide assumes that you are familiar with linux and the command line, and that you have an actual idea of what you are doing. This won't teach you why things are done the way they are, its just a handy reference of the commands you need to run to setup the requirements for the latest php version.

There is no installation guide for MySQL here as I'm going to use SQLite for this.

Install commands

1sudo apt update
2sudo apt install nginx
3 
4# Optional, setup firewall
5sudo ufw app list
6sudo ufw allow 'Nginx HTTP'
7sudo ufw allow 'Nginx HTTPS'
8sudo ufw status
9 
10# Optional, print ip address
11ip addr show
12hostname -I
13curl -4 icanhazip.com
14 
15apt-get install ca-certificates apt-transport-https software-properties-common
16sudo apt-get install ca-certificates apt-transport-https software-properties-common
17sudo add-apt-repository ppa:ondrej/php
18sudo apt-get update
19sudo apt-get install php8.3
20 
21# Optional, verify php version
22php8.3 --version
23sudo apt install php8.3-fpm
24 
25# Optional, verify php process is running
26systemctl status php8.3-fpm
27 
28# Optional install common php extensions (Tailored for Laravel)
29sudo apt install openssl php8.3-bcmath php8.3-curl php8.3-mbstring php8.3-mysql php8.3-tokenizer php8.3-xml php8.3-zip php8.3-sqlite3

Server config (optional)

1sudo mkdir /var/www/welcome
2sudo chown -R $USER:$USER /var/www/welcome
3sudo nano /etc/nginx/sites-available/welcome # Paste the config below
1server {
2 listen 80;
3 server_name welcome www.welcome;
4 root /var/www/welcome;
5 
6 index index.html index.htm index.php;
7 
8 location / {
9 try_files $uri $uri/ = 404;
10 }
11 
12 location ~ \.php$ {
13 include snippets/fastcgi-php.conf;
14 fastcgi_pass unix:/var/run/php/php8.3-fpm.sock;
15 }
16 
17 location ~ /\.ht {
18 deny all;
19 }
20}
1sudo ln -s /etc/nginx/sites-available/welcome /etc/nginx/sites-enabled/
2sudo unlink /etc/nginx/sites-enabled/default
3sudo nginx -t
4sudo systemctl reload nginx
5 
6# Optional, create info file to verify php is working
7echo "<?php phpinfo(); ?>" > /var/www/welcome/index.php
8curl http://localhost/
9# Later you probably want to remove the info file
10sudo rm /var/www/welcome/index.php

SSL (optional)

1sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/nginx-selfsigned.key -out /etc/ssl/certs/nginx-selfsigned.crt
2 
3sudo nano /etc/nginx/snippets/self-signed.conf # Paste the following two lines but with the hash sign removed
4# ssl_certificate /etc/ssl/certs/nginx-selfsigned.crt;
5# ssl_certificate_key /etc/ssl/private/nginx-selfsigned.key;
6 
7sudo nano /etc/nginx/sites-available/welcome # Paste the following two lines but with the hash sign removed
8# listen 443 ssl;
9# include snippets/self-signed.conf;
10 
11sudo nginx -t
12sudo systemctl restart nginx

Conclusion

And that's it, you should now have a working server with PHP 8.3 and Nginx. If this post helped you, feel free to follow me on Twitter/X to find more useful tips! I'm @CodeWithCaen.

You can also Buy me a coffee if I really saved you some time!


Syntax highlighting by Torchlight.dev

End of article