centos7 php7+nginx服务器配置

nginx安装:

1 yum update
2 yum install nginx
3 systemctl start nginx
4 systemctl enable nginx

MariaDB安装:

  • 添加源
1 vi /etc/yum.repos.d/MariaDB.repo
2 
3 [mariadb]
4 name = MariaDB
5 baseurl = http://yum.mariadb.org/10.1/centos7-amd64
6 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
7 gpgcheck=1
  • 安装数据库并设置
1 yum install MariaDB-server MariaDB-client
2 systemctl start mariadb  
3 mysql_secure_installation
4 systemctl enable mariadb

php7的安装:

  • 安装指定版本方式

  输入一下命令进行指定php版本安装  

1 rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
2 yum install php70w

  注:此处安装的是php7.0,如果安装php7.1,将 yum install php70w 修改为 yum install php71w 即可

  • 安装默认php
1 yum install php
  • 安装你需要的php模块:
1 yum install php70w-xml php70w-soap php70w-xmlrpc php70w-mbstring php70w-json php70w-gd php70w-mcrypt php70w-mysql php70w-intl php70w-tidy php-pecl-mongodb php70w-fpm php70w-devel php70w-pear php70w-pecl-apcu php70w-opcache
  • 修改php.ini
1 vi /etc/php.ini
2 cgi.fix_pathinfo=1 --> cgi.fix_pathinfo=0
  • 修改php-fpm的www.conf文件
 1 vi /etc/php-fpm.d/www.conf
 2 
 3 1. 
 4 listen = /var/run/php-fpm/php-fpm.sock
 5 2. 
 6 listen.owner = nginx
 7 listen.group = nginx
 8 3. 
 9 user = nginx
10 group = nginx
  • 开启php-fpm
1 systemctl start php-fpm
2 systemctl enable php-fpm

修改nginx的配置文件:

 1 vi /etc/nginx/conf.d/default.conf
 2 server {
 3     listen       80;
 4     server_name  localhost;
 5 
 6     # note that these lines are originally from the "location /" block
 7     root   /usr/share/nginx/html;
 8     index index.php index.html index.htm;
 9 
10     location / {
11         try_files $uri $uri/ =404;
12     }
13     error_page 404 /404.html;
14     error_page 500 502 503 504 /50x.html;
15     location = /50x.html {
16         root /usr/share/nginx/html;
17     }
18 
19     location ~ \.php$ {
20         try_files $uri =404;
21         fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
22         fastcgi_index index.php;
23         fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
24         include fastcgi_params;
25     }
26 }

如果出现了“502 Bad”页面,请更改目录权限:

1 chown nginx:nginx /var/run/php-fpm/php-fpm.sock
2 chown nginx:nginx -R /usr/share/nginx/html

 检测:

在网站目录下,输入info.php,输入如下代码,查看页面的返回

1 <?php
2 phpinfo();

 

转载于:https://www.cnblogs.com/steven1995/p/9723248.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值