Alex的博客

本博客的文章均为原创,是本人从事行业多年来所遇见一些小问题的解决心得,希望可以帮助到大家!



centos6.8 安装php7.1+mysql5.7+ nginx

安装方式yum

mysql

wget http://dev.mysql.com/get/mysql57-community-release-el6-7.noarch.rpm


yum install mysql57-community-release-el6-7.noarch.rpm
yum install mysql-community-server
service mysqld start
grep 'temporary password' /var/log/mysqld.log
mysql -uroot -p
set password = password('新密码');


nginx


vi  /etc/yum.repos.d/nginx.repo

写入:

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1


下载key:

http://nginx.org/keys/nginx_signing.key

导入key

rpm --import nginx_signing.key
yum -y install nginx


php7.1


rpm -Uvh http://www.btfw.org/linux/centos6_php5.6x64/epel-release-6-8.noarch.rpm

rpm -Uvh http://www.btfw.org/linux/centos6_php5.6x64/remi-release-6.rpm





yum install --enablerepo=remi --enablerepo=remi-php71 php71-php php71-php-cli php71-php-fpm php71-php-gd php71-php-json php71-php-mbstring php71-php-mcrypt php71-php-mysqlnd php71-php-odbc php71-php-opcache php71-php-pdo php71-php-pecl-mysql php71-php-pecl-mongodb php71-php-pecl-zip php71-php-pgsql php71-php-phpiredis  php71-php-xml php71-php-xmlrpc  php71-zephir php71-zephir-parser php71-php-bcmath

//配置文件位置 多个地方都可以配置的话,就存在一个优先级。php-fpm.conf优先级比php.ini高。
/etc/opt/remi/php71/php-fpm.conf
/etc/opt/remi/php71/php.ini
/etc/opt/remi/php71/php-fpm.d/www.conf
vi /etc/opt/remi/php71/php.ini





# 不显示错误,默认
display_errors = Off

# 在关闭display_errors后开启PHP错误日志(路径在php-fpm.conf中配置),默认
log_errors = On

# 字符集,默认
default_charset = "UTF-8"

# 文件上传大小,默认 
upload_max_filesize = 2M


# 设置PHP的时区
date.timezone = PRC

#开启PHP性能加速:
zend_extension=/opt/remi/php71/root/usr/lib64/php/modules/opcache.so
opcache.huge_code_pages=1
opcache.file_cache=/tmp
 
vi /etc/opt/remi/php71/php-fpm.conf
 
; 去掉里分号,方便以后重启。建议修改
; Default Value: none
; 下面的值最终目录是/usr/local/php/var/run/php-fpm.pid
; 开启后可以平滑重启php-fpm
pid = run/php-fpm.pid

; 设置错误日志的路径,可以默认值
; Note: the default prefix is /usr/local/php/var
; Default Value: log/php-fpm.log, 即/usr/local/php/var/log/php-fpm.log
error_log = /var/log/php-fpm/error.log

; Log等级,可以默认值
; Possible Values: alert, error, warning, notice, debug
; Default Value: notice
log_level = notice

; 后台运行,默认yes,可以默认值
; Default Value: yes
;daemonize = yes

vi
/etc/opt/remi/php71/php-fpm.d/www.conf

; 设置用户和用户组,默认都是nobody。可以默认值
user = nginx
group = nginx

; 设置PHP监听
; 下面是默认值,不建议使用。可以默认值
; listen = 127.0.0.1:9000
; 根据nginx.conf中的配置fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
listen = /var/run/php-fpm/php-fpm.sock

######开启慢日志。可以默认值
slowlog = /var/log/php-fpm/$pool-slow.log
request_slowlog_timeout = 10s
php_value[session.save_path]    = /var/opt/remi/php71/lib/php/session    #修改session存储路径 
配置nginx
vi /etc/nginx/nginx.conf
 
user  nginx;
worker_processes  1;

error_log  /backup/logs/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {

#禁止未绑定域名访问
server {
    listen       80  default_server;
    server_name  _;
    return       404;
}

     include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /backup/logs/nginx/access.log main; sendfile on; #tcp_nopush on; keepalive_timeout 65; #gzip on; include /etc/nginx/conf.d/sites-enabled/*.conf; }
mkdir
/etc/nginx/conf.d/sites-enabled
vi /etc/nginx/conf.d/php-fpm.conf
 
location ~ \.php$ {
    try_files                   $uri = 404;
    fastcgi_pass                127.0.0.1:9000;
    fastcgi_index               index.php;
    fastcgi_intercept_errors    on;
    fastcgi_param  SCRIPT_FILENAME  /$document_root$fastcgi_script_name;
    include                     /etc/nginx/fastcgi_params;
}
 
vi /etc/nginx/conf.d/sites-enabled/default.conf
server {
    listen       80;
    server_name  localhost;
    root         /data/web/test/;

    location / {
        index  index.html index.htm index.php;
        include     /etc/nginx/conf.d/php-fpm.conf;
    }
} 
配置完成
service php71-php-fpm start
service nginx start
service mysqld start



浏览1122  评论0  Alex于 2017-4-5 15:40
发言