Last update at :2024-06-13,Edit by888u
We generally configure the WEB environment in the Linux server, and most of them use Apache and Nginx engines. We call the former LAMP, and the latter we are accustomed to call it LNMP, but it is called LEMP abroad. For our daily production use, it is simpler for us to use the more mature one-click package. If we want to learn the application and the entire compilation process, we can try to manually compile the software.
In this article, Snail shares the manual compilation and installation of LEMP (Nginx) environment based on Ubuntu 16.04 system. If friends need it, you can refer to it. But there is no need to do this only for learning to use the website building environment, and the efficiency is too low.
First, install Nginx
sudo apt updatesudo apt install nginx -y
We need to update the source first, and then install Nginx according to the version that comes with the system.
systemctl enable nginx
Start Nginx here to take effect. Every Ubuntu installation comes preinstalled with the ufw software. To maximize security, we need to configure it to allow HTTP, HTTPS, FTP, and SSH connections, and deny all other connections.
sudo ufw allow OpenSSHsudo ufw allow SSHsudo ufw allow FTPsudo ufw allow \\’Nginx HTTP\\’sudo ufw allow \\’Nginx HTTPS\\’
Then we activate the startup:
sudo ufw enable
If an error is found, we need to disable:
sudo ufw disable
Second, install the MariaDB database
sudo apt install mariadb-server mariadb-client -y
Snail saw that foreigners prefer to use MariaDB database, and I remember the same from the previous tutorial.
sudo systemctl start mysql
After installing the database, we start.
sudo systemctl enable mysql
We need to set up startup.
sudo mysql_secure_installation
Then proceed to security account settings.
sudo mysql -u root -p
We can try to connect and create a database account.
Third, install PHP software
Now the latest PHP version is PHP7.3, we need to install this new version.
sudo apt install software-properties-common
We need to update and install the latest software packages first.
sudo add-apt-repository ppa:ondrej/php
Install the necessary software packages for PHP7.3, and then use apt update to upgrade the source.
sudo apt install php7.3 php7.3-fpm -y
In this way, let’s install PHP7.3.
sudo apt install php7.3-mysql php7.3-mbstring php7.3-dev php7.3-gd php-pear php7.3-zip php7.3-xml php7.3-curl -y
In this way, we will install the necessary software for WEB.
sudo update-alternatives –set php /usr/bin/php7.3
Set the latest version. At the same time, we can check whether PHP is the latest installed version.
Fourth, configure Nginx + PHP
Currently, the PHP software is installed and working properly, but Nginx does not use it automatically, which means we must configure Nginx ourselves. Before we do that, we'll fix a very insecure PHP setting called cgi.fix_pathinfo. By default, it is set to 1 (meaning enabled).
sudo nano /etc/php/7.3/fpm/php.ini
Open this file, edit to find \\";cgi.fix_pathinfo=1\\", and then set it to \\"cgi.fix_pathinfo=0\\". Then we start it to take effect\\"sudo systemctl restart php7.3-fpm\\".
We are ready to configure the site:
nano /etc/nginx/sites-enabled/default
Edit file:
server {listen 80 default_server;listen [::]:80 default_server;
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
server_name_;
location / {try_files $uri $uri/ =404;}
location ~ \\\\.php$ {include snippets/fastcgi-php.conf;fastcgi_pass unix:/run/php/php7.3-fpm.sock;}
location ~ /\\\\.ht {deny all;}}
Need to start after saving:
sudo systemctl restart nginx
Finally we test whether it works.
Add files:
sudo nano /var/www/html/index.php
Then we add the file code:
phpinfo();
?>
In this way, we open the website and see if we see the PHP configuration. If so, it means there is no problem with the connection.
In this way, a simple LEMP environment is configured. Reference address: https://lowendbox.com/blog/lemp-stack-installation-on-ubuntu-16-04/
Recommended site searches: domain name search, how to build a server, national dynamic IP, international domain name registration platform, Wanwang domain name space, website domain name query system, cn domain name registration, free virtual host server, Wanwang domain name space, < /p>
发表评论