CentOS源码部署系列(三)安装PHP

[3]PHP源码安装

进入/download目录

cd /download

下载PHP源码并解压并进入程序目录

sudo  wget https://www.php.net/distributions/php-7.x.x.tar.gz
sudo tar -zxvf php-7.3.5.tar.gz

执行configure文件并设置安装地址和配置文件地址

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc  --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir --with-jpeg-dir --with-xmlrpc --with-xsl --with-bz2 --with-mhash --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-sysvshm --enable-xml --enable-fpm

编译源码并安装

sudo make && sudo make install

配置php和php-fpm

1、先把源码包里的php.ini-development文件cp(复制)到php设置目录下改名为php.ini安装在/usr/local/php/lib/php.ini

2、到php目录的etc中:

cp php-fpm.conf.default php-fpm.conf
cp php-fpm.d/www.conf.default php-fpm.d/www.conf

3、设置php快捷命令

#ln -s 源文件 目标文件
ln -s /usr/local/php/bin/php /usr/bin
ln -s /usr/local/php/bin/php /usr/local/bin

# 验证
php -v
sudo php -v

4、进入sbin目录并启动php-fpm

cd /usr/local/php/sbin

#1、可以直接使用php-fpm启动
./php-fpm

#2、配置systemctl启动php-fpm
sudo vim /usr/lib/systemd/system/php-fpm.service

[Unit]
Description=The PHP FastCGI Process Manager
After=network.target

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

[Install]
WantedBy=multi-user.target

#启用配置
systemctl daemon-reload
#开机启动
systemctl enable php-fpm

启动命令:systemctl start php-fpm

你可能感兴趣的:(CentOS源码部署系列(三)安装PHP)