centos7 安装 (ღ˘⌣˘ღ)lnmp 环境

本贴最后更新于 1922 天前,其中的信息可能已经事过景迁

这次安装 centos7 安装环境遇到的问题差不多,就是 nginx 配置文件出错 nginx 没有与 php 链接默认的配置文件如果只是把 php 配置的那段注释去掉不能生效。

0x01 安装 yum 源

yum install wget
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
rpm -ivh mysql-community-release-el7-5.noarch.rpm
wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
rpm -ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

0x02 安装软件

 yum install -y  mysql-server
 yum install -y nginx
 yum install -y php70w php70w-fpm php70w-mysql.x86_64
 

0x03 修改 nginx 与 php-frp 配置文件

1 修改 /etc/nginx/conf.d/default.conf 去除对 IPv6 地址的监听,可参考下面的代码示例:

示例代码:vi /etc/nginx/conf.d/default.conf

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 {
    }

}

2 在 /etc/nginx/conf.d 目录中新建一个名为 php.conf 的文件,并配置 Nginx 端口 ,配置示例如下:

示例代码:vi /etc/nginx/conf.d/php.conf

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

ps:注意路径哦

3 修改 php-fpm 配置文件

php-fpm 配置文件位置:(/etc/php-fpm.d/www.conf)

示例代码:vi /etc/php-fpm.d/www.conf

user =apache ->nginx
​group=apache ->nginx

修改后 注意一下空格

user= nginx
​group= nginx

0x04 启动服务并开机自启

systemctl restart mysql.service
systemctl restart nginx.service
systemctl restart php-fpm.service

 systemctl enable mysqld.service
 systemctl enable nginx.service
 systemctl enable php-fpm.service

0x05 测试

这时候,我们就可以在/usr/share/php 目录下新建一个 info.php 文件来检查 php 是否安装成功了,文件内容参考如下:
示例代码:vi /usr/share/php/info.php

mkdir /usr/share/php
vi /usr/share/php/info.php  

<?php phpinfo(); ?>


  • CentOS

    CentOS(Community Enterprise Operating System)是 Linux 发行版之一,它是来自于 Red Hat Enterprise Linux 依照开放源代码规定释出的源代码所编译而成。由于出自同样的源代码,因此有些要求高度稳定的服务器以 CentOS 替代商业版的 Red Hat Enterprise Linux 使用。两者的不同在于 CentOS 并不包含封闭源代码软件。

    238 引用 • 224 回帖 • 1 关注
  • lnmp
    8 引用 • 18 回帖

相关帖子

欢迎来到这里!

我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。

注册 关于
请输入回帖内容 ...