Ubuntu 编译安装 php7.4

2 篇文章 0 订阅
1 篇文章 0 订阅

安装依赖

sudo apt update
sudo apt install gcc -y &&
sudo apt install make -y &&
sudo apt install openssl -y &&
sudo apt install curl -y &&
sudo apt install libbz2-dev -y &&
sudo apt install libxml2-dev -y &&
sudo apt install libjpeg-dev -y &&
sudo apt install libpng-dev -y &&
sudo apt install libfreetype6-dev -y &&
sudo apt install libzip-dev -y &&
sudo apt install libssl-dev -y &&
sudo apt install libsqlite3-dev -y &&
sudo apt install libcurl4-openssl-dev -y &&
sudo apt install libgmp3-dev -y &&
sudo apt install libonig-dev -y &&
sudo apt install libreadline-dev -y &&
sudo apt install libxslt1-dev -y &&
sudo apt install libffi-dev -y

模块对应的依赖(可选择性的安装)

xml
sudo apt-get install -y libxml2-dev
pcre
sudo apt-get install -y libpcre3-dev
jpeg
sudo apt-get install -y libjpeg62-dev
freetype
sudo apt-get install -y libfreetype6-dev
png
sudo apt-get install -y libpng12-dev libpng3 libpnglite-dev
iconv
sudo apt-get install -y libiconv-hook-dev libiconv-hook1
mycrypt
sudo apt-get install -y libmcrypt-dev libmcrypt4
mhash
sudo apt-get install -y libmhash-dev libmhash2
openssl
sudo apt-get install -y libltdl-dev libssl-dev
curl
sudo apt-get install -y libcurl4-openssl-dev
mysql
sudo apt-get install -y libmysqlclient-dev
imagick
sudo apt-get install -y libmagickcore-dev libmagickwand-dev
readline
sudo apt-get install -y libedit-dev
ubuntu 无法找到 iconv
sudo ln -s /usr/lib/libiconv_hook.so.1.0.0 /usr/lib/libiconv.so
sudo ln -s /usr/lib/libiconv_hook.so.1.0.0 /usr/lib/libiconv.so.1
安装PHP扩展
sudo apt-get install -y autoconf automake m4

官网下载php源码并解压

wget https://www.php.net/distributions/php-7.4.4.tar.gz
tar -xvf php-7.4.4.tar.gz
cd php-7.4.4

预编译

注:/opt/php/74 为php的安装目录 权限和具体目录位置可以根据自身需要配置。
预编译启用的模块也需根据自身需要配置。

./configure \
--prefix=/opt/php/74 \
--with-config-file-path=/opt/php/74/etc \
--enable-fpm \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared  \
--with-xmlrpc \
--with-mhash \
--with-sqlite3 \
--with-zlib \
--enable-bcmath \
--with-iconv \
--with-bz2 \
--with-openssl \
--enable-calendar \
--with-curl \
--with-cdb \
--enable-dom \
--enable-exif \
--enable-fileinfo \
--enable-filter \
--with-openssl-dir \
--with-zlib-dir \
--enable-gd-jis-conv \
--with-gettext \
--with-gmp \
--with-mhash \
--enable-json \
--enable-mbstring \
--enable-mbregex \
--enable-pdo \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-pdo-sqlite \
--with-readline \
--enable-session \
--enable-shmop \
--enable-simplexml \
--enable-sockets  \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--with-xsl \
--enable-mysqlnd-compression-support \
--with-pear \
--enable-opcache \
--with-zip \
--enable-gd \
--with-ffi

编译并安装

make -j && make install

配置文件

cp php.ini-development /opt/php/74/etc/php.ini &&
cd /opt/php/74/etc && cp php-fpm.conf.default php-fpm.conf &&
cd /opt/php/74/etc/php-fpm.d && cp www.conf.default www.conf
vim /opt/php/74/etc/php-fpm.conf

;pid = run/php-fpm.pid 去掉;

pid = run/php-fpm.pid
vim /opt/php/74/etc/php-fpm.d/www.conf

增加

user = www
group = www

增加php环境变量(我使用的zsh 如果是bash 请编辑 .bashrc 文件 )

vim ~/.zshrc

加入

export PHP_HOME=/opt/php/74
export PATH=$PHP_HOME/bin:$PATH

增加www用户用户组

sudo groupadd www
sudo useradd -g www www

php-fpm服务化(Systemd)

sudo touch /lib/systemd/system/php-fpm.service
sudo vim /lib/systemd/system/php-fpm.service
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target

[Service]
Type=forking
PIDFile=/opt/php/74/var/run/php-fpm.pid
ExecStart=/opt/php/74/sbin/php-fpm
ExecReload=/bin/kill -USR2 $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

服务开机启动

sudo systemctl enable php-fpm.service

启动、停止、重启、状态

sudo systemctl start php-fpm.service
sudo systemctl stop php-fpm.service
sudo systemctl restart php-fpm.service
sudo systemctl status php-fpm.service
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值