Hello Developers, Today in this post i will show you how we can get ready a server with Ngnix, MySQL and PHP(We will install PHP8.1 which is latest.)
i am running Ubuntu 22.04 Linux system with sudo (or root) privileged access, You should also run with root privilege.
Now, Open terminal and start following below steps.
Step 1 . Install Ngnix.
$ sudo apt update && sudo apt upgrade
our system is updated now we will install ngnix.
$ sudo apt install nginx
Ngnix is installed, Now we will configure firewall , we will allow port 80 and port 443 .
$ sudo ufw allow 80/tcp
$ sudo ufw allow 43/tcp
Now open your IP in web browser you will see the out put, If any problem occurred please comment below i will solve soon.
Step 2 – Install PHP
As before i told you , we will install latest Version of PHP, This time when i am writing this post, Current version is PHP8.1, So i will install PHP8.1.
The ondrej/php ppa contains all PHP version’s for Ubuntu systems. So first we need to add this repository first.
$ sudo add-apt-repository ppa:ondrej/php
Repository added now we are ready to install PHP.
sudo apt install php8.1
Note- You can also install any version of PHP like PHP 5.6, PHP 7.1, 7.2, 7.3, 7.4 and PHP 8.0, 8.1.
For PHP we need to Install and Configure PHP-FPM(FastCGI Process Manager).
$ sudo apt install php8.1-fpm
for a complete setup we need some additional packages to install on our system.
$ sudo apt install php8.1-mysql php8.1-curl php8.1-xml
Note- If you are want to use Laravel 9 to run on this system run the below command. This is install extension pf PHP.
$ sudo apt install openssl php-common php-curl php-json php-mbstring php-mysql php-xml php-zip
Now configure the Ngnix to execute PHP file.
$ sudo nano /etc/nginx/sites-enabled/default
and make changes which i am written below.
index index.php; location / { try_files $uri $uri/ =404; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php8.1-fpm.sock; }
Note- Please add index.php.
Step 3 – Install mysql
Already i written a post how to install mysql, Please use that link, And now every thing is ready to run.
Start running
Happy Coding.
If you love this article please comment below, Thanks .
3 Comments
Can you guide how to create AWS server and deploy a php project ?
Hi, my name is Anthony,
I got as far as (Ngnix is installed, Now we will configure firewall , we will allow port 80 and port 443).
when I open my public IP I get a file to open page saying Safari can’t connect to the server. I am running the server on AWS.
I figured it out. seems I was using the wrong AWS IP