Linux 安装 PHP
小于 1 分钟
PHP 安装
一、CentOS7.x 源码安装PHP
1、下载php
下载地址: https://www.php.net/distributions/php-7.2.34.tar.gz
eg:
wget https://www.php.net/distributions/php-7.2.34.tar.gz
2、解压缩
tar -zxvf php-7.2.34.tar.gz
3、依赖下载
yum install -y gcc make httpd-devel libxml2-devel bzip2-devel libcurl-devel libjpeg-devel libpng-devel libmcrypt-devel readline-devel libxslt-devel bzip2-devel freetype-devel
4、 配置 PHP 编译选项
./configure \
--prefix=/opt/php/72 \
--with-config-file-path=/usr/local/php72/etc \
--enable-fpm \
--with-fpm-user=www \
--with-fpm-group=www \
--with-mysqli=/opt/mysql/bin/mysql_config \
--with-pdo-mysql=/opt/mysql \
--with-curl \
--with-zlib \
--with-gd \
--with-jpeg-dir=/opt/php/72/lib \
--with-png-dir=/opt/php/72/lib \
--with-readline \
--with-xsl \
--enable-cli \
--with-freetype-dir \
--enable-gd-jis-conv \
--enable-mbstring \
--enable-opcache \
--enable-soap \
--enable-zip \
--disable-fileinfo
完整的选项说明地址:https://www.php.net/manual/en/configure.about.php
5、编译并安装
make && make install
cp php.ini-development /opt/php/72/lib/php.ini
cp /opt/php/72/etc/php-fpm.conf.default /opt/php/72/etc/php-fpm.conf
cp /opt/php/72/etc/php-fpm.d/www.conf.default /opt/php/72/etc/php-fpm.d/www.conf
6、查看php安装
/opt/php/72/php -v
7、systemd管理
php-fpm.service文件示例
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target
[Service]
Type=simple
PIDFile=/run/php-fpm.pid
ExecStart=/opt/php/72/sbin/php-fpm --nodaemonize --fpm-config=/opt/php/72/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
[Install]
WantedBy=multi-user.target
二、Docker安装
待补充 ~