{"id":599,"date":"2021-10-21T05:29:00","date_gmt":"2021-10-21T05:29:00","guid":{"rendered":"https:\/\/262235.xyz\/?p=599"},"modified":"2021-10-21T05:29:00","modified_gmt":"2021-10-21T05:29:00","slug":"599","status":"publish","type":"post","link":"https:\/\/lyvba.com\/index.php\/2021\/10\/21\/599\/","title":{"rendered":"\u4ec0\u4e48\u662f LEMP \u5806\u6808\uff1f\u5982\u4f55\u5728 Ubuntu 20.04 \u4e0a\u8fdb\u884c\u8bbe\u7f6e # What is LEMP Stack? How to set up on Ubuntu 20.04"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/lyvba.com\/wp-content\/uploads\/2021\/10\/2775392862.webp\" alt=\"install-LEMP-stack-on-your-Ubuntu-20.04-server.webp\" title=\"install-LEMP-stack-on-your-Ubuntu-20.04-server.webp\"><\/p>\n<h1>What is LEMP Stack? How to set up on Ubuntu 20.04<\/h1>\n<h1>\u4ec0\u4e48\u662f LEMP \u5806\u6808\uff1f\u5982\u4f55\u5728 Ubuntu 20.04 \u4e0a\u8fdb\u884c\u8bbe\u7f6e<\/h1>\n<p>Are you looking for simple steps to install LEMP stack on your Ubuntu 20.04<br \/>server? Read this tutorial, as I am going to share steps to install LEMP stack<br \/>on Ubuntu.<\/p>\n<p>\u60a8\u662f\u5426\u6b63\u5728\u5bfb\u627e\u5728 Ubuntu 20.04 \u670d\u52a1\u5668\u4e0a\u5b89\u88c5 LEMP \u5806\u6808\u7684\u7b80\u5355\u6b65\u9aa4\uff1f\u9605\u8bfb\u672c\u6559\u7a0b\uff0c\u56e0\u4e3a\u6211\u5c06\u5206\u4eab\u5728 Ubuntu \u4e0a\u5b89\u88c5 LEMP \u5806\u6808\u7684\u6b65\u9aa4\u3002<\/p>\n<p>LEMP stack is a bundle of software tools that include Linux, Nginx, MariaDB,<br \/>and PHP. All these tools are open source and free to use for anyone around the<br \/>world. The combination of these tools make a powerful server stack which can<br \/>be used to host high-performance websites. It is also a great way to install<br \/>WordPress on your VPS server.<\/p>\n<p>LEMP \u5806\u6808\u662f\u4e00\u7ec4\u8f6f\u4ef6\u5de5\u5177\uff0c\u5305\u62ec Linux\u3001Nginx\u3001MariaDB \u548c PHP\u3002\u6240\u6709\u8fd9\u4e9b\u5de5\u5177\u90fd\u662f\u5f00\u6e90\u7684\uff0c\u53ef\u4f9b\u4e16\u754c\u5404\u5730\u7684\u4efb\u4f55\u4eba\u514d\u8d39\u4f7f\u7528\u3002\u8fd9\u4e9b\u5de5\u5177\u7684\u7ec4\u5408\u6784\u6210\u4e86\u4e00\u4e2a\u5f3a\u5927\u7684\u670d\u52a1\u5668\u5806\u6808\uff0c\u53ef\u7528\u4e8e\u6258\u7ba1\u9ad8\u6027\u80fd\u7f51\u7ad9\u3002\u8fd9\u4e5f\u662f\u5728 VPS \u670d\u52a1\u5668\u4e0a\u5b89\u88c5 WordPress \u7684\u597d\u65b9\u6cd5\u3002<\/p>\n<p>Let me tell you what these tools stand for in short.<br \/>\u8ba9\u6211\u7b80\u5355\u5730\u544a\u8bc9\u60a8\u8fd9\u4e9b\u5de5\u5177\u7684\u542b\u4e49\u3002<\/p>\n<ul>\n<li><strong>Linux<\/strong> : A very popular & commonly used Operating System  \u4e00\u4e2a\u975e\u5e38\u6d41\u884c\u548c\u5e38\u7528\u7684\u64cd\u4f5c\u7cfb\u7edf<\/li>\n<li><strong>Nginx<\/strong> : A web server  \u4e00\u4e2a\u7f51\u7edc\u670d\u52a1\u5668<\/li>\n<li><strong>MariaDB\/MySQL<\/strong> : A database server  \u6570\u636e\u5e93\u670d\u52a1\u5668<\/li>\n<li><strong>PHP<\/strong> : Coding language used to build any kind of website. WordPress which is an open source platform is built using PHP.  \u7528\u4e8e\u6784\u5efa\u4efb\u4f55\u7c7b\u578b\u7f51\u7ad9\u7684\u7f16\u7801\u8bed\u8a00\u3002WordPress \u662f\u4e00\u4e2a\u4f7f\u7528 PHP \u6784\u5efa\u7684\u5f00\u6e90\u5e73\u53f0\u3002<\/li>\n<\/ul>\n<h2>Prerequisites<\/h2>\n<h2>\u5148\u51b3\u6761\u4ef6<\/h2>\n<p>To set up the LEMP stack on Ubuntu 20.04, you need Ubuntu 20.04 installed on<br \/>your server. Minimum server configuration should be<\/p>\n<p>\u8981\u5728 Ubuntu 20.04 \u4e0a\u8bbe\u7f6e LEMP \u5806\u6808\uff0c\u60a8\u9700\u8981\u5728\u670d\u52a1\u5668\u4e0a\u5b89\u88c5 Ubuntu 20.04\u3002\u6700\u4f4e\u670d\u52a1\u5668\u914d\u7f6e\u5e94\u8be5\u662f<\/p>\n<ul>\n<li>1GB Ram<\/li>\n<li>25GB SSD Storage<\/li>\n<li>Root Access to the Server<\/li>\n<\/ul>\n<p>You can easily create an Ubuntu 20.04 server on Skysilk for as low as<br \/>5$\/month.<br \/>\u60a8\u53ef\u4ee5\u4ee5\u4f4e\u81f3 5 \u7f8e\u5143\/\u6708\u7684\u4ef7\u683c\u5728 Skysilk \u4e0a\u8f7b\u677e\u521b\u5efa Ubuntu 20.04 \u670d\u52a1\u5668\u3002(\u5b9e\u96455\u7f8e\u51431\u5e74\u4e5f\u6709)<\/p>\n<p>Let us proceed with this tutorial so you can set up & get it running quickly.<br \/>\u8ba9\u6211\u4eec\u7ee7\u7eed\u672c\u6559\u7a0b\uff0c\u4ee5\u4fbf\u60a8\u53ef\u4ee5\u8bbe\u7f6e\u5e76\u4f7f\u5176\u5feb\u901f\u8fd0\u884c\u3002<\/p>\n<h3>Connecting your Server<\/h3>\n<h3>\u8fde\u63a5\u60a8\u7684\u670d\u52a1\u5668<\/h3>\n<p>If you are running MacOS or Ubuntu operating system on your machine, you can<br \/>use Terminal app to remotely connect with your server. Simply use the below<br \/>command in your terminal app to login.<\/p>\n<p>\u5982\u679c\u60a8\u7684\u673a\u5668\u4e0a\u8fd0\u884c MacOS \u6216 Ubuntu \u64cd\u4f5c\u7cfb\u7edf\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u7ec8\u7aef\u5e94\u7528\u7a0b\u5e8f\u8fdc\u7a0b\u8fde\u63a5\u60a8\u7684\u670d\u52a1\u5668\u3002\u53ea\u9700\u5728\u60a8\u7684\u7ec8\u7aef\u5e94\u7528\u7a0b\u5e8f\u4e2d\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5373\u53ef\u767b\u5f55\u3002<\/p>\n<pre><code>ssh root@118.118.1.2\n<\/code><\/pre>\n<h3>Step 1: Package Updates  \u8f6f\u4ef6\u5305\u66f4\u65b0<\/h3>\n<p>It is a good practice to update the software packages and refresh the apt<br \/>repositories by running a few commands on Ubuntu 20.04 OS. Here are the<br \/>commands:<br \/>\u901a\u8fc7\u5728 Ubuntu 20.04 \u64cd\u4f5c\u7cfb\u7edf\u4e0a\u8fd0\u884c\u4e00\u4e9b\u547d\u4ee4\u6765\u66f4\u65b0\u8f6f\u4ef6\u5305\u548c\u5237\u65b0 apt \u5b58\u50a8\u5e93\u662f\u4e00\u4e2a\u5f88\u597d\u7684\u505a\u6cd5\u3002\u4ee5\u4e0b\u662f\u547d\u4ee4\uff1a<\/p>\n<pre><code>sudo apt update\nsudo apt upgrade\n<\/code><\/pre>\n<h3>Step 2: Nginx Web Server Installation  \u670d\u52a1\u5668\u5b89\u88c5<\/h3>\n<p>Follow the below steps with commands to install Nginx server. Nginx is a<br \/>widely used server nowadays. To ensure, you install it properly on your<br \/>computer, enter the following commands.<br \/>\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u4f7f\u7528\u547d\u4ee4\u5b89\u88c5 Nginx \u670d\u52a1\u5668\u3002Nginx \u662f\u5f53\u4eca\u5e7f\u6cdb\u4f7f\u7528\u7684\u670d\u52a1\u5668\u3002\u4e3a\u786e\u4fdd\u5728\u8ba1\u7b97\u673a\u4e0a\u6b63\u786e\u5b89\u88c5\u5b83\uff0c\u8bf7\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u3002<\/p>\n<pre><code>sudo apt install nginx\n<\/code><\/pre>\n<p>With this command, Nginx will be installed. But now we need to enable it to<br \/>auto-start at boot time.<br \/>\u4f7f\u7528\u6b64\u547d\u4ee4\uff0c\u5c06\u5b89\u88c5 Nginx\u3002\u4f46\u662f\u73b0\u5728\u6211\u4eec\u9700\u8981\u8ba9\u5b83\u5728\u542f\u52a8\u65f6\u81ea\u52a8\u542f\u52a8\u3002<\/p>\n<p>So, run the following command to auto-start Nginx.<br \/>\u56e0\u6b64\uff0c\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u4ee5\u81ea\u52a8\u542f\u52a8 Nginx\u3002<\/p>\n<pre><code>sudo systemctl enable nginx\n<\/code><\/pre>\n<p>Now start Nginx with the below command<br \/>\u73b0\u5728\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u542f\u52a8 Nginx<\/p>\n<pre><code>sudo systemctl start nginx\n<\/code><\/pre>\n<p>To check the status of Nginx, use the following command<br \/>\u8981\u68c0\u67e5 Nginx \u7684\u72b6\u6001\uff0c\u8bf7\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4<\/p>\n<pre><code>sudo systemctl status nginx\n<\/code><\/pre>\n<p>This is the output you get when you check the status of Nginx<br \/>\u8fd9\u662f\u60a8\u68c0\u67e5 Nginx \u72b6\u6001\u65f6\u5f97\u5230\u7684\u8f93\u51fa<\/p>\n<pre><code>\u25cf nginx.service - A high performance web server and a reverse proxy server\n     Loaded: loaded (\/lib\/systemd\/system\/nginx.service; enabled; vendor preset: enabled)\n     Active: active (running) since Mon 2021-07-05 13:09:03 UTC; 1min 22s ago\n       Docs: man:nginx(8)\n   Main PID: 14447 (nginx)\n      Tasks: 2 (limit: 464250)\n     Memory: 2.9M\n     CGroup: \/system.slice\/nginx.service\n             \u251c\u250014447 nginx: master process \/usr\/sbin\/nginx -g daemon on; master_process on;\n             \u2514\u250014448 nginx: worker process\n<\/code><\/pre>\n<p>If the status shows Enabled, it means Nginx will auto-start at boot time and<br \/>is running properly. You can also check the memory consumption by Nginx and<br \/>quit the command manually by pressing \u2018q\u2019 if it doesn't quit automatically.<br \/>\u5982\u679c\u72b6\u6001\u663e\u793a\u4e3a Enabled\uff0c\u5219\u8868\u793a Nginx \u5c06\u5728\u542f\u52a8\u65f6\u81ea\u52a8\u542f\u52a8\u5e76\u6b63\u5e38\u8fd0\u884c\u3002\u60a8\u8fd8\u53ef\u4ee5\u901a\u8fc7 Nginx \u68c0\u67e5\u5185\u5b58\u6d88\u8017\uff0c\u5982\u679c\u6ca1\u6709\u81ea\u52a8\u9000\u51fa\uff0c\u8bf7\u6309\u201cq\u201d\u624b\u52a8\u9000\u51fa\u547d\u4ee4\u3002 <\/p>\n<p>To check the Nginx version, use the below command<br \/>\u8981\u68c0\u67e5 Nginx \u7248\u672c\uff0c\u8bf7\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4<\/p>\n<pre><code>\nnginx -v\n<\/code><\/pre>\n<p>And it will show the output as follows:  \u5b83\u5c06\u663e\u793a\u5982\u4e0b\u8f93\u51fa\uff1a<\/p>\n<pre><code>nginx version: nginx\/1.18.0 (Ubuntu)\n<\/code><\/pre>\n<p>Next, type the public IP address of your Ubuntu 20.04 server which you can get<br \/>from Skysilk VPS dashboard.<br \/>\u63a5\u4e0b\u6765\uff0c\u952e\u5165\u60a8\u53ef\u4ee5\u4ece Skysilk VPS \u4eea\u8868\u677f\u83b7\u53d6\u7684 Ubuntu 20.04 \u670d\u52a1\u5668\u7684\u516c\u5171 IP \u5730\u5740\u3002<\/p>\n<p>If the Nginx server is running properly, you will see \u201c <strong>Welcome to Nginx! \"<\/strong> page.<br \/>\u5982\u679c Nginx \u670d\u52a1\u5668\u8fd0\u884c\u6b63\u5e38\uff0c\u60a8\u5c06\u770b\u5230\u201c\u6b22\u8fce\u4f7f\u7528 Nginx\uff01\u201d \u9875\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.skysilk.com\/blog\/wp-content\/uploads\/2021\/07\/image.jpeg\" alt=\"\" title=\"\"><\/p>\n<p>Just in case it does not work, the chances are that the UFW firewall is<br \/>preventing Port 80.<br \/>\u4ee5\u9632\u4e07\u4e00\u5b83\u4e0d\u8d77\u4f5c\u7528\uff0c\u53ef\u80fd\u662f UFW \u9632\u706b\u5899\u963b\u6b62\u4e86\u7aef\u53e3 80\u3002<\/p>\n<p>To open TCP port 80 when using UFW firewall, use this command<br \/>\u8981\u5728\u4f7f\u7528 UFW \u9632\u706b\u5899\u65f6\u6253\u5f00 TCP \u7aef\u53e3 80\uff0c\u8bf7\u4f7f\u7528\u6b64\u547d\u4ee4<\/p>\n<pre><code>sudo ufw allow http\n<\/code><\/pre>\n<p>To make Nginx user as the owner of the web directory, use:<br \/>\u8981\u4f7f Nginx \u7528\u6237\u6210\u4e3a web \u76ee\u5f55\u7684\u6240\u6709\u8005\uff0c\u8bf7\u4f7f\u7528\uff1a<\/p>\n<pre><code>\nsudo chown www-data:www-data \/usr\/share\/nginx\/html -R\n<\/code><\/pre>\n<h3>Step 3: MariaDB Database Server Installation \u6570\u636e\u5e93\u670d\u52a1\u5668\u5b89\u88c5<\/h3>\n<p>You already know that MariaDB is an alternative for MySQL developed by the<br \/>former members of MySQL. To install MariaDB on Ubuntu 20.04, enter the below<br \/>commands.<br \/>\u4f60\u5df2\u7ecf\u77e5\u9053 MariaDB \u662f MySQL \u7684\u524d\u6210\u5458\u5f00\u53d1\u7684 MySQL \u7684\u66ff\u4ee3\u54c1\u3002\u8981\u5728 Ubuntu 20.04 \u4e0a\u5b89\u88c5 MariaDB\uff0c\u8bf7\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u3002<\/p>\n<pre><code>sudo apt install mariadb-server mariadb-client\n<\/code><\/pre>\n<p>Now that MariaDB is installed, you can check its status.<br \/>\u73b0\u5728 MariaDB \u5df2\u5b89\u88c5\uff0c\u60a8\u53ef\u4ee5\u68c0\u67e5\u5176\u72b6\u6001\u3002<\/p>\n<pre><code>systemctl status mariadb\n<\/code><\/pre>\n<p>The output should be like:<br \/>\u8f93\u51fa\u5e94\u8be5\u662f\u8fd9\u6837\u7684\uff1a<\/p>\n<pre><code>\u25cf mariadb.service - MariaDB 10.3.29 database server\n     Loaded: loaded (\/lib\/systemd\/system\/mariadb.service; enabled; vendor preset: enabled)\n     Active: active (running) since Mon 2021-07-05 13:13:28 UTC; 18s ago\n       Docs: man:mysqld(8)\n             https:\/\/mariadb.com\/kb\/en\/library\/systemd\/\n   Main PID: 15247 (mysqld)\n     Status: \"Taking your SQL requests now...\"\n      Tasks: 31 (limit: 464250)\n     Memory: 66.3M\n     CGroup: \/system.slice\/mariadb.service\n             \u2514\u250015247 \/usr\/sbin\/mysqld\n<\/code><\/pre>\n<p>If the status shows enabled, it means MariaDB has started. But if not, you can<br \/>use this command<br \/>\u5982\u679c\u72b6\u6001\u663e\u793a\u5df2\u542f\u7528\uff0c\u5219\u8868\u793a MariaDB \u5df2\u542f\u52a8\u3002\u4f46\u5982\u679c\u6ca1\u6709\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u8fd9\u4e2a\u547d\u4ee4<\/p>\n<pre><code>\n\nsudo systemctl start mariadb\n<\/code><\/pre>\n<p>Just like Nginx, you can set MariaDB to auto-start at the boot time. Use this<br \/>command to auto-start MariaDB at boot time.<br \/>\u5c31\u50cf Nginx \u4e00\u6837\uff0c\u60a8\u53ef\u4ee5\u5c06 MariaDB \u8bbe\u7f6e\u4e3a\u5728\u542f\u52a8\u65f6\u81ea\u52a8\u542f\u52a8\u3002\u4f7f\u7528\u6b64\u547d\u4ee4\u5728\u542f\u52a8\u65f6\u81ea\u52a8\u542f\u52a8 MariaDB\u3002<\/p>\n<pre><code>\nsudo systemctl enable mariadb\n<\/code><\/pre>\n<p>Next, you need to run the post installation security script<br \/>\u63a5\u4e0b\u6765\uff0c\u60a8\u9700\u8981\u8fd0\u884c\u5b89\u88c5\u540e\u5b89\u5168\u811a\u672c<\/p>\n<pre><code>sudo mysql_secure_installation\n<\/code><\/pre>\n<p>When asked about MariaDB root password, simply press Enter as there is no root<br \/>password.<br \/>\u5f53\u8be2\u95ee MariaDB root \u5bc6\u7801\u65f6\uff0c\u53ea\u9700\u6309 Enter\uff0c\u56e0\u4e3a\u6ca1\u6709 root \u5bc6\u7801\u3002<\/p>\n<p>Now press Y to set the new root password and re-enter the password.<br \/>\u73b0\u5728\u6309 Y \u8bbe\u7f6e\u65b0\u7684 root \u5bc6\u7801\u5e76\u91cd\u65b0\u8f93\u5165\u5bc6\u7801\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/i1.wp.com\/www.skysilk.com\/blog\/wp-content\/uploads\/2021\/07\/image-1.jpeg\" alt=\"\" title=\"\"><\/p>\n<p>Now press enter for all the other questions. This includes removing anonymous<br \/>users,disabling root login remotely, removing test databases & its access, and<br \/>reloading privilege tables.<br \/>\u73b0\u5728\u6309\u56de\u8f66\u952e\u56de\u7b54\u6240\u6709\u5176\u4ed6\u95ee\u9898\u3002\u8fd9\u5305\u62ec\u5220\u9664\u533f\u540d\u7528\u6237\u3001\u8fdc\u7a0b\u7981\u7528 root \u767b\u5f55\u3001\u5220\u9664\u6d4b\u8bd5\u6570\u636e\u5e93\u53ca\u5176\u8bbf\u95ee\u6743\u9650\u4ee5\u53ca\u91cd\u65b0\u52a0\u8f7d\u6743\u9650\u8868\u3002<\/p>\n<p>After completion of these steps, MariaDB installation is secured.<br \/>\u5b8c\u6210\u8fd9\u4e9b\u6b65\u9aa4\u540e\uff0cMariaDB \u5b89\u88c5\u5c31\u5b89\u5168\u4e86\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/i2.wp.com\/www.skysilk.com\/blog\/wp-content\/uploads\/2021\/07\/image-2.jpeg\" alt=\"\" title=\"\"><\/p>\n<p>If you want to login MariaDB without root password, you can run the command<br \/>below:<br \/>\u5982\u679c\u60a8\u60f3\u5728\u6ca1\u6709root\u5bc6\u7801\u7684\u60c5\u51b5\u4e0b\u767b\u5f55MariaDB\uff0c\u60a8\u53ef\u4ee5\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>sudo mariadb -u root\n<\/code><\/pre>\n<p>To exit, simple enter<br \/>\u8981\u9000\u51fa\uff0c\u53ea\u9700\u8f93\u5165<\/p>\n<pre><code>exit;\n<\/code><\/pre>\n<p>To check MariaDB version, enter:<br \/>\u8981\u68c0\u67e5 MariaDB \u7248\u672c\uff0c\u8bf7\u8f93\u5165\uff1a<\/p>\n<pre><code>mariadb --version\n<\/code><\/pre>\n<p>So you could see that MariaDB 10.3.22 has been installed successfully.<br \/>\u53ef\u4ee5\u770b\u5230 MariaDB 10.3.22 \u5df2\u7ecf\u5b89\u88c5\u6210\u529f\u3002<\/p>\n<pre><code>mariadb  Ver 15.1 Distrib 10.3.29-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2\n<\/code><\/pre>\n<h3>Step 4: PHP 7.4 Installation \u5b89\u88c5<\/h3>\n<p>To install PHP 7.4 with some minor improvement over PHP 7.3, enter the<br \/>following command:<br \/>\u8981\u5b89\u88c5\u5bf9 PHP 7.3 \u7a0d\u6709\u6539\u8fdb\u7684 PHP 7.4\uff0c\u8bf7\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>sudo apt install php7.4 php7.4-fpm php7.4-mysql php-common php7.4-cli php7.4-common php7.4-json php7.4-opcache php7.4-readline php7.4-mbstring php7.4-xml php7.4-gd php7.4-curl\n<\/code><\/pre>\n<p>To ensure WordPress runs error free, install PHP extensions. Now use the<br \/>following command to to start PHP 7.4-fpm<br \/>\u4e3a\u786e\u4fdd WordPress \u65e0\u9519\u8bef\u8fd0\u884c\uff0c\u8bf7\u5b89\u88c5 PHP \u6269\u5c55\u3002\u73b0\u5728\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u542f\u52a8 PHP 7.4-fpm<\/p>\n<pre><code>sudo systemctl start php7.4-fpm\n<\/code><\/pre>\n<p>Just like you had run commands to auto-start Nginx and MariaDB, you can enable<br \/>auto-start PHP.<br \/>\u5c31\u50cf\u60a8\u8fd0\u884c\u547d\u4ee4\u6765\u81ea\u52a8\u542f\u52a8 Nginx \u548c MariaDB \u4e00\u6837\uff0c\u60a8\u53ef\u4ee5\u542f\u7528\u81ea\u52a8\u542f\u52a8 PHP\u3002<\/p>\n<pre><code>sudo systemctl enable php7.4-fpm\n<\/code><\/pre>\n<p>Now check the status of PHP<br \/>\u73b0\u5728\u68c0\u67e5PHP\u7684\u72b6\u6001<\/p>\n<pre><code>\n\nsystemctl status php7.4-fpm\n<\/code><\/pre>\n<p>The output should be like:<br \/>\u8f93\u51fa\u5e94\u8be5\u662f\u8fd9\u6837\u7684\uff1a<\/p>\n<pre><code>\u25cf php7.4-fpm.service - The PHP 7.4 FastCGI Process Manager\n     Loaded: loaded (\/lib\/systemd\/system\/php7.4-fpm.service; enabled; vendor preset: enabled)\n     Active: active (running) since Mon 2021-07-05 13:21:45 UTC; 45s ago\n       Docs: man:php-fpm7.4(8)\n   Main PID: 26650 (php-fpm7.4)\n     Status: \"Processes active: 0, idle: 2, Requests: 0, slow: 0, Traffic: 0req\/sec\"\n      Tasks: 3 (limit: 464250)\n     Memory: 9.4M\n     CGroup: \/system.slice\/php7.4-fpm.service\n             \u251c\u250026650 php-fpm: master process (\/etc\/php\/7.4\/fpm\/php-fpm.conf)\n             \u251c\u250026651 php-fpm: pool www\n             \u2514\u250026652 php-fpm: pool www\n<\/code><\/pre>\n<p>Press Q if the above command doesn\u2019t exit immediately.<br \/>\u5982\u679c\u4e0a\u8ff0\u547d\u4ee4\u6ca1\u6709\u7acb\u5373\u9000\u51fa\uff0c\u8bf7\u6309 Q\u3002<\/p>\n<h3>Step 5: Setting up Nginx Server Block \u8bbe\u7f6e Nginx \u670d\u52a1\u5668\u5757<\/h3>\n<p>The default server block cannot run PHP code so we create a Nginx server block<br \/>that acts like a virtual host in Apache. Run the following command to remove<br \/>the default symlink in sites-enabled directory.<br \/>\u9ed8\u8ba4\u670d\u52a1\u5668\u5757\u65e0\u6cd5\u8fd0\u884c PHP \u4ee3\u7801\uff0c\u56e0\u6b64\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2a Nginx \u670d\u52a1\u5668\u5757\uff0c\u5b83\u7684\u4f5c\u7528\u7c7b\u4f3c\u4e8e Apache \u4e2d\u7684\u865a\u62df\u4e3b\u673a\u3002\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u4ee5\u5220\u9664\u542f\u7528\u7ad9\u70b9\u7684\u76ee\u5f55\u4e2d\u7684\u9ed8\u8ba4\u7b26\u53f7\u94fe\u63a5\u3002<\/p>\n<pre><code>\nsudo rm \/etc\/nginx\/sites-enabled\/default\n<\/code><\/pre>\n<p>To create a new server block, use the following command:<br \/>\u8981\u521b\u5efa\u65b0\u7684\u670d\u52a1\u5668\u5757\uff0c\u8bf7\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>sudo nano \/etc\/nginx\/conf.d\/default.conf\n<\/code><\/pre>\n<p>Now paste the following text into the file to make Nginx listen on IPv4 port<br \/>80 and IPv6 port 80.<br \/>\u73b0\u5728\u5c06\u4ee5\u4e0b\u6587\u672c\u7c98\u8d34\u5230\u6587\u4ef6\u4e2d\uff0c\u4f7f Nginx \u4fa6\u542c IPv4 \u7aef\u53e3 80 \u548c IPv6 \u7aef\u53e3 80\u3002<\/p>\n<pre><code>server {\n  listen 80;\n  listen [::]:80;\n  server_name _;\n  root \/usr\/share\/nginx\/html\/;\n  index index.php index.html index.htm index.nginx-debian.html;\n\n  location \/ {\n    try_files $uri $uri\/ \/index.php;\n  }\n\n  location ~ .php$ {\n    fastcgi_pass unix:\/run\/php\/php7.4-fpm.sock;\n    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;\n    include fastcgi_params;\n    include snippets\/fastcgi-php.conf;\n  }\n\n # A long browser cache lifetime can speed up repeat visits to your page\n  location ~* .(jpg|jpeg|gif|png|webp|svg|woff|woff2|ttf|css|js|ico|xml)$ {\n       access_log        off;\n       log_not_found     off;\n       expires           360d;\n  }\n\n  # disable access to hidden files\n  location ~ \/.ht {\n      access_log off;\n      log_not_found off;\n      deny all;\n  }\n}\n\n<\/code><\/pre>\n<p>Save the file by Ctrl+x, type Y and enter to confirm. To close the file press<br \/>Ctrl+X.<br \/>\u6309Ctrl+x\u4fdd\u5b58\u6587\u4ef6\uff0c\u8f93\u5165Y\u5e76\u56de\u8f66\u786e\u8ba4\u3002\u8981\u5173\u95ed\u6587\u4ef6\uff0c\u8bf7\u6309 Ctrl+X\u3002<\/p>\n<p>Now test the Nginx configuration.<br \/>\u73b0\u5728\u6d4b\u8bd5 Nginx \u914d\u7f6e\u3002<\/p>\n<pre><code>sudo nginx -t\n<\/code><\/pre>\n<p>If the test is successful and your configuration files have proper syntax, it<br \/>will show you a prompt like this.<br \/>\u5982\u679c\u6d4b\u8bd5\u6210\u529f\u5e76\u4e14\u60a8\u7684\u914d\u7f6e\u6587\u4ef6\u5177\u6709\u6b63\u786e\u7684\u8bed\u6cd5\uff0c\u5b83\u5c06\u5411\u60a8\u663e\u793a\u8fd9\u6837\u7684\u63d0\u793a<\/p>\n<pre><code>nginx: the configuration file \/etc\/nginx\/nginx.conf syntax is ok\nnginx: configuration file \/etc\/nginx\/nginx.conf test is successful\n<\/code><\/pre>\n<p>Reload Nginx if the test is successful<br \/>\u5982\u679c\u6d4b\u8bd5\u6210\u529f\uff0c\u8bf7\u91cd\u65b0\u52a0\u8f7d Nginx<\/p>\n<pre><code>\n\nsudo systemctl reload nginx\n<\/code><\/pre>\n<h3>Step 5: Test PHP \u6d4b\u8bd5 PHP<\/h3>\n<p>Create info.php file in the webroot directory to start testing PHP-FPM with<br \/>Nginx web server.<br \/>\u5728 webroot \u76ee\u5f55\u4e2d\u521b\u5efa info.php \u6587\u4ef6\u4ee5\u5f00\u59cb\u4f7f\u7528 Nginx Web \u670d\u52a1\u5668\u6d4b\u8bd5 PHP-FPM\u3002<\/p>\n<pre><code>sudo nano \/usr\/share\/nginx\/html\/info.php\n<\/code><\/pre>\n<p>Now paste the below php code into the file<br \/>\u73b0\u5728\u5c06\u4e0b\u9762\u7684php\u4ee3\u7801\u7c98\u8d34\u5230\u6587\u4ef6\u4e2d<\/p>\n<pre><code>&lt;?php phpinfo(); ?&gt;\n<\/code><\/pre>\n<p>Close the file and open a new browser window. Then enter **server-ip-<br \/>address\/info.php** and replace server ip address with actual IP.<br \/>\u5173\u95ed\u6587\u4ef6\u5e76\u6253\u5f00\u4e00\u4e2a\u65b0\u7684\u6d4f\u89c8\u5668\u7a97\u53e3\u3002\u7136\u540e\u8f93\u5165server-ip-address\/info.php\u5e76\u5c06\u670d\u52a1\u5668 ip \u5730\u5740\u66ff\u6362\u4e3a\u5b9e\u9645 IP\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.skysilk.com\/blog\/wp-content\/uploads\/2021\/07\/image-3.jpeg\" alt=\"\" title=\"\"><\/p>\n<p>You can see the PHP information on your system.<br \/>\u60a8\u53ef\u4ee5\u5728\u7cfb\u7edf\u4e0a\u67e5\u770b PHP \u4fe1\u606f\u3002 <\/p>\n<p>So if you follow the steps mentioned in this tutorial, you can successfully<br \/>install Nginx, MariaDB, and PHP 7.4 on ubuntu 20.04.<br \/>\u56e0\u6b64\uff0c\u5982\u679c\u60a8\u6309\u7167\u672c\u6559\u7a0b\u4e2d\u63d0\u5230\u7684\u6b65\u9aa4\u64cd\u4f5c\uff0c\u60a8\u53ef\u4ee5\u5728 ubuntu 20.04 \u4e0a\u6210\u529f\u5b89\u88c5 Nginx\u3001MariaDB \u548c PHP 7.4\u3002<\/p>\n<p>Do not forget to delete the info.php file for server security. Deleting this<br \/>file prevents your file from getting hacked.<br \/>\u4e3a\u4e86\u670d\u52a1\u5668\u5b89\u5168\uff0c\u4e0d\u8981\u5fd8\u8bb0\u5220\u9664 info.php \u6587\u4ef6\u3002\u5220\u9664\u6b64\u6587\u4ef6\u53ef\u9632\u6b62\u60a8\u7684\u6587\u4ef6\u88ab\u9ed1\u5ba2\u5165\u4fb5\u3002<\/p>\n<pre><code>\nsudo rm \/usr\/share\/nginx\/html\/info.php\n<\/code><\/pre>\n<p>If at any time you find an error, you can check the Nginx error<br \/>log(\/var\/log\/nginx\/error.log). This would help you troubleshoot the issues<br \/>quite effectively.<br \/>\u5982\u679c\u4efb\u4f55\u65f6\u5019\u53d1\u73b0\u9519\u8bef\uff0c\u53ef\u4ee5\u67e5\u770b Nginx \u9519\u8bef\u65e5\u5fd7(\/var\/log\/nginx\/error.log)\u3002\u8fd9\u5c06\u5e2e\u52a9\u60a8\u975e\u5e38\u6709\u6548\u5730\u89e3\u51b3\u95ee\u9898\u3002<\/p>\n<h3>Nginx Auto-restart \u81ea\u52a8\u91cd\u542f<\/h3>\n<p>If the Nginx process breaks, you can run the following command:<br \/>\u5982\u679c Nginx \u8fdb\u7a0b\u4e2d\u65ad\uff0c\u60a8\u53ef\u4ee5\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>sudo systemctl restart nginx\n<\/code><\/pre>\n<p>You can alternatively restart Nginx automatically instead of manually typing<br \/>this command. Create a separate directory to override the default system<br \/>service.<br \/>\u60a8\u4e5f\u53ef\u4ee5\u81ea\u52a8\u91cd\u65b0\u542f\u52a8 Nginx\uff0c\u800c\u4e0d\u662f\u624b\u52a8\u8f93\u5165\u6b64\u547d\u4ee4\u3002\u521b\u5efa\u4e00\u4e2a\u5355\u72ec\u7684\u76ee\u5f55\u6765\u8986\u76d6\u9ed8\u8ba4\u7684\u7cfb\u7edf\u670d\u52a1\u3002<\/p>\n<pre><code>sudo mkdir -p \/etc\/systemd\/system\/nginx.service.d\/\n<\/code><\/pre>\n<p>Now create a file under the directory you just created.<br \/>\u73b0\u5728\u5728\u60a8\u521a\u521a\u521b\u5efa\u7684\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a\u6587\u4ef6\u3002<\/p>\n<pre><code>\n\nsudo nano \/etc\/systemd\/system\/nginx.service.d\/restart.conf\n<\/code><\/pre>\n<p>By adding the following command lines, Nginx will restart automatically If a<br \/>failure is detected. The default value is 100ms which is too small, so change<br \/>it to 5 seconds.<br \/>\u901a\u8fc7\u6dfb\u52a0\u4ee5\u4e0b\u547d\u4ee4\u884c\uff0cNginx \u4f1a\u5728\u68c0\u6d4b\u5230\u6545\u969c\u65f6\u81ea\u52a8\u91cd\u542f\u3002\u9ed8\u8ba4\u503c\u662f 100ms \u592a\u5c0f\u4e86\uff0c\u6240\u4ee5\u628a\u5b83\u6539\u6210 5 \u79d2\u3002<\/p>\n<pre><code>\n[Service]\nRestart=always\nRestartSec=5s\n<\/code><\/pre>\n<p>For changes to take effect, reload the system after closing the file.<br \/>\u8981\u4f7f\u66f4\u6539\u751f\u6548\uff0c\u8bf7\u5728\u5173\u95ed\u6587\u4ef6\u540e\u91cd\u65b0\u52a0\u8f7d\u7cfb\u7edf<\/p>\n<pre><code>sudo systemctl daemon-reload\n<\/code><\/pre>\n<p>Kill Nginx and check it with the following command:<br \/>\u6740\u6b7b Nginx \u5e76\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u68c0\u67e5\u5b83\uff1a<\/p>\n<pre><code>\nsudo pkill nginx\n<\/code><\/pre>\n<p>Now check the Nginx status<br \/>\u73b0\u5728\u68c0\u67e5 Nginx \u72b6\u6001<\/p>\n<pre><code>\nsystemctl status nginx\n<\/code><\/pre>\n<h2>Conclusion \u7ed3\u8bba<\/h2>\n<p>After following the steps in this tutorial, you can install LEMP stack on<br \/><a href=\"https:\/\/www.skysilk.com\/ubuntu\/\">Ubuntu<\/a> 20.04 successfully. You can use LEMP<br \/>stack to host multiple websites on a VPS server by simply creating multiple<br \/>server blocks.<br \/>\u6309\u7167\u672c\u6559\u7a0b\u4e2d\u7684\u6b65\u9aa4\u64cd\u4f5c\u540e\uff0c\u60a8\u53ef\u4ee5\u5728Ubuntu 20.04 \u4e0a\u6210\u529f\u5b89\u88c5 LEMP \u5806\u6808\u3002\u60a8\u53ef\u4ee5\u901a\u8fc7\u7b80\u5355\u5730\u521b\u5efa\u591a\u4e2a\u670d\u52a1\u5668\u5757\uff0c\u4f7f\u7528 LEMP \u5806\u6808\u5728 VPS \u670d\u52a1\u5668\u4e0a\u6258\u7ba1\u591a\u4e2a\u7f51\u7ad9\u3002<\/p>\n<p><strong>About the author<\/strong> : <a href=\"https:\/\/vashishthakapoor.com\/\"><em>Vashishtha Kapoor<\/em><\/a><br \/>is a Web Hosting Expert and has over 5 years of experience in SEO, PPC,<br \/>Website Management and WordPress development. Vashishtha writes about<br \/>WordPress customizations, web design, server administration and ad-tech topics<br \/>\u5173\u4e8e\u4f5c\u8005\uff1a  Vashishtha Kapoor \u662f\u4e00\u540d\u865a\u62df\u4e3b\u673a\u4e13\u5bb6\uff0c\u5728 SEO\u3001PPC\u3001\u7f51\u7ad9\u7ba1\u7406\u548c WordPress \u5f00\u53d1\u65b9\u9762\u62e5\u6709\u8d85\u8fc7 5 \u5e74\u7684\u7ecf\u9a8c\u3002Vashishtha \u64b0\u5199\u6709\u5173 WordPress \u81ea\u5b9a\u4e49\u3001\u7f51\u9875\u8bbe\u8ba1\u3001\u670d\u52a1\u5668\u7ba1\u7406\u548c\u5e7f\u544a\u6280\u672f\u4e3b\u9898\u7684\u6587\u7ae0<\/p>\n","protected":false},"excerpt":{"rendered":"<p>What is LEMP Stack? How to set up on Ubuntu 20.04  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[23,30],"class_list":["post-599","post","type-post","status-publish","format-standard","hentry","category-linux","tag-linux","tag-web"],"_links":{"self":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts\/599","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/comments?post=599"}],"version-history":[{"count":0,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts\/599\/revisions"}],"wp:attachment":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/media?parent=599"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/categories?post=599"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/tags?post=599"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}