How to install Linux, Nginx, MariaDB, PHP (LEMP Stack) on Debian

Debian GNU/Linux Installer menu (BIOS mode)
Debian GNU/Linux Installer menu (BIOS mode)

This guide will teach you how to install and configure the Linux, NGINX, MySQL/MariaDB, and PHP (LEMP stack) on Debian 10.

  1. Install Debian Linux distribution:

Download the latest small installation image from https://www.debian.org/distrib/: 64-bit PC netinst iso or 32-bit PC netinst iso and create a bootable USB drive with Rufus; For this example, I will use 32-bit PC netinst iso (debian-10.1.0-i386-netinst.iso);

  • Boot the system with the Debian USB flash drive and choose Install:

[!!] Select a language
Language: English

[!!] Select your location
Country, territory or area: other
Continent or region: Europe
Country, territory or area: Romania

[!] Configure locales
Country to base default locale settings on: United States - en_US.UTF-8

[!!] Configure the keyboard
Keymap to use: American English or British English #depends on your computer keyboard

[!!] Configure the network
Primary network interface: enp2s0 #my example

[!] Configure the network
Hostname: webserver
<Continue>
Domain name: example.com
<Continue>

[!!] Set up users and passwords
Root password: rootpassword #create a strong password
<Continue>
Re-enter password to verify: rootpassword
<Continue>

[!!] Set up users and passwords #for non-administrative activities
Full name for the new user: Bogdan Caraman #my example
<Continue>
Username for your account: bogdan
Continue>
Choose a password for the new user: userpassword #create a strong password
<Continue>
Re-enter password to verify: userpassword
<Continue>

[!!] Partition disks
Partition method: Guided - use entire disk
Select disk partition: SCSI3 (sda) #my example

[!] Partition disks
Partitioning scheme: All files in one partition (recommended for new users)

[!!] Partition disks
Finish partitioning and write changes to disk

[!!] Partition disks
Write the changes to disks? <Yes>

Installing the base system

[!] Configure the package manager
Scan another CD or DVD? <No>

Debian archive mirror country: United States

Debian archive mirror: deb.debian.org
HTTP proxy information (blank for none):
<Continue>

Configuring apt

[!] Configuring popularity-contest
Participate in the package usage survey? <No>

[!] Software selection
Choose software to install:
[] <unselect all>
<Continue>

[!] Install the GRUB boot loader on a hard disk
Install the GRUB boot loader to the master boot record? <Yes>
Device for boot loader installation: /dev/sda

[!] Finish the installation

  • Remove the bootable USB Stick or installation media

<Continue>

Debian GNU/Linux 10 webserver tty1
webserver login: root
rootpassword

  1. Install the SSH Server
  • search software package:

[email protected]:~# apt-get update
[email protected]:~# apt-cache policy openssh-server
openssh-server:
Installed: 1:7.9p1-10
Candidate:
Version table:
*** 1:7.9p1-10 500
500 http://deb.debian.org/debian buster/main i386 Packages
100 /var/lib/dpkg/status

  • install software package:

[email protected]:~# apt-get install openssh-server
The following additional packeges will be installed:
dbus krb5-locales libdbus-1-3 libedit2 libgssapi-krb5-2 libk5crypto3 libkeyutils1 libkrb5-3 libkrb5support0 libpam-systemd libwrap0 libx11-6 libx11-data libxau6 libxcb1 libxdmcp6 libext6 libxmuu1 ncurses-term openssh-client openssh-sftp-server xauth
Suggested packages:
default-dbus-session-bus | dbus-session-bus krb5-doc krb5-user keychain libpam-ssh monkeysphere ssh-askpass molly-guard rssh ufw
The following NEW packages will be installed:
dbus krb5-locales libdbus-1-3 libedit2 libgssapi-krb5-2 libk5crypto3 libkeyutils1 libkrb5-3 libkrb5support0 libpam-systemd libwrap0 libx11-6 libx11-data libxau6 libxcb1 libxdmcp6 libext6 libxmuu1 ncurses-term openssh-client openssh-server openssh-sftp-server xauth
After this operation, 18.5 MB of additional disk space will be used
Do you want to continue? [Y/n] Y

  1. Enable SSH root login on Debian Linux Server.
  • make a backup of the original sshd_config file:

