Linux Centos7.6 安装 php.5.3.6,太详细了
应公司为事业单位,好多东西不能升级,程序只能适配低版本的PHP。
故留此文档,给大家避坑。安装的时候都想抓狂,各种报错
1.先安装一些php需要的依赖。
yum install -y bzip2 bzip2-devel gcc gcc-c++ make \
zlib zlib-devel pcre pcre-devel libxml2 libxml2-devel \
openssl openssl-devel curl-devel libjpeg-devel libpng \
libpng-devel sqlite-devel libxslt-devel oniguruma
yum -y install http://down.24kplus.com/linux/oniguruma/oniguruma-6.7.0-1.el7.x86_64.rpm
yum -y install http://down.24kplus.com/linux/oniguruma/oniguruma-devel-6.7.0-1.el7.x86_64.rpm
2.下载依赖包
wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/attic/libmcrypt/libmcrypt-2.5.7.tar.gz
3.如果以上3个地址无法访问,则使用以下我的百度网盘中下载
链接:https://pan.baidu.com/s/16uKkBaqocAfSyctQk7PA2A?pwd=odte
提取码:odte
4.下载安装包
php 官方地址:
https://www.php.net/downloads
找到你们需要安装的版本,点击下载,上传到服务器中
ls -lgh
总用量 15M
-rw-r--r--. 1 root 512K 7月 27 14:12 libmcrypt-2.5.7.tar.gz
-rw-r--r--. 1 root 169K 7月 27 14:11 oniguruma-6.7.0-1.el7.x86_64.rpm
-rw-r--r--. 1 root 35K 7月 27 14:11 oniguruma-devel-6.7.0-1.el7.x86_64.rpm
-rw-r--r--. 1 root 14M 7月 27 14:12 php-5.3.6.tar.gz
tar -xf php-5.3.6.tar.gz -C /usr/local/
cd /usr/local/php-5.3.6/
./configure \
--prefix=/usr/local/php --with-config-file-path=/etc \
--enable-fpm --with-gd --with-mhash --with-iconv --with-zlib \
--with-curl --with-openssl --with-mcrypt=/usr/local/include/ \
--with-gettext --with-xmlrpc --with-jpeg-dir --with-freetype-dir \
--enable-ftp --enable-zip --enable-xml --enable-soap \
--enable-pcntl --enable-mbstring --enable-sockets \
--enable-session --enable-opcache --enable-mbregex --enable-gd-native-ttf \
--enable-shmop --enable-shared --enable-bcmath --enable-inline-optimization \
--enable-sysvsem --without-pear --without-gdbm \
--disable-fileinfo --disable-debug --disable-rpath
make
make test 大概要等10分钟左右
make install
出现下图说明编译完成一半。
[root@localhost php-5.3.6]# vim /etc/profile
PATH=$PATH:/usr/local/php/bin
export PATH
[root@localhost php-5.3.6]# source /etc/profile
[root@localhost php-5.3.6]# php -version
PHP 5.3.6 (cli) (built: Jul 27 2023 16:57:53)
Copyright (c) 1997-2011 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies
make test 输出结果如下:
configure 报错
报错1:
configure: error: libjpeg.(a|so) not found.
报错2::
configure: error: libpng.(a|so) not found.
报错3:
configure: error: freetype.h not found.
报错4:
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
·
make 报错1
/usr/local/php-5.3.6/ext/dom/node.c: 在函数‘dom_canonicalization’中:
/usr/local/php-5.3.6/ext/dom/node.c:1903:21: 错误:提领指向不完全类型的指针
make 报错2
/usr/bin/ld: cannot find -lltdl
collect2: error: ld returned 1 exit status
make: *** [sapi/cli/php] 错误 1
make: *** 正在等待未完成的任务…
/usr/bin/ld: cannot find -lltdl
collect2: error: ld returned 1 exit status
configure 处理报错1:
[root@localhost ~]# find / -name 'libjpeg*'
/usr/lib64/libjpeg.so.62
/usr/lib64/libjpeg.so.62.1.0
/usr/lib64/libjpeg.so
[root@localhost ~]# cp -frp /usr/lib64/libjpeg* /usr/lib/
configure 处理报错2: 不用管有多少,通通cp过去
[root@localhost ~]# find / -name 'libpng*'
/usr/lib64/libpng15.so.15
/usr/lib64/libpng15.so.15.13.0
/usr/lib64/libpng.so.3
/usr/lib64/libpng.so.3.50.0
/usr/lib64/libpng12.so.0
/usr/lib64/libpng12.so.0.50.0
/usr/lib64/libpng.so
/usr/lib64/libpng15.so
[root@localhost ~]# cp -frp /usr/lib64/libpng* /usr/lib/
configure 处理报错3:
[root@localhost ~]# yum install freetype-devel -y
configure 处理报错4:
[root@localhost ~]# tar -xf libmcrypt-2.5.7.tar.gz -C /usr/local/
[root@localhost ~]# cd /usr/local/libmcrypt-2.5.7
./configure
make
make install
make 处理报错1:
新建一个下面的文件,将下面所有复制到这个文件中
[root@localhost php-5.3.6]# vim php-5.3.6-xmlBuf-error.patch
--- ext/dom/node.c 2012-08-06 17:49:48.826716692 +0800
+++ ext/dom/node.c 2012-08-06 17:52:47.633484660 +0800
@@ -1895,9 +1895,17 @@ static void dom_canonicalization(INTERNA
RETVAL_FALSE;
} else {
if (mode == 0) {
+#ifdef LIBXML2_NEW_BUFFER
+ ret = xmlOutputBufferGetSize(buf);
+#else
ret = buf->buffer->use;
+#endif
if (ret > 0) {
+#ifdef LIBXML2_NEW_BUFFER
+ RETVAL_STRINGL((char *) xmlOutputBufferGetContent(buf), ret, 1);
+#else
RETVAL_STRINGL((char *) buf->buffer->content, ret, 1);
+#endif
} else {
RETVAL_EMPTY_STRING();
}
--- ext/dom/documenttype.c 2012-08-06 18:02:16.019640870 +0800
+++ ext/dom/documenttype.c 2012-08-06 18:06:16.612228905 +0800
@@ -205,7 +205,13 @@ int dom_documenttype_internal_subset_rea
if (buff != NULL) {
xmlNodeDumpOutput (buff, NULL, (xmlNodePtr) intsubset, 0, 0, NULL);
xmlOutputBufferFlush(buff);
+
+#ifdef LIBXML2_NEW_BUFFER
+ ZVAL_STRINGL(*retval, xmlOutputBufferGetContent(buff),
+ xmlOutputBufferGetSize(buff), 1);
+#else
ZVAL_STRINGL(*retval, buff->buffer->content, buff->buffer->use, 1);
+#endif
(void)xmlOutputBufferClose(buff);
return SUCCESS;
}
--- ext/simplexml/simplexml.c 2012-08-06 18:10:44.621017026 +0800
+++ ext/simplexml/simplexml.c 2012-08-06 18:12:48.016270419 +0800
@@ -1417,7 +1417,12 @@ SXE_METHOD(asXML)
xmlNodeDumpOutput(outbuf, (xmlDocPtr) sxe->document->ptr, node, 0, 0, ((xmlDocPtr) sxe->document->ptr)->encoding);
xmlOutputBufferFlush(outbuf);
+#ifdef LIBXML2_NEW_BUFFER
+ RETVAL_STRINGL((char *)xmlOutputBufferGetContent(outbuf),
+ xmlOutputBufferGetSize(outbuf), 1);
+#else
RETVAL_STRINGL((char *)outbuf->buffer->content, outbuf->buffer->use, 1);
+#endif
xmlOutputBufferClose(outbuf);
}
} else {
[root@localhost php-5.3.6]# yum -y install patch
[root@localhost php-5.3.6]# patch -p0 -b < ./php-5.3.6-xmlBuf-error.patch
patching file ext/dom/node.c
Hunk #1 succeeded at 1900 (offset 5 lines).
patching file ext/dom/documenttype.c
patching file ext/simplexml/simplexml.c
Hunk #1 succeeded at 1387 (offset -30 lines).
看到 succeeded 为成功。
make 报错2:
yum install libtool-ltdl-devel glibc-static
安装扩展模块
[root@192 local]# yum install php-pear -y
[root@192 local]# yum -y install php-devel
安装/usr/local/php-5.3.6/ext/目录下的模块使用如下方式
[root@192 localhost]# cd /usr/local/php-5.3.6/ext/bz2
[root@192 bz2]# phpize
[root@192 bz2]# ./configure --with-php-config=/usr/local/php/bin/php-config
[root@192 bz2]# make && make install
[root@192 localhost]# vim /etc/php.ini
extension=bz2.so
[root@192 localhost]# cd /usr/local/php/sbin/
[root@192 sbin]# ./php-fpm
#### 报错
[28-Jul-2023 15:45:29] ERROR: Unable to open file '/usr/local/php/etc/php-fpm.conf', errno=2
[28-Jul-2023 15:45:29] ERROR: failed to load configuration file '/usr/local/php/etc/php-fpm.conf'
#### 处理
[root@192 sbin]# more /usr/local/php/etc/php-fpm.conf
/usr/local/php/etc/php-fpm.conf: 没有那个文件或目录
[root@192 sbin]# find / -name 'php-fpm.conf'
/usr/local/php-5.3.6/sapi/fpm/php-fpm.conf
[root@192 sbin]# cp /usr/local/php-5.3.6/sapi/fpm/php-fpm.conf /usr/local/php/etc/
[root@192 sbin]# ./php-fpm
#### 报错
[28-Jul-2023 15:46:03] ALERT: [pool www] pm.min_spare_servers(0) must be a positive value
[28-Jul-2023 15:46:03] ERROR: failed to post process the configuration
#### 处理
[root@192 sbin]# vi /usr/local/php/etc/php-fpm.conf
pm.start_servers=20
pm.min_spare_servers=5
pm.max_spare_servers=35
[root@192 sbin]# ./php-fpm
[root@192 sbin]# ln -s /usr/local/php/sbin/php-fpm /usr/bin/
[root@192 sbin]# php -m | grep bz2
## 模块已安装
systemctl 管理 php-fpm
vim /usr/lib/systemd/system/php-fpm.service
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target
[Service]
Type=forking
ExecStart=/usr/local/php/sbin/php-fpm
ExecReload=/bin/kill -USR2 $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
# 重新加载systemctl
systemctl daemon-reload
# 将刚刚启动的php-fpm kill 掉
[root@localhost sbin]# kill -9 `ps -ef | grep php-fpm |grep -v grep | awk '{print $2}'`
[root@192 sbin]# systemctl start php-fpm.service
[root@192 sbin]# systemctl status php-fpm.service
安装 gd 模块
yum -y install php-gd