编译安装nginx和php的方法:1、通过yum install命令安装依赖包;2、下载源码包并解压编译;3、修改虚拟主机配置文件;4、启动nginx并配置systemctl启动;5、下载php并解压编译即可。
本教程操作环境:windows10系统、php7.2.33版、DELL G3电脑
怎么编译安装nginx和php?
nginx和php编译安装
nginx编译安装
安装依赖包
yum install -y gcc gcc-c++ automake pcre pcre-devel zlip zlib-devel openssl openssl-devel
下载源码包并解压
[root@web03 ~]# wget http://nginx.org/download/nginx-1.18.0.tar.gz [root@web03 ~]# tar xf nginx-1.18.0.tar.gz [root@web03 ~]# cd nginx-1.18.0/
编译源码
[root@web03 nginx-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@web03 nginx-1.18.0]# make && make install [root@web03 nginx-1.18.0]# cd /usr/local/nginx/ [root@web03 nginx]# 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@web03 nginx]# useradd -s /sbin/nologin -M www [root@web03 conf]# ln -s /usr/local/nginx/sbin/nginx /usr/local/bin/ [root@web03 nginx]# mkdir conf/conf.d # 拆分默认配置和虚拟主机 user www; worker_processes auto; error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; pid logs/nginx.pid; events { worker_connections 1024; } http { include 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 logs/access.log main; sendfile on; tcp_nopush on; server_tokens off; #keepalive_timeout 0; keepalive_timeout 65; gzip on; include conf.d/*.conf; } #虚拟主机配置文件 [root@web03 conf]# vim conf.d/www.conf server { listen 80; server_name localhost; charset utf-8; location / { root html; index index.html index.htm; } error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } location ~ \.php$ { proxy_pass http://127.0.0.1; } location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; proxy_set_header Referer $http_referer; proxy_set_header Cookie $http_cookie; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }
启动nginx
nginx nginx -s reload 重启
配置systemctl启动
[root@web03 conf]# cat /usr/lib/systemd/system/nginx.service [Unit] Description=The nginx HTTP and reverse proxy server After=network.target remote-fs.target nss-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 -s reload KillSignal=SIGQUIT TimeoutStopSec=5 KillMode=process PrivateTmp=true [Install] WantedBy=multi-user.target
php二进制
rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm yum install php71w
php编译安装
依赖包
源码下载
[root@web03 ~]# wget http://hk1.php.net/get/php-7.2.33.tar.gz [root@web03 ~]# tar xf php-7.2.33.tar.gz [root@web03 ~]# cd php-7.2.33/
编译
yum install bzip2 bzip2-devel -y yum install curl curl-devel -y yum install php-mcrypt libmcrypt libmcrypt-devel -y yum install readline-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 && make install
配置
ln -s /usr/local/php/bin/php /usr/bin/php php -i | grep ini Configuration File (php.ini) Path => /usr/local/php/lib Scan this dir for additional .ini files => (none) # 移动php.ini, 从源码拷贝 [root@web03 ~]# cp php-7.2.33/php.ini-production /usr/local/php/lib/php.ini php -i | grep ini Loaded Configuration File => /usr/local/php/lib/php.ini 已经加载配置文件 # php-fpm cd /usr/local/php/etc/ cp php-fpm.conf.default php-fpm.conf cp php-fpm.d/www.conf.default php-fpm.d/www.conf # 更改www.conf sed -i 's#nobody#www#g' www.conf
system启动
[root@web03 conf]# cat /usr/lib/systemd/system/php-fpm.service [Unit] Description=php-fpm After=syslog.target network.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@web03 etc]# systemctl daemon-reload [root@web03 etc]# systemctl start php-fpm.service
测试nginx
[root@web03 sbin]# cd /usr/local/nginx/html/ [root@web03 html]# cat index.php <?php phpinfo() ?> systemctl restart nginx
测试mysql
<?php $link=mysql_connect("172.25.90.14","root","redhat"); if(!$link) echo "FAILD!连接错误,用户名密码不对"; else echo "OK!可以连接"; ?>
推荐学习:《PHP视频教程》
以上是怎么编译安装nginx和php的详细内容。更多信息请关注PHP中文网其他相关文章!

本文比较了酸和基本数据库模型,详细介绍了它们的特征和适当的用例。酸优先确定数据完整性和一致性,适合财务和电子商务应用程序,而基础则侧重于可用性和

本文讨论了确保PHP文件上传的确保,以防止诸如代码注入之类的漏洞。它专注于文件类型验证,安全存储和错误处理以增强应用程序安全性。

本文讨论了在PHP中实施API速率限制的策略,包括诸如令牌桶和漏水桶等算法,以及使用Symfony/Rate-limimiter之类的库。它还涵盖监视,动态调整速率限制和手

本文讨论了使用password_hash和pyspasswify在PHP中使用密码的好处。主要论点是,这些功能通过自动盐,强大的哈希算法和SECH来增强密码保护

本文讨论了OWASP在PHP和缓解策略中的十大漏洞。关键问题包括注射,验证损坏和XSS,并提供用于监视和保护PHP应用程序的推荐工具。


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

SublimeText3 Linux新版
SublimeText3 Linux最新版

mPDF
mPDF是一个PHP库,可以从UTF-8编码的HTML生成PDF文件。原作者Ian Back编写mPDF以从他的网站上“即时”输出PDF文件,并处理不同的语言。与原始脚本如HTML2FPDF相比,它的速度较慢,并且在使用Unicode字体时生成的文件较大,但支持CSS样式等,并进行了大量增强。支持几乎所有语言,包括RTL(阿拉伯语和希伯来语)和CJK(中日韩)。支持嵌套的块级元素(如P、DIV),

Atom编辑器mac版下载
最流行的的开源编辑器

DVWA
Damn Vulnerable Web App (DVWA) 是一个PHP/MySQL的Web应用程序,非常容易受到攻击。它的主要目标是成为安全专业人员在合法环境中测试自己的技能和工具的辅助工具,帮助Web开发人员更好地理解保护Web应用程序的过程,并帮助教师/学生在课堂环境中教授/学习Web应用程序安全。DVWA的目标是通过简单直接的界面练习一些最常见的Web漏洞,难度各不相同。请注意,该软件中

VSCode Windows 64位 下载
微软推出的免费、功能强大的一款IDE编辑器