[email protected]:~# cp /etc/ssh/sshd_config /etc/ssh/sshd_config.backup-original

  • edit sshd_config and add PermitRootLogin yes:

[email protected]:~# nano /etc/ssh/sshd_config

# Authentication:
#LoginGraceTime 2m
#PermitRootLogin prohibit-password
PermitRootLogin yes
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

^X Exit | Save modified buffer? Y Yes | File Name to Write: /etc/ssh/sshd_config Enter

[email protected]:~# /etc/init.d/ssh restart
[ ok ] Restarting ssh (via systemctl): ssh.service.

  • find the current IP address of the server:

~# ip -4 a
inet 192.168.1.15/24 brd 192.168.1.255 scope global dynamic enp2s0
we found our DHCP IP address 192.168.1.15
Now you can connect to your server from another computer with PuTTY by the current IP address.

  1. Setting up an Ethernet Interface.
  • configuring the interface manually by changing dhcp with static IP address:

[email protected]:~# nano /etc/network/interfaces
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
allow-hotplug enp2s0
iface enp2s0 inet dhcp
# This is an autoconfigured IPv6 interface
iface enp2s0 inet6 auto

will change with:

# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
allow-hotplug enp2s0
iface enp2s0 inet static
address 192.168.1.120
netmask 255.255.255.0
network 192.168.1.100
broadcast 192.168.1.255 # found it from ip -4 a command line (inet 192.168.1.15/24 brd 192.168.1.255 scope global dynamic enp2s0)
gateway 192.168.1.1 # found it from ip route command line (ip route default via 192.168.1.1 dev enp2s0)

# This is an autoconfigured IPv6 interface
iface enp2s0 inet6 auto

^X Exit | Save modified buffer? Y Yes | File Name to Write: /etc/network/interfaces Enter

192.168.1.1 it will be your router from where you should add 192.168.1.120 for Port forwarding of 80 HTTP and 443 HTTPS

[email protected]:~# reboot your server for the changes to take effect

  1. Prevent suspending when the lid is closed (for laptops):

[email protected]:~# nano /etc/systemd/logind.conf
#HandleLidSwitch=suspend
HandleLidSwitch=ignore
#HandleLidSwitchExternalPower=suspend
#HandleLidSwitchDocked=ignore
HandleLidSwitchDocked=ignore
#PowerKeyIgnoreInhibited=no

^X Exit | Save modified buffer? Y Yes | File Name to Write: /etc/systemd/logind.conf Enter

  1. Disable suspend and hibernation

[email protected]:~# systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target
Created symlink /etc/systemd/system/sleep.target → /dev/null.
Created symlink /etc/systemd/system/suspend.target → /dev/null.
Created symlink /etc/systemd/system/hibernate.target → /dev/null.
Created symlink /etc/systemd/system/hybrid-sleep.target → /dev/null.

  • Re-Enable suspend and hibernation

[email protected]:~# systemctl unmask sleep.target suspend.target hibernate.target hybrid-sleep.target
Removed /etc/systemd/system/sleep.target.
Removed /etc/systemd/system/suspend.target.
Removed /etc/systemd/system/hibernate.target.
Removed /etc/systemd/system/hybrid-sleep.target.

[email protected]:~# reboot your server for the changes to take effect

  1. Change the hostname from “webserver” to anything else.

[email protected]:~# nano /etc/hostname

change webserver name to anything you want. For this demonstration, I didn’t change mine

[email protected]:~# hostname
webserver
[email protected]:~# hostname -f (long host name FQDN)
webserver.example.com
[email protected]:~#

  1. Configure the Hostname for your domain (www.example.com).

