CentOS+Nginx+php7+typecho +MySQL 博客搭建踩坑
in Linux with 0 comment

CentOS+Nginx+php7+typecho +MySQL 博客搭建踩坑

in Linux with 0 comment

搭建笔记

安装 nginx

$ yum -y install nginx

安装php7

$ yum remove php* php-common

rpm 安装 Php7 相应的 yum源:

$ rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
$ rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

yum 安装php7 及相应组建

$ yum install php70w php70w-opcache php70w-fpm

检查php版本

$ php -v

PHP 7.0.19 (cli) (built: May 12 2017 21:01:27) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.0.19, Copyright (c) 1999-2017, by Zend Technologies


配置nginx.conf

$ Whereis nginx

vi /etc/nginx/nginx.conf

typecho官方推荐配置如下:

server {
        listen          80;
        server_name     yourdomain.com;
        root            /home/yourdomain/www/;
        index           index.html index.htm index.php;
 
        if (!-e $request_filename) {
            rewrite ^(.*)$ /index.php$1 last;
        }
 
        location ~ .*\.php(\/.*)*$ {
            include fastcgi.conf;
            fastcgi_pass  127.0.0.1:9000;
        }
 
        access_log logs/yourdomain.log combined;
    }

###启动nginx

$ pa -aux | grep nginx

$ kill nginx-pidkill 9588

$ /usr/sbin/nginx || service nginx start || systemctl start nginx

启动php-fpm

$ service php-fpm start

几个注意点


安装博客程序

$ yum search php70W | grep mysql

Repository epel is listed more than once in the configuration
php70w-mysql.x86_64 : A module for PHP applications that use MySQL databases
php70w-mysqlnd.x86_64 : A module for PHP applications that use MySQL databases

$ yum install php70w.x86_64

后续

Nginx服务器无法登录后台,点击前台链接或者后台登录时出现"404, not found"
一般的出现这种情况时,nginx.conf里的的location设置都是类似这样 location ~ .*\.php$
要支持pathinfo,要改成 location ~ .*\.php(\/.*)*$
在某些老版本的php里面,可能还要打开php.ini里的cgi.fix_pathinfo cgi.fix_pathinfo = 1

添加rewite规则
fastcgi_split_path_info ^(.+?\.php)(/.*)$;

关于安装mysql

*下载mysql的repo源

$ wget http://repo.mysql.com//mysql57-community-release-el7-7.noarch.rpm

rpm -Uvh mysql57-community-release-el7-7.noarch.rpm

$ yum install mysql-server

*启动/重启mysql

$ service myself start/restart

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

$ set password for root@localhost = password('123');

$ flushprivilege;
timg.jpeg

Responses