Step 1: Install Nginx
Firstly install the prerequisites:
sudo apt install curl gnupg2 ca-certificates lsb-release
Then we need to add the Nginx mainline package to our repository so that when we run apt install nginx, we will download the mainline version instead of the old stable version.
echo "deb http://nginx.org/packages/mainline/debian `lsb_release -cs` nginx" | sudo tee /etc/apt/sources.list.d/nginx.list
Next we need to download the signing key so that we can verify its authenticity
curl -fsSL https://nginx.org/keys/nginx_signing.key | sudo apt-key add -
If it prints out OK! then you are good to go!
Now update package repositories and install Nginx:
sudo apt update
sudo apt install nginx
That’s it! You have now installed the latest release of Nginx on Debian 10. You should now start it!
sudo systemctl start nginx.service
And Don’t forget to make it automatically start on system boot as well.
sudo systemctl enable nginx.service
Step 2: Install PHP 7.4
To install PHP 7.4 we need to add repository. Since PHP 7.4 didn’t come with Debian 10 it is required to add the following repository. Write this commands:
sudo apt-get install software-properties-common sudo add-apt-repository ppa:ondrej/php
Update package repositories:
sudo apt update
And now install PHP 7.4:
sudo apt install php7.4-fpm php7.4-common php7.4-mysql php7.4-gmp php7.4-curl php7.4-intl php7.4-mbstring php7.4-xmlrpc php7.4-gd php7.4-xml php7.4-cli php7.4-zip php7.4-soap php7.4-imap
It is recommended to raise the memory limit to improve the overall performance. Your PHP configuration is located in /etc/php/7.4/fpm/php.ini.
sudo vim /etc/php/7.4/fpm/php.ini
Replace it with memory_limit = 256 and save document with :wq command. How to edit files in text editor Vim you can read here: How to exit Vim? And other required commands.
Step 3: Configure Nginx
Add nginx to www-data group
sudo usermod -a -G www-data nginx
Change owner of directory to www-data
sudo chown -R www-data /usr/share/nginx/html
Go into your default.conf file
sudo vim /etc/nginx/conf.d/default.conf
Replace your existing configuration file with the one below
server { listen 80; server_name localhost; root /usr/share/nginx/html; index index.php index.html index.htm; location / { if ($request_uri ~ ^/(.*)\.html$) { return 302 /$1; } } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } location ~ \.php$ { fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
Restart Nginx server:
service nginx restart
Now you can cteate test file fith information about PHP version:
nano /usr/share/nginx/html/phpinfo.php
phpinfo();
In Web-browser write IP address of server:
http://192.168.1.1/phpinfo.php
That’s all Nginx Server with PHP 7.4 installed.