温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

nginx+php手动编译的详细过程

发布时间:2021-07-02 15:40:41 来源:亿速云 阅读:233 作者:chen 栏目:编程语言

本篇内容主要讲解“nginx+php手动编译的详细过程”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“nginx+php手动编译的详细过程”吧!

  • 系统 阿里云 CentOS-8 //注意端口开放,防火墙限制等问题,这些问题自己检查

  • PHP 版本 7.49

  • nginx 版本 1.18.0

不说废话,直接上流程,手动编译不规定一定要用,但是一定要会。

下载

1、下载Nginx

wget http://nginx.org/download/nginx-1.18.0.tar.gz

2、下载PHP

wget https://www.php.net/distributions/php-7.4.9.tar.gz

安装Nginx

依赖:

yum install gcc gcc-c++ automake pcre pcre-devel zlip zlib-devel openssl openssl-devel

1、解压

 tar -zxvf nginx-1.18.0.tar.gz

2、进入目录

cd ./nginx-1.18.0

3、编译(默认就好)

./configure

4、安装

make && make install#注:编译安装的过程中如果有报错,一般都是缺少依赖,缺什么安装什么就好了

5、把nginx 添加进服务

在/etc/init.d下创建文件nginx

添加可执行权限 chmod a+x /etc/init.d/nginx

vim /etc/init.d/nginx

#!/bin/bash#Startup script for the nginx Web Server#chkconfig: 2345 85 15nginx=/usr/local/nginx/sbin/nginxconf=/usr/local/nginx/conf/nginx.confcase $1 instart)echo -n "Starting Nginx"$nginx -c $confecho " done.";;stop)echo -n "Stopping Nginx"killall -9 nginxecho " done.";;test)$nginx -t -c $confecho "Success.";;reload)echo -n "Reloading Nginx"ps auxww | grep nginx | grep master | awk '{print $2}' | xargs kill -HUPecho " done.";;restart)$nginx -s reloadecho "reload done.";;*)echo "Usage: $0 {start|restart|reload|stop|test|show}";;esac

保存,即可使用命令:

service nginx start
service nginx stop
service nginx restart

//启动nginx , 通过ip访问正常:

nginx+php手动编译的详细过程

安装PHP

依赖:

yum install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel

1、解压

tar -zxvf php-7.4.9.tar.gz

2、进入目录

cd ./php-7.4.9

3、编译

./configure --prefix=/usr/local/php --disable-fileinfo --enable-fpm --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-openssl --with-zlib --with-curl --enable-ftp --with-gd --with-xmlrpc --with-jpeg-dir --with-png-dir --with-freetype-dir --enable-gd-native-ttf --enable-mbstring --with-mcrypt=/usr/local/libmcrypt --enable-zip --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-mysql-sock=/var/lib/mysql/mysql.sock --without-pear  --enable-bcmath

4、安装

make && make install#注:编译安装的过程中如果有报错,一般都是缺少依赖,缺什么安装什么就好了

5、配置文件

# 复制配置文件
cp ./php-7.4.9/php.ini-development /usr/local/php/lib/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
#复制启动脚本
cp ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
#添加执行权限
chmod +x /etc/init.d/php-fpm

使用命令查看

php -v

php-fpm命令(开启/重启/停止):
/etc/init.d/php-fpm start/restart/stop

查看是否安装完成:

ps -ef|grep php-fpm

Nginx与PHP结合(快速简易版,优化的配置请自行研究)

配置文件的解释请看文章

https://zhuanlan.zhihu.com/p/97208252

vim nginx.conf

server {listen       80;server_name  localhost;#charset koi8-r;#access_log  logs/host.access.log  main;location / {root   html;index  index.html index.htm index.php;}#error_page  404              /404.html;# redirect server error pages to the static page /50x.html#error_page   500 502 503 504  /50x.html;location = /50x.html {root   html;}# proxy the PHP scripts to Apache listening on 127.0.0.1:80##location ~ \.php$ {#    proxy_pass   http://127.0.0.1;#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000#location ~ \.php$ {root           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;}

配置PHP 的 /usr/local/php/etc/php-fpm.d/www.conf

env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp
listen.allowed_clients = 127.0.0.1
listen.owner = nobody
listen.group = nobody
listen = 127.0.0.1:9000
#以上配置去掉注释
保存

重启fpm 和 nginx

在项目目录,也就是默认的 nginx 下的 html 目录,创建.php文件,进行访问。

到此,相信大家对“nginx+php手动编译的详细过程”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI