前言
NGINX Unit 是用于各种Web应用程序的轻型,动态,开源服务器。 NGINX Unit 从头开始构建,可以一次运行多种语言版本的Web应用程序。
——略
总之nignx_unit就是nginx团队从头开始构建的动态Web应用服务器,支持多语言.
官网:unit
安装
php需要开启 embed
编译php时加入参数--enable-embed
如果是预编译安装可以参考官网的方法这里不再描述
'./configure' '--prefix=/usr/local/php' '--with-config-file-path=/usr/local/php/etc' '--with-config-file-scan-dir=/usr/local/php/etc/php.d' '--with-fpm-user=www' '--with-fpm-group=www' '--enable-fpm' '--enable-opcache' '--disable-fileinfo' '--enable-mysqlnd' '--with-mysqli=mysqlnd' '--with-pdo-mysql=mysqlnd' '--with-iconv' '--with-freetype' '--with-jpeg' '--with-zlib' '--enable-xml' '--disable-rpath' '--enable-bcmath' '--enable-shmop' '--enable-exif' '--enable-sysvsem' '--with-curl=/usr/local/curl' '--enable-mbregex' '--enable-mbstring' '--with-password-argon2' '--with-sodium=/usr/local' '--enable-embed' '--with-openssl=/usr/local/openssl' '--with-mhash' '--enable-pcntl' '--enable-sockets' '--enable-ftp' '--enable-intl' '--with-xsl' '--with-gettext' '--with-zip=/usr/local' '--enable-soap' '--disable-debug' 'PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/:'
以上为个人使用的php的./configure配置
这里我们采用编译安装unit的方式(PHP8要自定义安装)
yum install gcc make
git clone https://github.com/nginx/unit
cd unit
./configure --prefix=/usr/local/unit --group=www --user=www --openssl --control=unix:/var/run/control.unit.sock
make
make install
完成unit编译
编译PHP8模块
./configure php --module=php80\
--config=/usr/local/php/bin/php-config\
--lib-path=/usr/local/php/lib
make
make install
其中--config
需要对应php的php-config文件
lib-path
需要对应php的lib目录
创建链接
ln -s /usr/local/unit/sbin/unitd /usr/sbin/unitd
将unit添加到systemd
vim /usr/lib/systemd/system/unit.service
将以下代码写入该文件
[Unit]
Description=NGINX Unit
Wants=network-online.target
After=network-online.target
[Service]
Type=simple
Environment="UNITD_OPTIONS=--log /usr/local/unit/unit.log --pid /usr/local/unit/unit.pid"
ExecStart=/usr/sbin/unitd $UNITD_OPTIONS --no-daemon
ExecReload=
RuntimeDirectory=unit
RuntimeDirectoryMode=0755
[Install]
WantedBy=multi-user.target
而后重载
systemctl daemon-reload
systemctl enable unit
systemctl start unit
至此完成unit&unit-php安装