美文网首页
Ubuntu+ php8+ nginx

Ubuntu+ php8+ nginx

作者: 米酒真香 | 来源:发表于2022-03-18 17:00 被阅读0次

php8.0安装和php-fpm
Nginx配置后无法解析PHP问题
PHP官网下载最新版 PHP8.1.4 tar.gz包

php编译安装

tar -zxvf php-8.1.4.tar.gz 
mv php-8.1.4 php.8.1.4
cd php.8.1.4
cat README.md
根据README.md文档 
sudo apt install -y pkg-config build-essential autoconf bison re2c libxml2-dev libsqlite3-dev libssl-dev libonig-dev libpng-dev zlib1g-dev libzip-dev

./configure --prefix=/usr/local/php8 --with-config-file-path=/usr/local/php8/etc --enable-fpm --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-mysqlnd-compression-support  --with-zlib  --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem  --with-curl --enable-mbregex --enable-mbstring --enable-intl   --enable-ftp  --enable-gd-jis-conv  --with-openssl --with-mhash --enable-pcntl --enable-sockets   --enable-soap --with-gettext --enable-fileinfo --enable-opcache --with-pear --without-gdbm --enable-gd --enable-exif --with-zip

make -j4  # 4是cpu的核数
make TEST_PHP_ARGS=-j4 test
sudo make install

启动 php-fpm

cd /usr/local/php8/etc
cp php-fpm.conf.default  php-fpm.conf
vi php-fpm.conf   
去掉# pid = run/php-fpm.pid 前面的注释


cd /usr/local/php8/etc/php-fpm.d
cp www.conf.default  www.conf


# 测试
sudo /usr/local/php8/sbin/php-fpm -t

# 启动
sudo /usr/local/php8/sbin/php-fpm  # 报错 cannot get gid for group 'nobody'
sudo groupadd nobody # 增加组即可


查看php-fpm是否正常启动

sudo netstat -antp | grep 9000

$ 正常输出:
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      616691/php-fpm: mas 

nginx 配置

sudo vim /etc/nginx/conf.d/php.conf
server {
        listen   80;
        server_name  你的域名;
        root   /var/www/xxx;
        index  index.html index.htm index.php;

        

        location ~ \.php$ {
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include        fastcgi_params;
                
        }

}
# 测试nginx 配置文件
sudo nginx -t                 
  nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
  nginx: configuration file /etc/nginx/nginx.conf test is successful
# 重启nginx
sudo nginx -s reload 

在网站根目录新建index.php
<? phpinfo();?>
打开测试。

相关文章

网友评论

      本文标题:Ubuntu+ php8+ nginx

      本文链接:https://www.haomeiwen.com/subject/tutwdrtx.html