Centos7 安装PHP7+Nginx+MariaDB+HTT

2018-11-05  本文已影响0人  w_w_wei
rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/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
yum install -y git

Nginx

yum install nginx
nginx -t
nginx

PHP7

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 php71w-geoip php71w-mcrypt php71w-pecl-redis php71w-pecl-xdebug php71w-pecl-geoip
php-fpm -t
php-fpm

Nginx + PHP

user nobody nobody;  ### `user-1`, this is the user run nginx woker process
...
include servers/*.conf;
server {
    listen       80;
    server_name  wwww.safecode.cc;


    root   /usr/share/nginx/html;
    location / {
        index  index.html index.htm index.php;
    }

    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    location ~* \.php$ {
        fastcgi_pass   unix:/run/php-fpm/fpm-www.sock;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

    location ~ /\.ht {
        deny  all;
    }
}
[www]
user = apache  ### `user-2`, this is the user run php-fpm pool process
user = apache

;listen = 127.0.0.1:9000  # tcp socket
listen = /var/run/php-fpm/fpm-www.sock  # unix socket

listen.onwer = nobody  ### `user-3`, this is the user for unix socket, like /var/run/php-fpm/fpm-www.sock
listen.group = nobody  # for tcp socket, these lines can be commented
listen.mode = 0660
systemctl restart php-fpm
nginx -s reload
echo "<?php phpinfo();" > /usr/share/nginx/html/info.php
image.png

MariaDb

安装

yum -y install mariadb mariadb-server
systemctl enable mariadb
systemctl start mariadb
mysql_secure_installation

编码设置为UTF-8

[mysqld]
init_connect='SET collation_connection = utf8_unicode_ci' 
init_connect='SET NAMES utf8' 
character-set-server=utf8 
collation-server=utf8_unicode_ci 
skip-character-set-client-handshake
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
lower_case_table_names=1 

重启

systemctl restart mariadb

Let's encrypt

证书生成

cd /var/www/
export WEBROOT=/usr/share/nginx/html
export DOMAIN=www.safecode.cc
export EMAIL=kerwin@qq.com
git clone https://github.com/letsencrypt/letsencrypt
cd letsencrypt
chmod +x letsencrypt-auto
./letsencrypt-auto certonly -a webroot --webroot-path=$WEBROOT --email $EMAIL -d $DOMAIN -d $DOMAIN

Nginx 添加https

server {
    listen  80;
    server_name www.safecode.cc;
    rewrite ^(.*)$  https://$host$1 permanent;
}
server {
        listen 443 ssl;
        ssl on;
        ssl_certificate /etc/letsencrypt/live/www.safecode.cc/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/www.safecode.cc/privkey.pem;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;
        ssl_ciphers AES256+EECDH:AES256+EDH:!aNULL;

        server_name www.safecode.cc;
        index index.html index.htm index.php default.html default.htm default.php;
        root /usr/share/nginx/html;

        location ~* \.php$ {
            fastcgi_pass   unix:/run/php-fpm/fpm-www.sock;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

}
nginx -s reload

问题

  1. nginx: [error] invalid PID number "" in "/var/run/nginx.pid"
pkill -9 nginx
nginx -c /etc/nginx/nginx.conf
  1. File not found
# 检查SCRIPT_FILENAME是否是/script
fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
#检查根目录权限
上一篇下一篇

猜你喜欢

热点阅读