[email protected]:~# nano /etc/hosts
127.0.0.1 localhost
127.0.1.1 webserver.example.com webserver
your IP Static example.com www.example.com
# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

If you are using Cloudflare and your domain name are hosted there skip this step.
I chose Cloudflare for the SSL/TLS certificates and to run my websites through HTTPS. Let’s Encrypt (certbot) or Comodo Free SSL Certificate (valid for 30 days) are alternatives, but till now my favorite remains Cloudflare.
Instead of IP Static, you can also choose a Dynamic DNS to automatically updating your name server in the Domain Name Server (DNS), for this you don’t need to modify the hosts file anymore.

  1. Synchronize the System Clock with an NTP (network time protocol) server over the Internet:

[email protected]:~# apt-get update
[email protected]:~# apt-get install ntp
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
libevent-core-2.1-6 libevent-pthreads-2.1-6 libgdbm-compat4 libgdbm6 libopts25 libperl5.28 perl
perl-modules-5.28 sntp
Suggested packages:
ntp-doc perl-doc libterm-readline-gnu-perl | libterm-readline-perl-perl make libb-debug-perl
liblocale-codes-perl
The following NEW packages will be installed:
libevent-core-2.1-6 libevent-pthreads-2.1-6 libgdbm-compat4 libgdbm6 libopts25 libperl5.28 ntp perl
perl-modules-5.28 sntp
0 upgraded, 10 newly installed, 0 to remove and 0 not upgraded.
Need to get 7,907 kB of archives.
After this operation, 44.2 MB of additional disk space will be used.
Do you want to continue? [Y/n]

  1. Keeping your Debian system up-to-date:

[email protected]:~# apt-get udpate (updating the package database)
[email protected]:~# apt-get upgrade (upgrade the installed packages)
[email protected]:~# apt-get dist-upgrade (perform a complete upgrade)

  • How to clean your system with apt-get:

[email protected]:~# apt-get clean (removes those retrieved package files that have a newer version now, and so won’t be used anymore)
[email protected]:~# apt-get autoclean (it removes libraries and packages that were installed automatically to satisfy the dependencies of another installed package)
[email protected]:~# apt-get autoremove (cleaning a Linux system)

  1. Adjust the Firewall.

If you use iptables to filter connections to your system, you’ll need to open HTTP (80), HTTPS (443) and SSH (22) ports.
Open the necessary ports by issuing the following command:

[email protected]:~# iptables -A INPUT -p tcp --dport 22 -j ACCEPT
[email protected]:~# iptables -A INPUT -p tcp --dport 80 -j ACCEPT
[email protected]:~# iptables -A INPUT -p tcp --dport 443 -j ACCEPT

To see the effective rules:
[email protected]:~# iptables -L
[email protected]:~# iptables -t nat -L

Save IPtables Rules to a File:
[email protected]:~# iptables-save > ~/iptables.rules

After ~# reboot you can restore IPtables rules from the file with:
[email protected]:~# iptables-restore < ~/iptables.rules

Install the Nginx (Engine X) web server, MariaDB database management, and PHP by using the packages available in the Debian Package archive.

  1. Install and configure Nginx:

