2026年10月

rocky linux9 安装php + nginx
sudo dnf groupinstall -y "Development Tools"
sudo dnf install -y autoconf automake libtool pkgconf bison re2c

sudo dnf config-manager --set-enabled crb
dnf install -y openssl-devel libxml2-devel curl-devel libpng-devel libjpeg-turbo-devel freetype-devel libzip-devel oniguruma-devel sqlite-devel

./configure \
CFLAGS="-fPIE" \
LDFLAGS="-pie" \
--prefix=/usr/local/php84 \
--with-config-file-path=/usr/local/php84/etc \
--enable-fpm \
--with-fpm-user=www \
--with-fpm-group=www \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-openssl \
--with-zlib \
--with-curl \
--enable-gd \
--with-jpeg \
--with-freetype \
--enable-mbstring \
--enable-bcmath \
--enable-sockets \
--enable-opcache \
--with-zip \
--with-libxml
--with-sqlite3 \
--with-pdo-sqlite

make -j$(nproc)
make install

sudo cp php.ini-production /usr/local/php84/etc/php.ini
sudo cp /usr/local/php84/etc/php-fpm.conf.default /usr/local/php84/etc/php-fpm.conf
sudo cp /usr/local/php84/etc/php-fpm.d/www.conf.default /usr/local/php84/etc/php-fpm.d/www.conf

sudo tee /etc/systemd/system/php84-fpm.service > /dev/null <<'EOF'
[Unit]
Description=The PHP 8.4 FastCGI Process Manager
After=network.target

[Service]
Type=simple
PIDFile=/usr/local/php84/var/run/php-fpm.pid
ExecStart=/usr/local/php84/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php84/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target
EOF

echo 'export PATH=/usr/local/php84/bin:/usr/local/php84/sbin:$PATH' | sudo tee /etc/profile.d/php84.sh
source /etc/profile.d/php84.sh

useradd -r -s /sbin/nologin -M www

sudo systemctl daemon-reload
sudo systemctl start php84-fpm
sudo systemctl enable php84-fpm
php -v

安装nginx
dnf install nginx
systemctl enable --now nginx