【介绍】
由于某些程序不支持php5.2以上的版本,需要安装php5.2.17和ZendOptimizer3.3.9。
参考:http://kimsom.com/article/363
下载:http://pan.baidu.com/s/1hrLA4gW
【依赖】
综合:
yum install yum-utils perl dos2unix apr apr-devel apr-util apr-util-devel curl curl-devel libcurl libcurl-devel wget gcc gcc-c++ flex git zip icu unzip libtiff-devel pam-devel libtool libtool-ltdl libtool-ltdl-devel bison bison-devel libxslt libxslt-devel ncurses ncurses-devel bzip2 bzip2-devel bzip2-libs libpsl libicu libjpeg libjpeg-devel unixODBC-devel net-snmp net-snmp-devel openldap-devel openldap-servers openldap-clients mhash-devel readline-devel libedit-devel sqlite-devel libffi libffi-devel guile guile-devel gmp gmp-devel gettext gettext-devel libidn libidn-devel unbound unbound-devel help2man texlive gtk-doc texinfo autogen autoconf mailcap git2cl gperf libev libev-devel jemalloc jemalloc-devel Cython setuptool trousers trousers-devel python python-devel patch
【安装:Apache 2.2.32】
下载:http://archive.apache.org/dist/httpd/
安装 Apache 2.2.32 (2017-01-13):
wget http://archive.apache.org/dist/httpd/httpd-2.2.32.tar.gz && tar -zxvf httpd-2.2.32.tar.gz && cd httpd-2.2.32 ./configure --prefix=/usr/local/apache2 --enable-so --enable-mods-shared=most --with-crypto --enable-rewrite --enable-headers --enable-deflate --enable-socache-shmcb --enable-negotiation --enable-ssl --with-ssl=/usr/lib make && make install
查看版本:
/usr/local/apache2/bin/httpd -v
输出:
Server version: Apache/2.2.32 (Unix) Server built: Mar 20 2018 08:37:43
安装CGI支持:
cd modules/generators /usr/local/apache2/bin/apxs -i -a -c mod_cgi.c /usr/local/apache2/bin/apxs -i -a -c mod_cgid.c
查看下配置文件 httpd.conf ,发现cgi与cgid模块已被加载:
... LoadModule cgi_module modules/mod_cgi.so LoadModule cgid_module modules/mod_cgid.so
创建 apache 用户:
groupadd apache && useradd -g apache -s /sbin/nologin -M apache
设置启动命令:
将Apache设成系统服务:
cp /usr/local/apache2/bin/apachectl /etc/init.d/httpd
编辑 /etc/init.d/httpd,在第二行加入:
# chkconfig: 2345 85 15 # description: httpd is web server
把Apache添加到系统的启动服务组里:
chkconfig --add httpd && chkconfig --level 35 httpd on
输入命令:
service httpd start
输出:
httpd: Could not reliably determine the server's fully qualified domain name, using vultr.guest for ServerName
没关系,这是因为没有在httpd.conf中设置主机名,在后面再处理。
设为开机启动:
chkconfig httpd on
编译安装完成。
【安装:MySQL】
【安装:PHP 5.2.17】
安装系统环境需要的软件:
yum install gcc gcc-c++ autoconf libmcrypt libmcrypt-devel libmhash libmhash-devel libjpeg libjpeg-devel libpng libpng-devel gd gd-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5-libs krb5-devel krb5-server libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers
编译安装libiconv:
编译安装mcrypt:
编译安装PHP-5.2.17:
下载:http://php.net/releases/index.php
参考:http://serverfault.com/questions/272241/apache2-and-php5-wont-work-together
wget http://museum.php.net/php5/php-5.2.17.tar.gz && tar zxvf php-5.2.17.tar.gz
或:
wget http://museum.php.net/php5/php-5.2.17.tar.bz2 && tar jxvf php-5.2.17.tar.bz2
打补丁:
参考:http://bbs.chinaunix.net/archiver/tid-3668293.html
参考:https://sourceforge.net/projects/mapn/
yum install patch
wget http://php-fpm.org/downloads/php-5.2.17-fpm-0.5.14.diff.gz && gzip -cd php-5.2.17-fpm-0.5.14.diff.gz | patch -d php-5.2.17 -p1 wget https://downloads.sourceforge.net/project/mapn/patch/php-5.2.17-max-input-vars.patch && cd php-5.2.17 && patch -p1 < ../php-5.2.17-max-input-vars.patch sed -i "s/\!png_check_sig (sig, 8)/png_sig_cmp (sig, 0, 8)/" ext/gd/libgd/gd_png.c && ln -s /usr/lib64/libjpeg.so /usr/lib/libjpeg.so && ln -s /usr/lib64/libpng.so /usr/lib/libpng.so
参考:http://www.cnblogs.com/antarctican/p/3752812.html
参考:http://stackoverflow.com/questions/12671148/compile-php-with-ldap
ln -s /usr/lib64/liblber* /usr/lib/ cp -frp /usr/lib64/libldap* /usr/lib/
cd php-5.2.17 curl -o php-5.2.17.patch https://mail.gnome.org/archives/xml/2012-August/txtbgxGXAvz4N.txt && patch -p0 -b < php-5.2.17.patch
参考:
cd php-5.2.17 && curl -o php-5.x.x.patch https://mail.gnome.org/archives/xml/2012-August/txtbgxGXAvz4N.txt && patch -p0 -b < php-5.x.x.patch
参考:http://www.cnblogs.com/hojor/p/3230739.html
参考:http://blog.csdn.net/wildwild1/article/details/7763644
参考:https://forums.cpanel.net/threads/easy-apache-compile-error-with-enable-extention-mysqli-on-cloudlinux.362552/
参考:https://www.webmasterworld.com/forum88/7177.htm
参考:http://blog.sina.com.cn/s/blog_66e4076401011z0s.html
参考:https://forums.cpanel.net/threads/easy-apache-compile-error-with-enable-extention-mysqli-on-cloudlinux.362552/
参考:http://stackoverflow.com/questions/20266246/unable-to-compile-php-5-2-with-mysqli-extension
开始编译PHP:
确认curl位置:
whereis curl
输出:
curl: /usr/bin/curl /usr/include/curl
开始编译:
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql/ --with-iconv-dir=/usr/local --with-apxs2=/usr/local/apache2/bin/apxs --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl=/usr/bin/curl --with-curlwrappers --enable-mbregex --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap --with-mysqli=/usr/local/mysql/bin/mysql_config make ZEND_EXTRA_LIBS='-liconv' make install
【排错】
报错:error while loading shared libraries: libiconv.so.2: cannot open shared object file: No such file or directory
首先确认自己的系统中是否存在这个动态链接库:
sudo find / -name libiconv.so.2
如果找不到文件路径,请安装libiconv:
如果找到libiconv.so.2文件路径,可以将此文件添加到ld.so.conf最上面
sudo vim /etc/ld.so.conf
然后运行ldconfig文件:
sudo /sbin/ldconfig
报错:dlname not found in /usr/local/apache2/modules/libphp5.la.
Installing PHP SAPI module: apache2handler /usr/local/apache2/build/instdso.sh SH_LIBTOOL='/usr/lib64/apr-1/build/libtool' libphp5.la /usr/local/apache2/modules /usr/lib64/apr-1/build/libtool --mode=install cp libphp5.la /usr/local/apache2/modules/ libtool: install: cp .libs/libphp5.lai /usr/local/apache2/modules/libphp5.la libtool: install: cp .libs/libphp5.a /usr/local/apache2/modules/libphp5.a libtool: install: chmod 644 /usr/local/apache2/modules/libphp5.a libtool: install: ranlib /usr/local/apache2/modules/libphp5.a libtool: install: warning: remember to run `libtool --finish /root/php-5.2.17/libs' Warning! dlname not found in /usr/local/apache2/modules/libphp5.la. Assuming installing a .so rather than a libtool archive. chmod 755 /usr/local/apache2/modules/libphp5.so chmod: cannot access ‘/usr/local/apache2/modules/libphp5.so’: No such file or directory apxs:Error: Command failed with rc=65536 . make: *** [install-sapi] Error 1
参考:https://www.linuxquestions.org/questions/linux-software-2/cannot-access-%60-usr-local-apache2-modules-libphp5-so%27-384689/
参考:http://hudeyong926.iteye.com/blog/1059390
参考:https://bugs.php.net/bug.php?id=27795#c83708
如果没有先安装MySQL,不能启用mysqli:
ext/mysqli/mysqli.o: In function `php_local_infile_init': /root/php-5.2.17/ext/mysqli/mysqli.c:1064: undefined reference to `client_errors ' ext/mysqli/mysqli.o: In function `php_local_infile_read': /root/php-5.2.17/ext/mysqli/mysqli.c:1113: undefined reference to `client_errors ' ext/mysqli/mysqli.o: In function `php_local_infile_error': /root/php-5.2.17/ext/mysqli/mysqli.c:1175: undefined reference to `client_errors ' collect2: error: ld returned 1 exit status make: *** [sapi/cli/php] Error 1
那么去掉:
--with-mysqli=/usr/local/mysql/bin/mysql_config
参考:http://stackoverflow.com/questions/20266246/unable-to-compile-php-5-2-with-mysqli-extension
参考:http://blog.sina.com.cn/s/blog_67dd1efa0100jkkn.html
参考:http://blog.csdn.net/suppress/article/details/5329810
cp php.ini-dist /usr/local/php/etc/php.ini
第四步:编译安装PHP5扩展模块
编译安装memcache
官网:http://www.php.net/memcache
下载:https://pecl.php.net/package/memcache
wget https://pecl.php.net/get/memcache-2.2.6.tgz && tar zxvf memcache-2.2.6.tgz && cd memcache-2.2.6 /usr/local/php/bin/phpize ./configure --with-php-config=/usr/local/php/bin/php-config make && make install
编译安装eaccelerator
官网:http://eaccelerator.net/
下载:https://sourceforge.net/projects/eaccelerator/files/eaccelerator/
wget https://sourceforge.net/projects/eaccelerator/files/eaccelerator/eAccelerator%200.9.6.1/eaccelerator-0.9.6.1.tar.bz2 && tar jxvf eaccelerator-0.9.6.1.tar.bz2 && cd eaccelerator-0.9.6.1 /usr/local/php/bin/phpize ./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php/bin/php-config --without-eaccelerator-use-inode make && make install
编译安装PDO_MYSQL
官网:http://php.net/pdo
下载:https://pecl.php.net/package/PDO
wget http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz && tar zxvf PDO_MYSQL-1.0.2.tgz && cd PDO_MYSQL-1.0.2 /usr/local/php/bin/phpize ./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql/ make && make install
参考:http://www.92csz.com/30/1232.html
编译安装ImageMagick
官网:https://sourceforge.net/projects/imagemagick/
下载:https://sourceforge.net/projects/imagemagick/files/
wget https://jaist.dl.sourceforge.net/project/imagemagick/old-sources/6.x/6.8/ImageMagick-6.8.8-10.tar.gz && tar zxvf ImageMagick-6.8.8-10.tar.gz && cd ImageMagick-6.8.8-10 ./configure && make && make install ln -s /usr/local/include/ImageMagick-6 /usr/local/include/ImageMagick
编译安装imagick
官网:http://php.net/imagick
下载:https://pecl.php.net/package/imagick
wget https://pecl.php.net/get/imagick-3.0.1.tgz && tar zxvf imagick-3.0.1.tgz && cd imagick-3.0.1 /usr/local/php/bin/phpize && ./configure --with-php-config=/usr/local/php/bin/php-config make && make install
第五步:修改php.ini文件
sed -i "s/output_buffering = Off/output_buffering = On/" /usr/local/php/etc/php.ini sed -i "s/extension_dir =/; extension_dir =/" /usr/local/php/etc/php.ini sed -i "s/; cgi.fix_pathinfo=0/cgi.fix_pathinfo=0/" /usr/local/php/etc/php.ini sed -i 's%;open_basedir =%open_basedir ="/tmp/:/usr/local/apache2/htdocs/"%' /usr/local/php/etc/php.ini sed -i "s/disable_functions =/disable_functions = popen,pentl_exec,passthru,exec,system,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,pfsockopen,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,show_source,escapeshellcmd,escapeshellarg,curl_exec,curl_multi_exec,parse_ini_file,assert/" /usr/local/php/etc/php.ini sed -i "s/expose_php = On/expose_php = Off/" /usr/local/php/etc/php.ini sed -i "s/display_errors = On/display_errors = Off/" /usr/local/php/etc/php.ini sed -i "s/log_errors = Off/log_errors = On/" /usr/local/php/etc/php.ini
创建apache用户及启动php-fpm并加入启动脚本
/usr/sbin/groupadd apache /usr/sbin/useradd -g apache apache chown -R apache:apache /usr/local/apache2/htdocs chmod +w /usr/local/apache2/htdocs
注:这里的/usr/local/apache2/htdocs/是网站目录,可以根据实际情况修改。
第七步:安装ZendOptimizer 3.3.9
解压ZendOptimizer 3.3.9,并复制ZendOptimizer.so到/usr/local/Zend/lib/
wget http://downloads.zend.com/optimizer/3.3.9/ZendOptimizer-3.3.9-linux-glibc23-x86_64.tar.gz tar -zxvf ZendOptimizer-3.3.9-linux-glibc23-x86_64.tar.gz && cd ZendOptimizer-3.3.9-linux-glibc23-x86_64 cd data/5_2_x_comp && mkdir -p /usr/local/Zend/lib && cp ZendOptimizer.so /usr/local/Zend/lib/
注:/usr/local/Zend/lib/这个目录可以自定义。
在/usr/local/php/etc/php.ini文件尾部添加
; [Zend] zend_optimizer.optimization_level=1023 zend_optimizer.encoder_loader=1 zend_extension=/usr/local/Zend/lib/ZendOptimizer.so
安装完成:
添加 php 到系统命令:
ln -s /usr/local/php/bin/php /usr/bin/php
查看PHP版本。
/usr/local/php/bin/php -v php -v
结果如下:
PHP 5.2.17p1 (cli) (built: Mar 30 2021 10:18:18) Copyright (c) 1997-2010 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2010 Zend Technologies with Zend Optimizer v3.3.9, Copyright (c) 1998-2009, by Zend Technologies
安装phpmyadmin