[email protected]:~# apt-get update (update the Debian repository information)
[email protected]:~# apt-cache policy nginx (find out if a specific program is installed)
nginx:
Installed: (none)
Candidate: 1.14.2-2+deb10u1
Version table:
1.14.2-2+deb10u1 500
500 http://deb.debian.org/debian buster/main i386 Packages
500 http://security.debian.org/debian-security buster/updates/main i386 Packages
[email protected]:~# apt-get install nginx (install the software package)
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
fontconfig-config fonts-dejavu-core geoip-database libfontconfig1 libgd3
libgeoip1 libicu63 libjbig0 libjpeg62-turbo libnginx-mod-http-auth-pam
libnginx-mod-http-dav-ext libnginx-mod-http-echo libnginx-mod-http-geoip
libnginx-mod-http-image-filter libnginx-mod-http-subs-filter
libnginx-mod-http-upstream-fair libnginx-mod-http-xslt-filter
libnginx-mod-mail libnginx-mod-stream libtiff5 libwebp6 libxml2 libxpm4
libxslt1.1 nginx-common nginx-full
Suggested packages:
libgd-tools geoip-bin fcgiwrap nginx-doc ssl-cert
The following NEW packages will be installed:
fontconfig-config fonts-dejavu-core geoip-database libfontconfig1 libgd3
libgeoip1 libicu63 libjbig0 libjpeg62-turbo libnginx-mod-http-auth-pam
libnginx-mod-http-dav-ext libnginx-mod-http-echo libnginx-mod-http-geoip
libnginx-mod-http-image-filter libnginx-mod-http-subs-filter
libnginx-mod-http-upstream-fair libnginx-mod-http-xslt-filter
libnginx-mod-mail libnginx-mod-stream libtiff5 libwebp6 libxml2 libxpm4
libxslt1.1 nginx nginx-common nginx-full
0 upgraded, 27 newly installed, 0 to remove and 0 not upgraded.
Need to get 16.4 MB of archives.
After this operation, 53.3 MB of additional disk space will be used.
Do you want to continue? [Y/n]
[email protected]:~# nginx -v find the version number of the nginx installed
nginx version: nginx/1.14.2

  • backup the original nginx.conf file:

[email protected]:~# cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.backup-original

  • Disable Server Tokens. Disabling server tokens makes it more difficult to determine NGINX’s version:

