版权声明:本站文章如无说明,则为 锅子博客 原创,版权归作者所有,转载请注明出处!
本文链接:https://www.gzpblog.com/20170303/731.html
写在前面
对于新手的一点建议:
最好熟悉一下linux 的基本命令,vim的常用命令千万不要无脑复制,先看一下命令,特别是路径要注意学会排查错误本篇安装的软件版本为:
Linux:Centos6.8Nginx:1.10.3MySQL:5.7.17PHP:7.0.16最近研究了Linux系统下的PHP环境搭建,个人感觉最好最好不要用yum默认的程序包安装,因为版本都比较低,下载最新的稳定版自行安装比较好。现在网上教程很多,之所以还记这篇,原因有一点,当你重复网上的教程自行安装时,90%还是会出现各种各样的问题,因为你可能linux的系统版本不同,你想装的软件版本不同,安装的方法不同,你下错了安装包的版本,还有其它乱七八糟的。举个例,比如你看着5.6的mysql安装教程,装5.7的,你感觉没问题,但是事实就是,5.7的不一样了!而且网上还没有新的这方面内容,不好找,这就需要你去摸索了,亲身经历啊。这里面,Niginx感觉最好配,MySQL最坑。
修改配置文件,重启服务后永久生效。 # sed -i ‘s/SELINUX=.*/SELINUX=disabled/g’ /etc/selinux/config 命令行设置立即生效。 # setenforce 0
上Nginx官网,复制最新稳定版的下载地址过来,然后用wget下载(接下来需要下载安装包的都可以用wget):
# cd /usr/local/src # wget http://nginx.org/download/nginx-1.10.3.tar.gz
2. 进行解压编译
# tar xvf nginx-1.10.3.tar.gz # yum groupinstall “Development tools” # yum -y install gcc wget gcc-c++ automake autoconf libtool libxml2-devel libxslt-devel perl-devel perl-ExtUtils-Embed pcre-devel openssl-devel
进入解压后的nginx-1.10.3文件夹: cd /usr/local/src/nginx-1.10.3
执行以下语句:
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 ./configure \ --prefix=/usr/local/nginx \ --sbin-path=/usr/sbin/nginx \ --conf-path=/etc/nginx/nginx.conf \ --error-log-path=/var/log/nginx/error.log \ --http-log-path=/var/log/nginx/access.log \ --pid-path=/var/run/nginx.pid \ --lock-path=/var/run/nginx.lock \ --http-client-body-temp-path=/var/tmp/nginx/client \ --http-proxy-temp-path=/var/tmp/nginx/proxy \ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi \ --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \ --http-scgi-temp-path=/var/tmp/nginx/scgi \ --user=nginx \ --group=nginx \ --with-pcre \ --with-http_v2_module \ --with-http_ssl_module \ --with-http_realip_module \ --with-http_addition_module \ --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_stub_status_module \ --with-http_auth_request_module \ --with-mail \ --with-mail_ssl_module \ --with-file-aio \ --with-ipv6 \ --with-http_v2_module \ --with-threads \ --with-stream \ --with-stream_ssl_module \ --with-openssl完成后执行编译: # make && make install # mkdir -pv /var/tmp/nginx/client
用vim编辑脚本: # vim /etc/init.d/nginx
写入以下内容: 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 #!/bin/sh # # nginx - this script starts and stops the nginx daemon # # chkconfig: - 85 15 # description: Nginx is an HTTP(S) server, HTTP(S) reverse \ # proxy and IMAP/POP3 proxy server # processname: nginx # config: /etc/nginx/nginx.conf # config: /etc/sysconfig/nginx # pidfile: /var/run/nginx.pid # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ "$NETWORKING" = "no" ] && exit 0 nginx="/usr/sbin/nginx" prog=$(basename $nginx) NGINX_CONF_FILE="/etc/nginx/nginx.conf" [ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx lockfile=/var/lock/subsys/nginx start() { [ -x $nginx ] || exit 5 [ -f $NGINX_CONF_FILE ] || exit 6 echo -n $"Starting $prog: " daemon $nginx -c $NGINX_CONF_FILE retval=$? echo [ $retval -eq 0 ] && touch $lockfile return $retval } stop() { echo -n $"Stopping $prog: " killproc $prog -QUIT retval=$? echo [ $retval -eq 0 ] && rm -f $lockfile return $retval killall -9 nginx } restart() { configtest || return $? stop sleep 1 start } reload() { configtest || return $? echo -n $"Reloading $prog: " killproc $nginx -HUP RETVAL=$? echo } force_reload() { restart } configtest() { $nginx -t -c $NGINX_CONF_FILE } rh_status() { status $prog } rh_status_q() { rh_status >/dev/null 2>&1 } case "$1" in start) rh_status_q && exit 0 $1 ;; stop) rh_status_q || exit 0 $1 ;; restart|configtest) $1 ;; reload) rh_status_q || exit 7 $1 ;; force-reload) force_reload ;; status) rh_status ;; condrestart|try-restart) rh_status_q || exit 0 ;; *) echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}" exit 2 esac保存退出(按:wq!);可能你得稍微查一下vim的一些命令,不然操作时可能会出现一点小问题。 赋予脚本执行权限: # chmod +x /etc/init.d/nginx
添加至服务管理列表,设置开机自启: # chkconfig –add nginx # chkconfig nginx on
# service nginx start
出现这玩意说明成功了! 注:如果报错 [emerg]: getpwnam(“nginx”) failed ; 解决方法: # useradd -s /sbin/nologin -M nginx # id nginx
执行以上的配置,如果出现下面这样的license,才是正确的,才可以开始编译,如果出问题,就解决,一般是少了什么库。
(注意将来可能会用到的一些库,先正确地编译好以免以后再来编就麻烦了,比如openssl, gd, mbstring, sockets, opcache等等) 执行编译: # make && make install首先备份默认的配置文件。
# cp /etc/nginx/nginx.conf /etc/nginx/nginx.confbak
# cp /etc/nginx/nginx.conf.default /etc/nginx/nginx.conf
编辑/etc/nginx/nginx.conf,在所支持的主页面格式中添加php格式的主页,类似如下: 1 2 3 4 location / { root /usr/local/nginx/html; index index.php index.html index.htm; } 取消以下内容前面的注释: 1 2 3 4 5 6 7 location ~ \.php$ { root /usr/local/nginx/html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html/$fastcgi_script_name; include fastcgi_params; }