CentOS7源码部署PHP-7-0-27
文章发布较早,内容可能过时,阅读注意甄别。
# 1,安装 php7 依赖
yum install epel-release
yum install -y gcc gcc-c++ 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 pcre-devel autoconf librabbitmq librabbitmq-devel libmcrypt libmcrypt-devel
1
2
2
# 2,添加用户用户组
groupadd www
useradd -r -g www www
1
2
2
# 3,安装 php7.0.27
下载 http://at2.php.net/get/php-7.0.27.tar.gz/from/this/mirror
tar -xzvf php php7.0.27.tar.gz
cd php-php7.0.27
./configure \
--prefix=/usr/local/php \
--enable-fpm --with-fpm-user=www --with-fpm-group=www --enable-inline-optimization --disable-rpath \
--enable-shared --enable-soap --with-libxml-dir --with-xmlrpc --with-openssl --with-mhash --with-pcre-regex \
--with-sqlite3 --with-zlib --enable-bcmath --with-iconv --with-bz2 --enable-calendar --with-curl --with-cdb \
--enable-dom --enable-exif --enable-fileinfo --enable-filter --with-pcre-dir --enable-ftp --with-gd \
--with-openssl-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-freetype-dir --with-gmp \
--enable-gd-jis-conv --with-gettext --with-mhash --enable-json --enable-mbstring --enable-mbregex \
--enable-mbregex-backtrack --with-libmbfl --with-onig --enable-pdo --with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd --with-zlib-dir --with-pdo-sqlite --with-readline --enable-session --enable-shmop \
--enable-simplexml --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx \
--with-xsl --enable-zip --enable-mysqlnd-compression-support --with-pear --disable-debug --enable-pcntl
make && make install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 4,配置 php-fpm
cp php.ini-production /usr/local/php/etc/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
1
2
3
4
2
3
4
# 5,设置 php.ini 时区
vi /usr/local/php/etc/php.ini
date.timezone = "Asia/Shanghai"
1
2
2
# 6,配置通过 systemd 管理
首先更改 pid 路径。
vim /usr/local/php/etc/php-fpm.conf
//修改如下内容
pid = /var/run/php-fpm.pid
1
2
3
2
3
添加启动文件:
cat >> /usr/lib/systemd/system/php-fpm.service << EOF
[Unit]
Description=php for systemd
After=syslog.target network.target
[Service]
Type=forking
PIDFile=/var/run/php-fpm.pid
ExecStart=/usr/local/php/sbin/php-fpm
ExecReload=/bin/kill -USR2 $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
EOF
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
验证:
$ systemctl daemon-reload
$ systemctl start php-fpm
$ systemctl status php-fpm
1
2
3
2
3
# 7, 添加到系统路径
cat >> /etc/profile << 'EOF'
export PHP_HOME="/usr/local/php"
export PATH="$PATH:$PHP_HOME/bin"
EOF
source /etc/profile
1
2
3
4
5
2
3
4
5
上次更新: 2024/11/19, 23:11:42