[email protected]:~# nano /etc/nginx/nginx.conf
...
http {
...
# server_tokens off;
change it to
server_tokens off;

^X Exit | Save modified buffer? Y Yes | File Name to Write: /etc/nginx/nginx.conf Enter

Now all 404 Not Found missing webpages with nginx 1.14.2 will show only 404 Not Found – nginx

Set the site’s root directory:

  • create the directory for example.com

[email protected]:~# mkdir -p /var/www/example.com/
[email protected]:~# cd /var/www/example..com
[email protected]:/var/www/example.com# ls -la long format list (permissions, ownership, size and modification date) of all files
total 8
drwxr-xr-x 2 root root 4096 Sep 17 00:02 .
drwxr-xr-x 4 root root 4096 Sep 17 00:02 ..
[email protected]:/var/www/example.com#

  • create a sample index.html page

[email protected]:~# nano /var/www/example.com/index.html
<html>
<head>
<title>Welcome to example.com!</title>
</head>
<body>
<h1>Success! The example.com server block is working!</h1>
</body>
</html>

^X Exit | Save modified buffer? Y Yes | File Name to Write: /var/www/example.com/index.html Enter

In order for Nginx to serve this content, it’s necessary to create a server block with the correct directives. Instead of modifying the default configuration file directly, let’s make a new one at /etc/nginx/sites-available/example.com:

[email protected]:~# nano /etc/nginx/sites-available/example.com
server {
listen 80;
listen [::]:80;
server_name example.com www.example.com;
root /var/www/example.com;
index index.html index.htm index.nginx-debian.html;
location / {
try_files $uri $uri/ =404;
}
}

  • enable the file by creating a link from it to the sites-enabled directory, which Nginx reads from during startup:

[email protected]:~# ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/

[email protected]:~# nginx -t (test the configuration file: nginx checks the configuration for correct syntax, and then tries to open files referred in the configuration)
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

[email protected]:~# systemctl restart nginx (restarting nginx service)

From your Desktop computer open the favorite browser and type your example.com address or IP address to see your first HTML test page. To upload your webpage at /var/www/example.com/ you can use WinSCP (a free and open-source SFTP, FTP client for Microsoft Windows) and connect with the root user name and rootpassword. Make sure to have PermitRootLogin yes on your /etc/ssh/ssd_config file.

  1. Enabling HTTPS on your server.

[email protected]:~# apt-get update
[email protected]:~# apt-get install openssl

  • Managing Cloudflare Origin CA certificates (in my case) or use alternatives like Let’s Encrypt (certbot) or Comodo Free SSL Certificate (valid for 30 days);
  • Generate a free TLS certificate signed by Cloudflare to install on your origin server;
  • Choose how long before your certificate expires: 30 days or more;
  • Save both the private key and certificate below to your web server;
  • Origin Certificate save it to example.com.pem
  • A private key save it to example.com.key
  • copy the files to the server or you can paste the codes as below:

[email protected]:~# nano /etc/ssl/certs/example.com.pem Paste the PEM code there and save the file
[email protected]:~# nano /etc/ssl/private/example.com.key Paste the private key and save the file

  1. Edit the Nginx virtual host file and add the following lines to:

[email protected]:~# nano /etc/nginx/sites-available/example.com
server {
listen 80;
listen [::]:80;

listen 443;
listen [::]:443;

ssl on;
ssl_certificate /etc/ssl/certs/example.com.pem;
ssl_certificate_key /etc/ssl/private/example.com.key;

server_name example.com www.example.com;
root /var/www/example.com;
index index.html index.htm index.nginx-debian.html;
location / {
try_files $uri $uri/ =404;
}
}

^X Exit | Save modified buffer? Y Yes | File Name to Write: /etc/nginx/sites-available/example.com Enter

  • test configuration file:

[email protected]:~# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

  • restart Nginx:

[email protected]:~# systemctl restart nginx

From now on, the address of the web page will be changed in https://example.com when you type it from your favorite browser.

  1. Install and configure MariaDB:

[email protected]:~# apt-get update (update the Debian repository information)
[email protected]:~# apt-cache policy mariadb-server (find out if a specific program is installed)
mariadb-server:
Installed: (none)
Candidate: 1:10.3.17-0+deb10u1
Version table:
1:10.3.17-0+deb10u1 500
500 http://deb.debian.org/debian buster/main i386 Packages
[email protected]:~# apt-get install mariadb-server (install the software package)
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
fontconfig-config fonts-dejavu-core geoip-database libfontconfig1 libgd3
libgeoip1 libicu63 libjbig0 libjpeg62-turbo libnginx-mod-http-auth-pam
libnginx-mod-http-dav-ext libnginx-mod-http-echo libnginx-mod-http-geoip
libnginx-mod-http-image-filter libnginx-mod-http-subs-filter
libnginx-mod-http-upstream-fair libnginx-mod-http-xslt-filter
libnginx-mod-mail libnginx-mod-stream libtiff5 libwebp6 libxml2 libxpm4
libxslt1.1 nginx-common nginx-full
Use 'apt autoremove' to remove them.
The following additional packages will be installed:
galera-3 gawk libaio1 libcgi-fast-perl libcgi-pm-perl
libconfig-inifiles-perl libdbd-mysql-perl libdbi-perl libencode-locale-perl
libfcgi-perl libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl
libhttp-date-perl libhttp-message-perl libio-html-perl
liblwp-mediatypes-perl libmariadb3 libmpfr6 libreadline5 libsigsegv2
libsnappy1v5 libterm-readkey-perl libtimedate-perl liburi-perl lsof
mariadb-client-10.3 mariadb-client-core-10.3 mariadb-common
mariadb-server-10.3 mariadb-server-core-10.3 mysql-common psmisc rsync socat
Suggested packages:
gawk-doc libclone-perl libmldbm-perl libnet-daemon-perl
libsql-statement-perl libdata-dump-perl libipc-sharedcache-perl libwww-perl
mailx mariadb-test netcat-openbsd tinyca
The following NEW packages will be installed:
galera-3 gawk libaio1 libcgi-fast-perl libcgi-pm-perl
libconfig-inifiles-perl libdbd-mysql-perl libdbi-perl libencode-locale-perl
libfcgi-perl libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl
libhttp-date-perl libhttp-message-perl libio-html-perl
liblwp-mediatypes-perl libmariadb3 libmpfr6 libreadline5 libsigsegv2
libsnappy1v5 libterm-readkey-perl libtimedate-perl liburi-perl lsof
mariadb-client-10.3 mariadb-client-core-10.3 mariadb-common mariadb-server
mariadb-server-10.3 mariadb-server-core-10.3 mysql-common psmisc rsync socat
0 upgraded, 36 newly installed, 0 to remove and 0 not upgraded.
Need to get 22.5 MB of archives.
After this operation, 161 MB of additional disk space will be used.
Do you want to continue? [Y/n]
[email protected]:~# systemctl status mariadb (check the status of MariaDB)
● mariadb.service - MariaDB 10.3.17 database server
Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset:
Active: active (running) since Tue 2019-09-17 21:56:30 EEST; 19s ago
Docs: man:mysqld(8)
https://mariadb.com/kb/en/library/systemd/
Main PID: 1361 (mysqld)
Status: "Taking your SQL requests now..."
Tasks: 31 (limit: 4915)
Memory: 51.0M
CGroup: /system.slice/mariadb.service
└─1361 /usr/sbin/mysqld
Sep 17 21:56:29 webserver systemd[1]: Starting MariaDB 10.3.17 database server..
Sep 17 21:56:30 webserver mysqld[1361]: 2019-09-17 21:56:30 0 [Note] /usr/sbin/m
Sep 17 21:56:30 webserver systemd[1]: Started MariaDB 10.3.17 database server.
Sep 17 21:56:30 webserver /etc/mysql/debian-start[1452]: Triggering myisam-recov
line 1-16/16 (END)

  • improve the security of your MariaDB installation:

[email protected]:~# mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

We don’t have to change the MySQL root password as we just set a new one during installation.
Answer the questions as follows:

Enter current password for root (enter for none):
Set root password? <Y>
New password: MySQL root password
Re-enter new password: MySQL root password
Remove anonymous users? <Y>
Disallow root login remotely? <Y>
Remove test database and access to it? <Y>
Reload privilege tables now? <Y>
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!

  • show databases list from MariaDB:

[email protected]:~# mysql -u root -p
Enter password: MySQL root password
MariaDB [(none)]> SHOW DATABASES;
Database
information_schema
mysql
performance_schema

  • show users list from MariaDB:

MariaDB [(none)]> SELECT User FROM mysql.user;
User
root

MariaDB [(none)]> create database db1;

MariaDB [(none)]> GRANT ALL ON db1.* TO administrator_db1 IDENTIFIED BY "administratorpasswordfordb1";

MariaDB [(none)]> DROP USER administrator_db1;

MariaDB [(none)]> DROP DATABASE db1;

  • to quit from MariaDB:

MariaDB [(none)]> quit
Bye
[email protected]:~#

  • exporting a single database and the user using mysqldump:

[email protected]:~# mysqldump -u administrator_db1 -p db1 > backup-db1.sql
Enter password: administratorpasswordfordb1

  • check if it’s a legitimate SQL dump file:

[email protected]:~# head -n 5 backup-db1.sql

  • delete MySQL Shell History and Bash History:

[email protected]:~# cat /dev/null > ~/.mysql_history
[email protected]:~# cat /dev/null > ~/.bash_history

  1. Install PHP with FastCGI Process Manager (FPM)

r[email protected]:~# apt-get update (update the Debian repository information)
[email protected]:~# apt-get install php-fpm
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
fontconfig-config fonts-dejavu-core geoip-database libfontconfig1 libgd3 libgeoip1 libjbig0
libjpeg62-turbo libnginx-mod-http-auth-pam libnginx-mod-http-dav-ext libnginx-mod-http-echo
libnginx-mod-http-geoip libnginx-mod-http-image-filter libnginx-mod-http-subs-filter
libnginx-mod-http-upstream-fair libnginx-mod-http-xslt-filter libnginx-mod-mail
libnginx-mod-stream libtiff5 libwebp6 libxpm4 libxslt1.1 nginx-common nginx-full
Use 'apt autoremove' to remove them.
The following additional packages will be installed:
libpcre2-8-0 libsodium23 php-common php7.3-cli php7.3-common php7.3-fpm php7.3-json
php7.3-opcache php7.3-readline
Suggested packages:
php-pear
The following NEW packages will be installed:
libpcre2-8-0 libsodium23 php-common php-fpm php7.3-cli php7.3-common php7.3-fpm php7.3-json
php7.3-opcache php7.3-readline
0 upgraded, 10 newly installed, 0 to remove and 0 not upgraded.
Need to get 4,474 kB of archives.
After this operation, 17.7 MB of additional disk space will be used.
Do you want to continue? [Y/n]

  • install an additional package:

[email protected]:~# apt-get install php-mysql
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
fontconfig-config fonts-dejavu-core geoip-database libfontconfig1 libgd3 libgeoip1 libjbig0
libjpeg62-turbo libnginx-mod-http-auth-pam libnginx-mod-http-dav-ext libnginx-mod-http-echo
libnginx-mod-http-geoip libnginx-mod-http-image-filter libnginx-mod-http-subs-filter
libnginx-mod-http-upstream-fair libnginx-mod-http-xslt-filter libnginx-mod-mail
libnginx-mod-stream libtiff5 libwebp6 libxpm4 libxslt1.1 nginx-common nginx-full
Use 'apt autoremove' to remove them.
The following additional packages will be installed:
php7.3-mysql
The following NEW packages will be installed:
php-mysql php7.3-mysql
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 131 kB of archives.
After this operation, 445 kB of additional disk space will be used.
Do you want to continue? [Y/n]
[email protected]:~#

  • verify your default PHP version used on your system:

[email protected]:~# php -v
PHP 7.3.4-2 (cli) (built: Apr 13 2019 19:05:48) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.4, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.3.4-2, Copyright (c) 1999-2018, by Zend Technologies

  • show PHP version information:

[email protected]:~# apt show php
[email protected]:~# apt show php -a

  • Configure Nginx to Use the PHP Processor:

[email protected]:~# nano /etc/nginx/sites-available/example.com
server {
listen 80;
listen [::]:80;

listen 443;
listen [::]:443;

ssl on;
ssl_certificate /etc/ssl/certs/example.com.pem;
ssl_certificate_key /etc/ssl/private/example.com.key;

server_name example.com www.example.com;

root /var/www/example.com;
index index.php index.html index.htm index.nginx-debian.html;

location / {
try_files $uri $uri/ =404;
}

location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
}

location ~ /\.ht {
deny all;
}

}

  • when you’ve made the above changes, you can save and close the file:

