手工搭建LNMP平台

[root@hecs-x-medium-2-linux-20200619090653 html]# yum install -y nginx mysql-server php php-fpm
Last metadata expiration check: 1:05:55 ago on Wed 10 Feb 2021 11:26:44 AM CST.
Package nginx-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_64 is already installed.
Package mysql-server-8.0.21-1.module_el8.2.0+493+63b41e36.x86_64 is already installed.
Package php-7.2.24-1.module_el8.2.0+313+b04d0a66.x86_64 is already installed.
Package php-fpm-7.2.24-1.module_el8.2.0+313+b04d0a66.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!

[root@hecs-x-medium-2-linux-20200619090653 html]# mysql_secure_installation

Securing the MySQL server deployment.

Enter password for user root:

[root@hecs-x-medium-2-linux-20200619090653 html]# systemctl start nginx mysqld php-fpm

[root@hecs-x-medium-2-linux-20200619090653 html]# systemctl enable nginx mysqld php-fpm
[root@hecs-x-medium-2-linux-20200619090653 html]# systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
Drop-In: /usr/lib/systemd/system/nginx.service.d
└─php-fpm.conf
Active: active (running) since Wed 2021-02-10 11:59:43 CST; 33min ago
Main PID: 10097 (nginx)
Tasks: 2 (limit: 11434)
Memory: 7.9M
CGroup: /system.slice/nginx.service
├─10097 nginx: master process /usr/sbin/nginx
└─10098 nginx: worker process

Feb 10 11:59:43 hecs-x-medium-2-linux-20200619090653 systemd[1]: nginx.service: Succeeded.
Feb 10 11:59:43 hecs-x-medium-2-linux-20200619090653 systemd[1]: Stopped The nginx HTTP and reverse proxy server.
Feb 10 11:59:43 hecs-x-medium-2-linux-20200619090653 systemd[1]: Starting The nginx HTTP and reverse proxy server...
Feb 10 11:59:43 hecs-x-medium-2-linux-20200619090653 nginx[10093]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Feb 10 11:59:43 hecs-x-medium-2-linux-20200619090653 nginx[10093]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Feb 10 11:59:43 hecs-x-medium-2-linux-20200619090653 systemd[1]: nginx.service: Failed to parse PID from file /run/nginx.pid: Invalid argument
Feb 10 11:59:43 hecs-x-medium-2-linux-20200619090653 systemd[1]: Started The nginx HTTP and reverse proxy server.
[root@hecs-x-medium-2-linux-20200619090653 html]# systemctl status mysqld
● mysqld.service - MySQL 8.0 database server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Wed 2021-02-10 11:34:42 CST; 59min ago
Main PID: 9072 (mysqld)
Status: "Server is operational"
Tasks: 40 (limit: 11434)
Memory: 420.8M
CGroup: /system.slice/mysqld.service
└─9072 /usr/libexec/mysqld --basedir=/usr

Feb 10 11:34:35 hecs-x-medium-2-linux-20200619090653 systemd[1]: Starting MySQL 8.0 database server...
Feb 10 11:34:35 hecs-x-medium-2-linux-20200619090653 mysql-prepare-db-dir[8990]: Initializing MySQL database
Feb 10 11:34:42 hecs-x-medium-2-linux-20200619090653 systemd[1]: Started MySQL 8.0 database server.
[root@hecs-x-medium-2-linux-20200619090653 html]# systemctl status php-fpm
● php-fpm.service - The PHP FastCGI Process Manager
Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; enabled; vendor preset: disabled)
Active: active (running) since Wed 2021-02-10 11:44:53 CST; 49min ago
Main PID: 9849 (php-fpm)
Status: "Processes active: 0, idle: 5, Requests: 3, slow: 0, Traffic: 0req/sec"
Tasks: 6 (limit: 11434)
Memory: 20.2M
CGroup: /system.slice/php-fpm.service
├─9849 php-fpm: master process (/etc/php-fpm.conf)
├─9850 php-fpm: pool www
├─9851 php-fpm: pool www
├─9852 php-fpm: pool www
├─9853 php-fpm: pool www
└─9854 php-fpm: pool www

Feb 10 11:44:53 hecs-x-medium-2-linux-20200619090653 systemd[1]: Starting The PHP FastCGI Process Manager...
Feb 10 11:44:53 hecs-x-medium-2-linux-20200619090653 systemd[1]: Started The PHP FastCGI Process Manager.

修改Nginx配置文件以支持PHP。

  1. 执行以下命令打开配置文件“default.conf”。

    vim /etc/nginx/conf.d/default.conf

  2. i键进入编辑模式。
  3. 修改打开的“default.conf”文件。
    • 在所支持的主页面格式中添加php格式的主页,如下所示:
          location / {
              root   /usr/share/nginx/html;
              index index.php index.html index.htm;
          }
       
    • 取消如下内容的注释,并设置字体加粗部分为Nginx的默认路径,如下图所示:
          location ~ \.php$ {
              root           html;
              fastcgi_pass   127.0.0.1:9000;
              fastcgi_index  index.php;
              fastcgi_param  SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
              include        fastcgi_params;
          }
       
  4. Esc键退出编辑模式,并输入:wq保存后退出。

浏览器访问测试。

 

  1. 在/usr/share/nginx/html目录下创建“info.php”的测试页面。
    1. 执行以下命令创建并打开“info.php”的测试文件。

      vim /usr/share/nginx/html/info.php

    2. i键进入编辑模式。
    3. 修改打开的“info.php”文件,将如下内容写入文件。
      <?php
       phpinfo();
      ?>
       
    4. Esc键退出编辑模式,并输入:wq保存后退出。

 

posted @   无边无忌  阅读(97)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 通过 API 将Deepseek响应流式内容输出到前端
· 因为Apifox不支持离线,我果断选择了Apipost!
点击右上角即可分享
微信分享提示