- 系统 阿里云 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 15
nginx=/usr/local/nginx/sbin/nginx
conf=/usr/local/nginx/conf/nginx.conf
case $1 in
start)
echo -n "Starting Nginx"
$nginx -c $conf
echo " done."
;;
stop)
echo -n "Stopping Nginx"
killall -9 nginx
echo " done."
;;
test)
$nginx -t -c $conf
echo "Success."
;;
reload)
echo -n "Reloading Nginx"
ps auxww | grep nginx | grep master | awk '{print $2}' | xargs kill -HUP
echo " done."
;;
restart)
$nginx -s reload
echo "reload done."
;;
*)
echo "Usage: $0 {start|restart|reload|stop|test|show}"
;;
esac
保存,即可使用命令:
service nginx start
service nginx stop
service nginx restart
//启动nginx , 通过ip访问正常:

安装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文件,进行访问。