原文链接: http://www.kylin-ux.com/2017/04/23/linux-ops-centos7安装nginx-php-mysql-mariadb

本文以安装禅道为例

下载禅道并解压缩

1
2
curl -O http://dl.cnezsoft.com/zentao/9.1.2/ZenTaoPMS.9.1.2.zip
sudo unzip ZenTaoPMS.9.1.2.zip -d /opt

web根目录为/opt/zentaopms/www
配置nginx时会用到, 即root /opt/zentaopms/www
minimal版需要安装unzip, sudo yum install unzip

安装nginx

CentOS7系统, 需要安装epel, 才能使用yum安装nginx

下载epel

1
2
curl -O https://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-9.noarch.rpm
sudo rpm -ivh ./epel-release-7-9.noarch.rpm

安装nginx

1
sudo yum install nginx

安装数据库

安装mariadb

1
sudo yum install mariadb-server

或者, 安装mysql
卸载mariadb-libs

1
sudo rpm -e mariadb-libs --nodeps

安装mysql

1
sudo rpm -ivh mysql-community-client-5.7.17-1.el7.x86_64.rpm mysql-community-common-5.7.17-1.el7.x86_64.rpm mysql-community-libs-5.7.17-1.el7.x86_64.rpm mysql-community-server-5.7.17-1.el7.x86_64.rpm

mysql-community-* 请自行下载, 网址https://dev.mysql.com/downloads/mysql/
minimal版需要安装net-tools, sudo yum install net-tools

安装php-fpm

1
sudo yum install php-fpm

安装php-mysqlnd

1
sudo yum install php-mysqlnd

配置nginx

修改/etc/nginx/nginx.conf

  • server节点中root /usr/share/nginx/html;修改为root /opt/zentaopms/www;
  • server节点中root下一行添加index index.php
  • server节点添加如下配置

    1
    2
    3
    4
    5
    6
    7
    location ~ \.php$ {
    root /opt/zentaopms/www;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    }
  • 配置完成后, grep输出

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    grep "location ~ \\\.php" /etc/nginx/nginx.conf -A8 -B5
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
    }
    location ~ \.php$ {
    root /opt/zentaopms/www;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    }
    }

php相关配置内容记不住也没关系 grep php /etc/nginx/ -R

值都是从哪儿来的呢?
fastcgi_pass

1
grep listen /etc/php-fpm.d/www.conf | grep -v ';'

fastcgi_param
/etc/nginx/fastcgi_params.default文件里找去

提示
xxx的配置信息通常在xxx.d/目录
看一下/etc/php-fpm.confinclude=xxx就明白了

启动

1
2
3
sudo systemctl start mysqld
sudo systemctl start php-fpm
sudo systemctl start nginx

设置开机启动

1
2
3
sudo systemctl enable mysqld
sudo systemctl enable php-fpm
sudo systemctl enable nginx

其他操作-禅道要求

1
2
3
4
sudo chmod o=rwx -R /opt/zentaopms/tmp/
sudo chmod o=rwx -R /opt/zentaopms/www/data
sudo mkdir -p /var/lib/php/session
sudo chmod o=rwx -R /var/lib/php/session

SELinux

由于SELinux引起的问题, 可通过sealert分析解决

1
2
3
sudo yum install setroubleshoot
sealert -a /var/log/audit/audit.log > tmp.txt
cat tmp.txt

粗暴一点, 直接

1
sudo setenforce 0

常见问题

Q1. 403 Forbidden
/var/log/nginx/error.log
“index.html” is forbidden (13: Permission denied)
index of “/opt/zentaopms/www/“ is forbidden

A1:
nginx.conf中添加index index.php
chmod 755 /opt

Q2. Access denied.
/var/log/nginx/error.log FastCGI sent in stderr: “Unable to open primary script: index.php (Permission denied)” while reading response header from upstream
Starting nginx: nginx: [emerg] bind() to 0.0.0.0:8086 failed (13: Permission denied)

A2:
sudo setenforce 0