最新消息:

debian10安装php5.2.17

学习 林夕 237浏览

debian10安装php5.2.17
以下教程来源于阿里云的一篇教程,按照那个教程,在debian8系统下,直接按命令一条一条操作即可成功。换到debian10系统却遇到拦路虎。
此文算是那篇教程的一个补充,略有修改。

1、下载php5.2.17源码,php-fpm补丁:

cd && wget http://museum.php.net/php5/php-5.2.17.tar.gz
cd && wget http://php-fpm.org/downloads/php-5.2.17-fpm-0.5.14.diff.gz

2、安装patch工具

如未安装patch工具,执行下面第3步打补丁时会有出错提示:-bash: patch: command not found
解决办法:

apt-get install patch

3、解压php5.2.17源码包,且打好php-fpm补丁:

tar -xvzf php-5.2.17.tar.gz
gzip -cd php-5.2.17-fpm-0.5.14.diff.gz | patch -d php-5.2.17 -p1

4、转到php5.2.17的目录,下载php5.2的xml补丁,打上:

cd php-5.2.17
wget https://mail.gnome.org/archives/xml/2012-August/txtbgxGXAvz4N.txt
patch -p0 -b < txtbgxGXAvz4N.txt

5、安装GCC编译器以及编译软件所需的其他库和实用程序

默认的Debian存储库包含一个名为meta的包build-essential,其中包含GCC编译器以及编译软件所需的其他库和实用程序。

apt-get install build-essential

要确认已成功安装GCC编译器,请输入gcc –version:

gcc --version

6、安装依赖库包

编译出错或不能编译,十有八九就是依赖库未安装或安装错误或依赖库版本不对,依赖库最好还是apt方式安装包吧,依赖库还有相关的依赖库,apt包却是自动安装了相关的依赖库,相比源码编译安装省心不少。
安装mcrypt时有如下提示:/usr/bin/rm: cannot remove ‘libtoolT’: No such file or directory
#libtool

apt-get install libtool

#zlib1g-dev

apt-get install zlib1g-dev

#libxml2 libxml2-dev

apt-get install libxml2-dev

#libmcrypt-dev

apt-get install libmcrypt-dev

#mcrypt

apt-get install mcrypt

#libiconv-hook-dev

apt-get install libiconv-hook-dev

#libxslt-dev

apt-get install libxslt-dev

#libbz2-dev

apt-get install libbz2-dev

#libcurl4-openssl-dev

apt-get install libcurl4-openssl-dev

#libmhash-dev

apt-get install libmhash-dev

#libjpeg-dev
从源码编译安装了libjpeg v9,还是提示configure: error: libjpeg.(a|so) not found.
网上找的方法都说安装libjpeg-devel这个包,这个方法是错的,正确的包名是libjpeg-dev,感谢这个链接: https://www.linuxquestions.org/questions/linux-software-2/configure-error-libjpeg-a%7Cso-not-found-903300/
解决办法:

apt-get install libjpeg-dev

#libpng-dev
从源码编译安装了libpng16,还是提示configure: error: libpng.(a|so) not found.
网上找的方法都说安装libpng-devel这个包,这个方法是错的,正确的包名是libpng-dev,
解决办法:

apt-get install libpng-dev

#libcurl
configure: error: Please reinstall the libcurl distribution – easy.h should be in /include/curl/
解决办法:

cd /usr/local/include
ln -s /usr/include/x86_64-linux-gnu/curl curl
apt-get install libcurl4-gnutls-dev

#opensll
编译php时提示:configure: error: Cannot find OpenSSL’s
解决办法:

apt-get install libssl-dev

#添加源以安装适用于5.5.62的旧版本libmysqlclient-dev
不要安装default-libmysqlclient-dev这个包,跟mysql5.5.62不配套,后面编译的时候会出错:
error: ‘MYSQL_PORT’ undeclared (first use in this function); did you mean ‘MYSQL_STMT’?
php-5.2.17/ext/mysql/php_mysql.c:519:36: note: each undeclared identifier is reported only once for each function it appears in
make: *** [Makefile:957: ext/mysql/php_mysql.lo] Error 1
解决办法:

echo "deb http://security.debian.org/debian-security jessie/updates main" >> /etc/apt/sources.list
apt-get update
apt-get install libmysqlclient-dev

7、编译,并安装php5.2.17:

cd && cd php-5.2.17
./configure --prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--enable-fastcgi \
--enable-fpm \
--with-libdir=/lib/x86_64-linux-gnu \
--with-mcrypt \
--enable-mbstring \
--enable-pdo \
--with-curl \
--disable-debug \
--enable-xml \
--with-zlib \
--enable-sockets \
--with-mhash \
--with-gd \
--with-pdo-mysql=/usr/local/mysql \
--with-jpeg-dir=/usr/lib \
--with-png-dir=/usr/lib \
--with-mysql=/usr/local/mysql  \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--with-mysql-sock=/tmp/mysql.sock

8、根据编译时写好的安装路径,调整php-fpm的运行参数,如修改运行用户和用户组,将 php-fpm.conf 的 “Unix user of processes” 和 “Unix group of processes” 代码注释删除,且添加好www-data用户及组

vi /usr/local/php/etc/php-fpm.conf

			Unix user of processes
		<!--	<value name="user">nobody</value>				-->

			Unix group of processes
		<!--	<value name="group">nogroup</value>		-->

修改为:

			Unix user of processes
			<value name="user">www-data</value>				

			Unix group of processes
			<value name="group">www-data</value>		

9、复制php.ini文件到php-fpm的路径:

find / -name 'php.ini*'

(查找php.ini在哪个目录下)

/root/php-5.2.17/php.ini-dist
/root/php-5.2.17/php.ini-recommended

cp /root/php-5.2.17/php.ini-recommended /usr/local/php/etc/php.ini

10、下载、解压 Zend Optimizer

cd && wget http://downloads.zend.com/optimizer/3.3.9/ZendOptimizer-3.3.9-linux-glibc23-x86_64.tar.gz
tar -xzvf ZendOptimizer-3.3.9-linux-glibc23-x86_64.tar.gz

11、复制 ZendOptimizer.so 到相应的扩展目录:

mkdir -p /usr/local/php/lib/php/extensions/no-debug-non-zts-201910012028
find / -name 'ZendOptimizer.so'

(查找ZendOptimizer.so在哪个目录下)

cp /root/ZendOptimizer-3.3.9-linux-glibc23-x86_64/data/5_2_x_comp/ZendOptimizer.so /usr/local/php/lib/php/extensions/no-debug-non-zts-201910012028

12、在 php.ini 里添加一行:

zend_extension=/usr/local/php/lib/php/extensions/no-debug-non-zts-201910012028/ZendOptimizer.so

10. 启动 php-fpm 服务:

/usr/local/php/sbin/php-fpm start
/usr/local/php/sbin/php-fpm restart

11. 在nginx的站点配置中配置相应的php-fpm信息:

location ~ \.php$ {
                include snippets/fastcgi-php.conf;
        #       # With php5-cgi alone:
                fastcgi_pass 127.0.0.1:9000;
        }
}

13、将php-fpm添加为系统服务:

cp /usr/local/php/sbin/php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
update-rc.d php-fpm defaults

14、php命令

php-fpm启动命令:

service php-fpm start

php-fpm停止命令:

service php-fpm stop

php-fpm重启命令:

service php-fpm restart

转载请注明:一秒钟的梦 » debian10安装php5.2.17