Table of Contents

  1. 系统
  2. 安装
    1. php
    2. MySQL
    3. Nginx
  3. 配置
    1. php
    2. MySQL
    3. Nginx

系统

  1. VirtualBox 6.0.0
  2. centOS 7 Minimal 64位
  3. php 7.1.24
  4. MySQL community server 8.0.13
  5. Nginx 1.14.2

安装

php

# 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
# yum install php71w php71w-cli php71w-common php71w-devel php71w-embedded php71w-fpm php71w-gd php71w-mbstring php71w-mysqlnd php71w-opcache php71w-pdo php71w-xml
# systemctl start php-fpm

MySQL

方法地址https://dev.mysql.com/doc/mysql-yum-repo-quick-guide/en/

# yum localinstall https://repo.mysql.com/mysql80-community-release-el7-1.noarch.rpm
# yum install mysql-community-server
# systemctl enable mysqld
# systemctl start mysqld

root初始密码

# grep 'temporary password' /var/log/mysqld.log

Nginx

# yum localinstall http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
# yum install -y nginx
# systemctl enable nginx.service
# systemctl start nginx.service

配置

php

  1. 配置/etc/php.ini文件
    添加cgi.fix_pathinfo=0
    原因http://www.laruence.com/2010/05/20/1495.html

  2. 配置/etc/php-fpm.d/www.conf

    user  = nginx
    group = nginx
    
  3. 重启服务

    # systemctl restart php-fpm
    

MySQL

编辑配置文件/etc/my.cnf
若有skip-grant-tables,需要将其注释掉

Nginx

  1. 配置/etc/nginx/conf.d/default.conf

    server {
         listen       80;
         server_name  test.web.com;
    
         charset utf8;
    
         location / {
             root   /var/www/html;
             index  index.php index.html index.htm;
         }
    
         error_page  404              /404.html;
         error_page   500 502 503 504  /50x.html;
    
         location = /50x.html {
             root   /usr/share/nginx/html;
         }
    
         location ~ \.php$ {
             root           html;
             fastcgi_pass   127.0.0.1:9000;
             fastcgi_index  index.php;
             fastcgi_param  SCRIPT_FILENAME  /var/www/html/$fastcgi_script_name;
             include        fastcgi_params;
         }
        }
    
  2. 防火墙开放80端口

    # firewall-cmd --zone=public --add-port=80/tcp --permanent
    # systemctl stop firewalld.service
    # systemctl start firewalld.service
    
  3. 测试nginx和php

    • 添加/var/www/html/index.html

      <h1>
          <span> hello, world. </span>
      </h1>
      
    • 添加/var/www/html/phpinfo.php

      <?php phpinfo(); ?>
      
    • 访问index.html
      在浏览器中打开http://ip/, 若出现“hello, world.”则成功

    • 访问phpinfo.php
      在浏览器中打开http://ip/phpinfo.php, 若出现php信息则成功

 posted on 2018-12-30 16:49  eat&die  阅读(116)  评论(0编辑  收藏  举报