LNMP环境搭建

2020-06-06  本文已影响0人  狂暴小绵羊
安装配置nginx

安装nginx 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 nginx

设置为开机自启动 chkconfig nginx on

安装 MySQL 数据库服务

安装mysql yum install mysql-server -y

启动mysql service mysqld restart

设置mysql账户和密码 /usr/bin/mysqladmin -u root password 'S713eqKI'

设置为开机自启动 chkconfig mysqld on

安装php

安装php yum install php php-fpm php-mysql -y

启动 PHP-FPM 进程 service php-fpm start

查看 PHP-FPM 进程监听哪个端口 netstat -nlpt | grep php-fpm

设置为开机自启动 chkconfig php-fpm on

配置 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;
    }
}

重启nginx service nginx restart

这时候,我们就可以在/usr/share/php 目录下新建一个 info.php 文件来检查 php 是否安装成功了

<?php phpinfo(); ?>

完成后通过 php.conf中配置的8000端口访问

上一篇 下一篇

猜你喜欢

热点阅读