Centos7编译安装NginxPHP1.安装编译依赖环境#使用root用户yum-yinstallpcre-develzlib-develgccgcc-c++make2.编译安装Nginx1,下载源码mkdir-p/home/src&&cd/home/srcwgethttp://nginx.org/download/nginx-1.23.0.tar.gztar-zxvfnginx-1.23.0.tar.gz2,创建nginx用户组groupadd-rnginx3,创建nginx用户useradd-M-s/sbin/nologinnginx4,创建安装目录mkdir-p/home/app/nginx5,编译安装#进入源码目录cd/home/src/nginx-1.23.0#配置编译选项生成Makefile./configure\--prefix=/home/app/nginx\--without-http_memcached_module\--user=nginx\--group=nginx\--with-http_stub_status_module\--with-http_ssl_module\--with-http_gzip_static_module#编译安装make&&makeinstall6,查看是否安装成功#启动nginx/home/app/nginx/sbin/nginx#查看nginx是否正常/home/app/nginx/sbin/nginx-t#输出执行后出现如下信息,如果没有提示错误,则表示安装成功.conf测试成功#stopnginx/home/app/nginx/sbin/nginx-sstop7编写快速启动脚本vi/lib/systemd/system/nginx.service#启动脚本代码[Unit]Description=nginxAfter=network.target[Service]Type=forkingPIDFile=/home/app/nginx/logs/nginx.pidExecStart=/home/app/nginx/sbin/nginxExecReload=/home/app/nginx/sbin/nginx-sreloadExecStop=/home/app/nginx/sbin/nginx-squitPrivateTmp=true[Install]WantedBy=multi-user.target8,setbootsystemctlenablenginx.service9,启动,重启,停止Nginx#startsystemctlstartnginx.service#restartsystemctlrestartnginx.service#stopsystemctlstopnginx.service3.安装PHP71,下载源码cd/home/srcwgethttp://ftp.ntu.edu.tw/php/distributions/php-7.1.30.tar.gztar-zxvfphp-7.1.30.tar.gz2,编译安装#进入源码目录cd/home/src/php-7.1.30#配置编译选项生成Makefile。/configure\--prefix=/home/app/php\--with-config-file-path=/home/app/php/etc\--enable-fpm\--with-fpm-user=www\--with-fpm-group=www\--enable-inline-optimization\--disable-debug\--disable-rpath\--enable-shared\--enable-soap\--with-libxml-dir\--with-xmlrpc\--with-openssl\--with-mcrypt\--with-mhash\--with-pcre-regex\--with-zlib\--enable-bcmath\--with-iconv\--with-bz2\--启用日历\--with-curl\--with-cdb\--enable-dom\--enable-exif\--enable-fileinfo\--enable-filter\--with-pcre-dir\--enable-ftp\--with-gd\--with-openssl-dir\--with-jpeg-dir\--with-png-dir\--with-zlib-dir\--with-freetype-dir\--enable-gd-native-ttf\--enable-gd-jis-conv\--with-gettext\--with-gmp\--with-mhash\--enable-json\--enable-mbstring\--enable-mbregex\--enable-mbregex-backtrack\--with-libmbfl\--with-onig\--启用-pdo\--with-mysqli=mysqlnd\--with-pdo-mysql=mysqlnd\--with-zlib-dir\--with-pdo-sqlite\--with-readline\--enable-session\--enable-shmop\--enable-simplexml\--enable-sockets\--enable-sysvmsg\--enable-sysvsem\--enable-sysvshm\--enable-wddx\--with-libxml-dir\--with-xsl\--enable-zip\--enable-mysqlnd-compression-support\--with-pear\--enable-opcache#编译&安装make&&makeinstall3、配置环境变量#创建独立环境变量文件touch/etc/profile.d/php.sh#写输入变量值echo'exportPATH=$PATH:/home/app/php/bin/'>/etc/profile.d/php.sh#赋予执行权限chmod0777/etc/profile.d/php.sh#刷新生效source/etc/profile.d/php.sh4,configurephp.ini#复制基础模板cpphp.ini-production/home/app/php/etc/php.ini#修改配置vi/home/app/php/etc/php.ini#进行如下修改(时区、版本号不显示,开启opcache缓存加速PHP)#------------------------------------------------------1.查找:;date.timezone=修改为:date.timezone=PRC2。找到:expose_php=On,修改为:expose_php=Off3。找到:opcache.enable=0,改成:opcache.enable=14。在动态扩展代码块中添加zend_extension=opcache.so#-----------------------------------------------------------5。配置php-fpm#复制基本配置模板cp/home/app/php/etc/php-fpm.conf.default/home/app/php/etc/php-fpm.confcp/home/app/php/etc/php-fpm.d/www.conf.default/home/app/php/etc/php-fpm.d/www.confcpsapi/fpm/init.d.php-fpm/home/app/php/bin/php-fpm#给php-fpm执行权限chmod0777/home/app/php/bin/php-fpm#vi/home/app/php/etc/php-fpm.conf#做如下修改#-----------------------------------------------------------1、找到:;daemonize=yes,修改为:daemonize=yes#---------------------------------------------------------------#vim/home/app/php/etc/php-fpm.d/www.conf#进行以下更改#--------------------------------------------------------------------------------------1.发现:listen=127.0.0.1:9000改为:;listen=127.0.0.1:90002。添加:listen=/home/app/php/var/run/php-fpm.sock3。发现:;listen.owner=www改为:listen.owner=www4。查找:;listen.group=www并更改为:listen.group=www5。找到:;listen.mode=0660改成:listen.mode=0660#------------------------------------------------------------------------------————6。测试php-fpm是否安装成功/home/app/php/bin/php-fpmstart#如果显示如下信息,说明安装成功。启动php-fpmdone7。编写快速启动脚本vi/lib/systemd/system/php-fpm.service#启动脚本代码[Unit]Description=php-fpmAfter=network.target[Service]Type=forkingPIDFile=/home/app/php/var/运行/php-fpm.pidExecStart=/home/app/php/bin/php-fpmstartExecReload=/home/app/php/bin/php-fpmrestartExecStop=/home/app/php/bin/php-fpmstopPrivateTmp=true[Install]WantedBy=multi-user.target8,setbootsystemctlenablephp-fpm.service9,start,restart,stopphp-fpm#startsystemctlstartphp-fpm.service#Restartsystemctlstopphp-fpm.service#stopsystemctlrestartphp-fpm.service4.NginxPHP配置1.修改/home/app/nginx/conf/nginx.conf#vim/home/app/nginx/conf/nginx。conf#进行以下更改#----------------------------------------------------——————————————————————————1、找到:#usernobody;更改为:用户www;2.在服务器配置部分位置添加以下内容~[^/]\.php(/|$){fastcgi_passunix:/home/app/php/var/run/php-fpm.sock;fastcgi_indexindex.php;fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;包含fastcgi.conf;}#--------------------------------------------------------——————————————————————2.重启nginxsystemctlrestartnginx3,测试#vi/home/app/nginx/html/test.php#写入以下内容#————————————————————————#——————————————————————————#用浏览器访问:http://xxx.xxx.xxx.xxx/test.php
