yum安装最新版本lnmp nginx/php配置问题

来源:互联网 发布:魔兽世界更新传输数据 编辑:程序博客网 时间:2024/06/05 13:32

前言:

本教程搭建好之后的环境如下:

[root@localhost ~]# cat /etc/system-releaseCentOS Linux release 7.3.1611 (Core)[root@localhost ~]# nginx -vnginx version: nginx/1.10.2[root@localhost ~]# mysql -Vmysql  Ver 15.1 Distrib 10.2.6-MariaDB, for Linux (x86_64) using readline 5.1[root@localhost ~]# php-fpm -vPHP 7.0.20 (fpm-fcgi) (built: Jun 10 2017 06:35:53)Copyright (c) 1997-2017 The PHP GroupZend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies    with Zend OPcache v7.0.20, Copyright (c) 1999-2017, by Zend Technologies[root@localhost ~]# php -vPHP 7.0.20 (cli) (built: Jun 10 2017 06:34:07) ( NTS )Copyright (c) 1997-2017 The PHP GroupZend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies    with Zend OPcache v7.0.20, Copyright (c) 1999-2017, by Zend Technologies

1、第一步,下载安装linux系统,设置国内yum源,这会大大加快安装进度:

系统下载地址:超快! https://mirrors.tuna.tsinghua.edu.cn/#
设置国内yum源:超快! http://blog.csdn.net/zhezhebie/article/details/73484695

2、提前安装需要的服务端:

因为待会编译php的时候会安装这些服务对应的拓展,所以提前装好服务端:

mysql 安装:

http://blog.csdn.net/zhezhebie/article/details/74200355

memcached安装:yum install -y memcached
redis安装:yum install -y redis

3、安装nginx和php

nginx安装:

http://blog.csdn.net/zhezhebie/article/details/73325853

php7.0版本yum安装:

http://blog.csdn.net/zhezhebie/article/details/73325663

4、查看各种软件的版本:

查看php版本:

php -v

查看mysql版本:

mysql -V  #这里的V要大写

查看nginx版本:

nginx -v

这里写图片描述

按照我上面讲的那些,装好之后应该就是这样的。

5、查看执行文件所在的路径:

这个很有必要,因为你待会儿需要开启,关闭,重启之类的操作,肯定要知道执行文件在哪里呀!

[root@localhost nginx]# which nginx/usr/sbin/nginx[root@localhost nginx]# which mysql/usr/bin/mysql[root@localhost nginx]# which php/usr/bin/php[root@localhost nginx]# which php-fpm/usr/sbin/php-fpm[root@localhost nginx]#

很简单吧?yum安装的就是这么简单呀!

6、查看各种配置文件所在的地方:

查看php的:

php --ini           #这些命令我咋知道?那是因为我用了php -h这条命令查看有哪些可用的参数Loaded Configuration File:         /etc/php.ini        #这个就是php.ini所在的位置啦!

查看php-fpm的,这个文件一般和php.ini在同一个文件夹下面,进到php.ini所在文件夹,然后ls查看一下就知道了:

/etc/php-fpm.conf/etc/php-fpm.d/www.conf

查看nginx的

nginx -V        #注意,这里是大V,也是 nginx -h 找到的命令

结果如下:

nginx version: nginx/1.10.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-4) (GCC)
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: –prefix=/usr/share/nginx –sbin-path=/usr/sbin/nginx –modules-path=/usr/lib64/nginx/modules –conf-path=/etc/nginx/nginx.conf –error-log-path=/var/log/nginx/error.log –http-log-path=/var/log/nginx/access.log –http-client-body-temp-path=/var/lib/nginx/tmp/client_body –http-proxy-temp-path=/var/lib/nginx/tmp/proxy –http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi –http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi –http-scgi-temp-path=/var/lib/nginx/tmp/scgi –pid-path=/run/nginx.pid –lock-path=/run/lock/subsys/nginx –user=nginx –group=nginx –with-file-aio –with-ipv6 –with-http_ssl_module –with-http_v2_module –with-http_realip_module –with-http_addition_module –with-http_xslt_module=dynamic –with-http_image_filter_module=dynamic –with-http_geoip_module=dynamic –with-http_sub_module –with-http_dav_module –with-http_flv_module –with-http_mp4_module –with-http_gunzip_module –with-http_gzip_static_module –with-http_random_index_module –with-http_secure_link_module –with-http_degradation_module –with-http_slice_module –with-http_stub_status_module –with-http_perl_module=dynamic –with-mail=dynamic –with-mail_ssl_module –with-pcre –with-pcre-jit –with-stream=dynamic –with-stream_ssl_module –with-google_perftools_module –with-debug –with-cc-opt=’-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong –param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic’ –with-ld-opt=’-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E’
[root@localhost nginx]#

看到了吧?上面信息非常丰富,各种文件的路径都有了,配置文件,安装路径,错误日志,访问日志等等。

