0%

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

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

0x01安装yum源

1
2
3
4
5
6
7
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安装软件

1
2
3
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 地址的监听,可参考下面的代码示例:

示例代码:

/etc/nginx/conf.d/default.conf```
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
```
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 端口 ,配置示例如下:

示例代码:

/etc/nginx/conf.d/php.conf```
1
2
3
4
5
6
7
8
9
10
11
12
```
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)

示例代码:

/etc/php-fpm.d/www.conf```
1
2
3
```
user =apache ->nginx
​group=apache ->nginx

修改后

1
2
3
```
user= nginx
​group= nginx

0x04 启动服务并开机自启

1
2
3
4
5
6
7
systemctl restart mysql.service
systemctl restart nginx.service
systemctl restart php-fpm.service

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

0x05测试

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

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

<?php phpinfo(); ?>