Linux系统下安装php是通过源码编译安装的,今天就来学习一下。
进入官网:https://www.php.net/downloads.php,找到你想要版本的源码的下载链接,我这里选择的是7.2.19。
cd /usr/local/src
wget https://www.php.net/distributions/php-7.2.19.tar.gz
tar -zxvf php-7.2.19.tar.gz
cd php-7.2.19
yum -y install gcc openssl openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel libxslt-devel libxml2 libxml2-devel epel-release libmcrypt-devel libzip libzip-devel
./configure \
--prefix=/usr/local/php \
--exec-prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
\
--with-curl \
--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-pear \
--with-png-dir \
--with-jpeg-dir\
--with-xmlrpc \
--with-xsl \
--with-zlib \
\
--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-xml \
--enable-zip
执行过程中如果发现缺少某些库导致出错,可以先使用 yum
安装这些库,然后再执行上面的配置命名。
具体的编译选项可以运行下面的命令查看:
./configure --help
要查看中文的翻译可以参考:php编译选项的翻译(./configure —help)
make && make install
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
执行:
/usr/local/php/bin/php -v
输出类似如下:
PHP 7.2.19 (cli) (built: Jun 10 2019 13:00:07) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
/usr/local/php/sbin/php-fpm
执行:
ps -aux | grep php
输出类似如下:
root 25864 0.0 0.6 198088 9448 pts/0 S+ 00:41 0:00 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)
nobody 25865 0.0 0.5 198284 7944 pts/0 S+ 00:41 0:00 php-fpm: pool www
nobody 25866 0.0 0.5 198284 8124 pts/0 S+ 00:41 0:00 php-fpm: pool www
root 25897 0.0 0.0 110288 908 pts/1 R+ 00:53 0:00 grep --color=auto php
这里不多说了,可查看我的另外一篇文章:Nginx配置PHP运行环境
暂无评论,赶紧发表一下你的看法吧。