Linx+Nginx+Mysql+PHP

1. 前置需求

​ 安装 Nginx

sudo yum install nginx -y

​ 修改 /etc/nginx/conf.d/default.conf ,去除对 IPv6 地址的监听,

server {
    listen       80 default_server;
    # listen       [::]:80 default_server;
    server_name  _;
    root         /usr/share/nginx/html;

    # Load configuration files for the default server block.
    include /etc/nginx/default.d/*.conf;

    location / {
    }

    error_page 404 /404.html;
        location = /40x.html {
    }

    error_page 500 502 503 504 /50x.html;
        location = /50x.html {
    }

}

​ 启动 Nginx ,访问公网IP,是否成功,

systemctl start nginx
2. 安装MySQL数据库服务

​ 安装 MySql,并启动:

sudo yum install mysql-server -y
service mysqld restart

​ 设置 MySQL 账户和密码,并将 MySQL 设置为开机自动启动:

chkconfig mysqld on
3. 搭建PHP环境

​ 安装 PHP ,并启动 PHP-FPM 进程:

sudo yum install php php-fpm php-mysql -y
service php-fpm start

​ 启动之后,可以使用下面的命令查看 PHP-FPM 进程监听哪个端口(默认9000),并把 PHP-FPM 设置成开机自动启动:

netstat -nlpt | grep php-fpm
chlconfig php-fpm on
4. 配置 Nginx 并运行 PHP 程序

​ 在 /etc/nginx/conf.d 目录中新建一个名为 php.conf 的文件,配置 nginx ,并重启:

server {
    listen 8000;
    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    location ~ .php$ {
        root           /usr/share/php;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}
service nginx restart

​ 在 /usr/share/php 目录下,新建一个 info.php 文件,来检查 php 是否安装成功:

<?php phpinfo(); ?>

Linx+Nginx+Mysql+PHP
https://everysunday.github.io/2022/02/16/LNMP/
作者
T-River
发布于
2022年2月16日
许可协议