查看mysql的配置文件

mysql的查看帮助命令比较特殊,不是直接加 -h,而是–help。这个是因为mysql登陆的时候有时候会用到-h这个命令。远程登陆的时候会用到,用来指定远程host地址。
mysql帮助文件比较长,我们直接把它输出到文件里面查看好了:

mysql --help >>/root/mysqlhelp.txt

这样,mysql的文件就不会输出了,而是直接写入到/root/mysqlhelp.txt 这里面了。查看一下就可以得知:mysql的配置文件可能在的位置就是以下三个地方啦!骑士有经验的话,肯定知道是在:/etc/my.cnf

/etc/mysql/my.cnf  /etc/my.cnf  ~/.my.cnf 

验证一下是否正确,命令如下:

cat /etc/my.cnf

即可看到内容是吧?

7、备份各种配置文件:

这个必须要做,不然,呵呵,你懂的:

#备份php的配置文件cp /etc/php.ini /root/php.inibak#备份php-fpm的配置文件cp /etc/php-fpm.conf /root/php-fpm.confbakcp /etc/php-fpm.d/www.conf /root/www.confbak#备份nginx配置文件:cp  /etc/nginx/nginx.conf /root/nginx.confbak
#php-fpm的pid文件和错误日志所在路径:pid = /var/run/php-fpm/php-fpm.piderror_log = /var/log/php-fpm/error.log
#nginx的错误日志和pid文件路径:error_log /var/log/nginx/error.log;pid /run/nginx.pid;#nginx默认的访问日志,这个可以在单独的虚拟机里面重新定义,现在只需要知道它的地址即可:access_log  /var/log/nginx/access.log

8、配置nginx虚拟机和php-fpm,rewrite规则

nginx主配置文件:

#nginx用户和组,一般组也是www-data,但是我这里是为了宿主机自动挂载共享文件夹设置成vboxsf的user www-data vboxsf;       worker_processes auto;#错误日志路径error_log /var/log/nginx/error.log;pid /run/nginx.pid;events {    use epoll;    worker_connections 51200;    multi_accept on;}http {    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  /var/log/nginx/access.log  main;    sendfile            on;    tcp_nopush          on;    tcp_nodelay         on;    keepalive_timeout   65;    types_hash_max_size 2048;    include             /etc/nginx/mime.types;    default_type        application/octet-stream;    #虚拟机所在目录    include /etc/nginx/vhosts/*.conf;}

其中一个虚拟机的配置文件:(未设置rewrite规则)

cat /etc/nginx/vhosts/mytest.com.conf
   server {       listen       80 ;       server_name  mytest.com;       root         /media/sf_WWW/mytest.com;       #设置默认首页       location / {           index  index.php index.html index.htm;       } #设置 php-fpm 解析.php文件,关于这几个的区别可以看看这篇文章http://www.cnblogs.com/charlesblc/p/6491591.html      location ~* \.php$ {           fastcgi_index   index.php;          fastcgi_pass    127.0.0.1:9000;          include         fastcgi_params;          fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;          fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;      }      error_page 404 /404.html;          location = /40x.html {      }      error_page 500 502 503 504 /50x.html;          location = /50x.html {      }  }

设置rewrite规则的虚拟机配置文件:

 server{         listen 80;         server_name  dev.xxx.ysp.com;         root         /media/sf_WWW/xxx.com/mfxxapi;         index index.php;         location ~* \.php$ {              fastcgi_pass  127.0.0.1:9000;             fastcgi_index index.php;             include fastcgi.conf;             index index.php index.html;           }        #rewrite规则,如果没找到文件,就把这个路径的后半截交给框架的index.php负责,框架就会去找到对应的文件,并输出         if (!-e $request_filename) {          rewrite ^/(.*)$ /index.php?s=$1 last;         } }

其他细节:

1、linux开启80端口和3306端口,让外面的人可以访问这个虚拟机的80端口,开3306的原因是让某些mysql用户可以远程访问数据库,因为我们经常使用mysql客户端管理数据库:

参考链接:http://blog.csdn.net/zhezhebie/article/details/73342362

2、php开启错误提示,如果不开的话,当代码出现错误的时候,直接一片空白或者50x错误,这是因为yum安装默认用的是生产环境的 ini 文件,我们开发的时候把这个打开,有利于拍错。

3、各种服务的开机自启动:
参考链接:http://blog.csdn.net/zhezhebie/article/details/73551403

vim /etc/php.ini

改动如下:

error_reporting = E_ALLdisplay_errors = On

出现问题的解决步骤:
1、查看nginx访问日志和错误日志;(95%的问题在这里可以找到答案)
2、查看php的错误日志(要使用的话需要手动开启,一般不会用到);
3、抓包fiddler工具辅助查看,postman模拟请求,提交表单

阅读全文
0 0
原创粉丝点击