这篇文章主要介绍“如何编译安装nginx和php”的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇“如何编译安装nginx和php”文章能帮助大家解决问题。 编译安装nginx和php的方法:1、通过yum install命令安装依赖包;2、下载源码包并解压编译;3、修改虚拟主机配置文件;4、启动nginx并配置systemctl启动;5、下载php并解压编译即可。nginx和php编译安装nginx编译安装安装依赖包
yuminstall-ygccgcc-c++automakepcrepcre-develzlipzlib-developensslopenssl-devel
下载源码包并解压
[root@web03~]#wgethttp://nginx.org/download/nginx-1.18.0.tar.gz [root@web03~]#tarxfnginx-1.18.0.tar.gz [root@web03~]#cdnginx-1.18.0/
编译源码
[root@web03nginx-1.18.0]#./configure--prefix=/usr/local/nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module [root@web03nginx-1.18.0]#make&&makeinstall [root@web03nginx-1.18.0]#cd/usr/local/nginx/ [root@web03nginx]#tree . ├──conf │├──fastcgi.conf │├──fastcgi.conf.default │├──fastcgi_params │├──fastcgi_params.default │├──koi-utf │├──koi-win │├──mime.types │├──mime.types.default │├──nginx.conf │├──nginx.conf.default │├──scgi_params │├──scgi_params.default │├──uwsgi_params │├──uwsgi_params.default │└──win-utf ├──html │├──50x.html │└──index.html ├──logs └──sbin └──nginx
基本配置
[root@web03nginx]#useradd-s/sbin/nologin-Mwww [root@web03conf]#ln-s/usr/local/nginx/sbin/nginx/usr/local/bin/ [root@web03nginx]#mkdirconf/conf.d #拆分默认配置和虚拟主机 userwww; worker_processesauto; error_loglogs/error.log; #error_loglogs/error.lognotice; #error_loglogs/error.loginfo; pidlogs/nginx.pid; events{ worker_connections1024; } http{ includemime.types; default_typeapplication/octet-stream; log_formatmain'$remote_addr-$remote_user[$time_local]"$request"' '$status$body_bytes_sent"$http_referer"' '"$http_user_agent""$http_x_forwarded_for"'; access_loglogs/access.logmain; sendfileon; tcp_nopushon; server_tokensoff; #keepalive_timeout0; keepalive_timeout65; gzipon; includeconf.d/*.conf; } #虚拟主机配置文件 [root@web03conf]#vimconf.d/www.conf server{ listen80; server_namelocalhost; charsetutf-8; location/{ roothtml; indexindex.htmlindex.htm; } error_page404/404.html; error_page500502503504/50x.html; location=/50x.html{ roothtml; } location~.php${ proxy_passhttp://127.0.0.1; } location~.php${ roothtml; fastcgi_pass127.0.0.1:9000; fastcgi_indexindex.php; fastcgi_paramSCRIPT_FILENAME $document_root$fastcgi_script_name; includefastcgi_params; proxy_set_headerReferer$http_referer; proxy_set_headerCookie$http_cookie; proxy_set_headerX-Real-IP$remote_addr; proxy_set_headerX-Forwarded-For $proxy_add_x_forwarded_for; } }
启动nginx
nginx nginx-sreload重启
配置systemctl启动
[root@web03conf]#cat/usr/lib/systemd/system/nginx.service [Unit] Description=ThenginxHTTPandreverseproxyserver After=network.targetremote-fs.targetnss-lookup.target [Service] Type=forking PIDFile=/usr/local/nginx/logs/nginx.pid ExecStartPre=/usr/bin/rm-f/usr/local/nginx/logs/nginx.pid ExecStartPre=/usr/local/nginx/sbin/nginx-t ExecStart=/usr/local/nginx/sbin/nginx ExecReload=/usr/local/nginx/sbin/nginx-sreload KillSignal=SIGQUIT TimeoutStopSec=5 KillMode=process PrivateTmp=true [Install] WantedBy=multi-user.target
php二进制
rpm-Uvhhttps://mirror.webtatic.com/yum/el7/epel-release.rpm rpm-Uvhhttps://mirror.webtatic.com/yum/el7/webtatic-release.rpm yuminstallphp71w
php编译安装依赖包源码下载
[root@web03~]#wgethttp://hk1.php.net/get/php-7.2.33.tar.gz [root@web03~]#tarxfphp-7.2.33.tar.gz [root@web03~]#cdphp-7.2.33/
编译
yuminstallbzip2bzip2-devel-y yuminstallcurlcurl-devel-y yuminstallphp-mcryptlibmcryptlibmcrypt-devel-y yuminstallreadline-devel-y ./configure--prefix=/usr/local/php7--enable-fpm --with-zlib --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-opcache --with-fpm-user=www --with-fpm-group=www --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-gettext --enable-mbstring --with-iconv --with-mcrypt --with-mhash --with-openssl --enable-bcmath --enable-soap --with-libxml-dir --enable-pcntl --enable-shmop --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-sockets --with-curl --with-zlib --enable-zip --with-bz2 --with-readline make&&makeinstall
配置
ln-s/usr/local/php/bin/php/usr/bin/php php-i|grepini ConfigurationFile(php.ini)Path=>/usr/local/php/lib Scanthisdirforadditional.inifiles=>(none) #移动php.ini,从源码拷贝 [root@web03~]#cpphp-7.2.33/php.ini-production/usr/local/php/lib/php.ini php-i|grepini LoadedConfigurationFil免费云主机域名e=>/usr/local/php/lib/php.ini已经加载配置文件 #php-fpm cd/usr/local/php/etc/ cpphp-fpm.conf.defaultphp-fpm.conf cpphp-fpm.d/www.conf.defaultphp-fpm.d/www.conf #更改www.conf sed-i's#nobody#www#g'www.conf
system启动
[root@web03conf]#cat/usr/lib/systemd/system/php-fpm.service [Unit] Description=php-fpm After=syslog.targetnetwork.target [Service] Type=forking ExecStart=/usr/local/php/sbin/php-fpm ExecReload=/bin/kill-USR2$MAINPID ExecStop=/bin/kill-INT$MAINPID PrivateTmp=true [Install] WantedBy=multi-user.target #启动 [root@web03etc]#systemctldaemon-reload [root@web03etc]#systemctlstartphp-fpm.service
测试nginx
[root@web03sbin]#cd/usr/local/nginx/html/ [root@web03html]#catindex.php systemctlrestartnginx
测试mysql
关于“如何编译安装nginx和php”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识,可以关注百云主机行业资讯频道,小编每天都会为大家更新不同的知识点。
这篇文章主要讲解了“linux sudo命令的知识点有哪些”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“linux sudo命令的知识点有哪些”吧!“Sudo”是Unix/Linux平台上的一个非常有用的工具,…
免责声明:本站发布的图片视频文字,以转载和分享为主,文章观点不代表本站立场,本站不承担相关法律责任;如果涉及侵权请联系邮箱:360163164@qq.com举报,并提供相关证据,经查实将立刻删除涉嫌侵权内容。