MENU

搭建LNMP环境

January 26, 2018 • Read: 3913 • 环境搭建

1.搭建 Nginx 静态服务器

安装 Nginx
使用 yum 安装 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

此时,可访问实验机器外网 HTTP 服务(http://123.207.14.179)来确认是否已经安装成功。
将 Nginx 设置为开机自动启动:

chkconfig nginx on

2.安装 MySQL 数据库服务

安装 MySQL
使用 yum 安装 MySQL:

yum install mysql-server -y

安装完成后,启动 MySQL 服务:

service mysqld restart

设置 MySQL 账户 root 密码:

/usr/bin/mysqladmin -u root password 'Km5eIW7Q'

将 MySQL 设置为开机自动启动:

chkconfig mysqld on

3.搭建 PHP 环境

安装 PHP
使用 yum 安装 PHP:

> yum install php php-fpm php-mysql -y

安装之后,启动 PHP-FPM 进程:

service php-fpm start

启动之后,可以使用下面的命令查看 PHP-FPM 进程监听哪个端口

netstat -nlpt | grep php-fpm

把 PHP-FPM 也设置成开机自动启动:

chkconfig php-fpm on

此时,访问 http://IP:8000/info.php 可浏览刚刚创建的 info.php 页面

兼总条贯 知至知终

最后编辑于: January 4, 2019