您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

怎么编译安装nginx和php

2024/3/15 0:54:24发布32次查看
编译安装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.confserver { 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
nginxnginx -s reload 重启
配置systemctl启动
[root@web03 conf]# cat /usr/lib/systemd/system/nginx.service[unit]description=the nginx http and reverse proxy serverafter=network.target remote-fs.target nss-lookup.target[service]type=forkingpidfile=/usr/local/nginx/logs/nginx.pidexecstartpre=/usr/bin/rm -f /usr/local/nginx/logs/nginx.pid execstartpre=/usr/local/nginx/sbin/nginx -texecstart=/usr/local/nginx/sbin/nginxexecreload=/usr/local/nginx/sbin/nginx -s reloadkillsignal=sigquittimeoutstopsec=5killmode=processprivatetmp=true[install]wantedby=multi-user.target
php二进制
rpm -uvh https://mirror.webtatic.com/yum/el7/epel-release.rpmrpm -uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpmyum 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 -yyum install curl curl-devel -yyum install php-mcrypt libmcrypt libmcrypt-devel -yyum 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/phpphp -i | grep iniconfiguration file (php.ini) path => /usr/local/php/libscan this dir for additional .ini files => (none)# 移动php.ini, 从源码拷贝[root@web03 ~]# cp php-7.2.33/php.ini-production /usr/local/php/lib/php.iniphp -i | grep iniloaded configuration file => /usr/local/php/lib/php.ini 已经加载配置文件# php-fpmcd /usr/local/php/etc/cp php-fpm.conf.default php-fpm.confcp php-fpm.d/www.conf.default php-fpm.d/www.conf# 更改www.confsed -i 's#nobody#www#g' www.conf
system启动
[root@web03 conf]# cat /usr/lib/systemd/system/php-fpm.service[unit]description=php-fpmafter=syslog.target network.target[service]type=forkingexecstart=/usr/local/php/sbin/php-fpmexecreload=/bin/kill -usr2 $mainpidexecstop=/bin/kill -int $mainpidprivatetmp=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 <?phpphpinfo()?>systemctl restart nginx
测试mysql
<?php $link=mysql_connect("172.25.90.14","root","redhat"); if(!$link) echo "faild!连接错误,用户名密码不对"; else echo "ok!可以连接"; ?>
推荐学习:《php视频教程》
以上就是怎么编译安装nginx和php的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product