^X Exit | Save modified buffer? Y Yes | File Name to Write: /etc/nginx/sites-available/example.com Enter

[email protected]:~# nginx -t (test the configuration file: nginx checks the configuration for correct syntax, and then tries to open files referred in the configuration)
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

[email protected]:~# systemctl restart nginx (restarting nginx service)

  • create a PHP file to test configuration:

[email protected]:~# nano /var/www/example.com/info.php

  • paste the following code:

<?php
// Show all information, defaults to INFO_ALL
phpinfo();
?>

^X Exit | Save modified buffer? Y Yes | File Name to Write: /var/www/example.com/info.php Enter

Open your favorite browser and type www.example.com/info.php or your static IP address to see a web page that has been generated by PHP with information about your server.

  • remove the info.php file by typing:

[email protected]:~# rm /var/www/example.com/info.php

  • configure the PHP processor:

[email protected]:~# cp /etc/php/7.3/fpm/php.ini /etc/php/7.3/fpm/php.ini.backup-original backup original php.ini
[email protected]:~# nano /etc/php/7.3/fpm/php.ini edit the php.ini file

find and change the date.timezone with your region:

date.timezone = Europe/Bucharest

  • restart PHP

[email protected]:~# systemctl restart php7.3-fpm
[email protected]:~# exit

~The End~

You can find the latest version of Debian at https://www.debian.org