下載並安裝libmcrypt 和 libmcrypt-devel
[root@test /opt/soft]# wget ftp://ftp.pbone.net/mirror/ftp5.gwdg.de/pub/opensuse/repositories/home:/csbuild:/centosextra/CentOS_CentOS-6/x86_64/libmcrypt-devel-2.5.8-4.3.x86_64.rpm [root@test /opt/soft]# wget ftp://ftp.pbone.net/mirror/ftp5.gwdg.de/pub/opensuse/repositories/home:/csbuild:/centosextra/CentOS_CentOS-6/x86_64/libmcrypt-2.5.8-4.3.x86_64.rpm [root@test /opt/soft]# rpm -ivh libmcrypt-* warning: libmcrypt-2.5.8-4.3.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 04b8b50a: NOKEY Preparing... ########################################### [100%] 1:libmcrypt ########################################### [ 50%] 2:libmcrypt-devel ########################################### [100%]
建議:使用yum源epel來安裝 libmcypt 和 libmcypt-devel,推薦使用aliyun的yum源
[epel]
name=epel
mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=epel-$releasever&arch=$basearch
enabled=1
gpgcheck=0
安裝開發工具組和必要的編譯軟件包
[root@test /opt/soft]# yum groupinstall -y "Development Tools"
[root@test /opt/soft]# yum -y install autoconf automake bzip2 bzip2-devel curl curl curl-devel e2fsprogs e2fsprogs-devel freetype freetype-devel gcc gcc-c++ gd gettext glib2 glib2-devel glibc glibc-devel krb5-devel krb5-libs krb5-workstation libiconv libiconv-devel libidn libidn-devel libjpeg-turbo libjpeg-turbo-devel libpng libpng-devel libxslt libxslt-devel libxml2 libxml2-devel libXpm libXpm-devel mhash mhash-devel ncurses ncurses-devel nss-pam-ldapd openldap openldap-clients openldap-devel openldap-servers openssl openssl-devel t1lib t1lib-devel zlib zlib-devel
[root@test /opt]# wget http://cn2.php.net/distributions/php-5.3.29.tar.gz
[root@test /opt]# tar xf php-5.3.29.tar.gz
[root@test /opt/php-5.3.29]# ./configure --prefix=/usr/local/php --disable-rpath --enable-bcmath --enable-calendar --enable-dba --enable-debug --enable-embed=fpm --enable-exif --enable-fpm --enable-ftp --enable-gd-jis-conv --enable-gd-native-ttf --enable-inline-optimization --enable-intl=shared --enable-maintainer-zts --enable-mbregex --enable-mbstring --enable-pcntl --enable-pdo --enable-shmop --enable-short-tags --enable-soap --enable-sockets --enable-static --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --enable-xml --enable-zend-multibyte --enable-zip --infodir=/usr/local/share/info --mandir=/usr/local/share/man --with-bz2 --with-config-file-path=/usr/local/php/etc --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-imap --with-imap-ssl --with-jpeg-dir --with-kerberos --with-libxml-dir --with-mcrypt --with-mhash --with-mysql=/usr/local/mysql --with-openssl --with-pcre-regex --with-pear --with-png-dir --with-t1lib --with-xmlrpc --with-xpm-dir --with-xsl --with-zlib --with-fpm-user=nginx --with-fpm-group=nginx
這裏須要注意的是--with-mysql這個參數:
若是不指定,php默認使用php自帶mysql庫文件即--with-mysql=mysqldn,
若是指定,就須要賦予mysql的base目錄路徑。(--with-mysqli 和 --with-pdo-mysql 後面以擴展的方式安裝)
可能遇到的一些錯誤:php
1. configure: error: utf8_mime2text() has new signature, but U8T_CANONICAL is missing
這個是因爲編譯加入了imap支持須要使用c-client庫
解決方法:
[root@test /opt/php-5.3.29]# yum install -y libc-client libc-client-devel
2. configure: error: libXpm.(a|so) not found.
解決方法:
[root@test /opt/php-5.3.29]# ln -s /usr/lib64/libXpm.so* /usr/lib/
Cannot find imap library (libc-client.a).
解決方法:
[root@test /opt/php-5.3.29]# ln -s /usr/lib64/libc-client.so* /usr/lib/
3. configure: error: Unable to detect ICU prefix or no failed. Please verify ICU install prefix and make sure icu-config works.
解決方法:
[root@test /opt/php-5.3.29]# yum install libicu-devel libicu
4. [...]/sapi/cli/php:error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory
解決方法:
[root@test /opt/php-5.3.29]# ln -s 【mysql的base目錄】/lib/libmysqlclient.so.18 /usr/lib64/libmysqlclient.so.18
或
[root@test /opt/php-5.3.29]# echo "【mysql的base目錄】/lib/libmysqlclient.so.18" > /etc/ld.so.conf.d/mysql-x86_64.conf
[root@test /opt/php-5.3.29]# ldconfig
... configure: creating ./config.status creating main/internal_functions.c creating main/internal_functions_cli.c +--------------------------------------------------------------------+ | License: | | This software is subject to the PHP License, available in this | | distribution in the file LICENSE. By continuing this installation | | process, you are bound by the terms of this license agreement. | | If you do not agree with the terms of this license, you must abort | | the installation process at this point. | +--------------------------------------------------------------------+ Thank you for using PHP. config.status: creating php5.spec config.status: creating main/build-defs.h config.status: creating scripts/phpize config.status: creating scripts/man1/phpize.1 config.status: creating scripts/php-config config.status: creating scripts/man1/php-config.1 config.status: creating sapi/cli/php.1 config.status: creating sapi/fpm/php-fpm.conf config.status: creating sapi/fpm/init.d.php-fpm config.status: creating sapi/fpm/php-fpm.service config.status: creating sapi/fpm/php-fpm.8 config.status: creating sapi/fpm/status.html config.status: creating sapi/cgi/php-cgi.1 config.status: creating ext/phar/phar.1 config.status: creating ext/phar/phar.phar.1 config.status: creating main/php_config.h config.status: executing default commands
[root@test /opt/php-5.3.29]# make install
編譯時可能出現的錯誤:--(這種狀況出如今使用mysql的二進制包,沒有找到庫文件libmysqlclient.so.18)
/opt/php-5.3.29/sapi/cli/php: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or director
make: *** [ext/phar/phar.phar] Error 127
[root@test /opt/php-5.3.29]#
[root@test /usr/local/mysql/lib]# ln -s /usr/local/mysql/lib/libmysqlclient.so.18.1.0 /usr/lib/libmysqlclient.so
[root@test /usr/local/mysql/lib]# ln -s /usr/local/mysql/lib/libmysqlclient.so.18.1.0 /usr/lib/libmysqlclient.so.18
[root@test /usr/local/mysql/lib]# ln -s /usr/local/mysql/lib/libmysqlclient.so.18.1.0 /usr/lib64/libmysqlclient.so
[root@test /usr/local/mysql/lib]# ln -s /usr/local/mysql/lib/libmysqlclient.so.18.1.0 /usr/lib64/libmysqlclient.so.18
[root@test /usr/lib]# ldconfig
清理已經編譯過文件,從新編譯
[root@test /opt/php-5.3.29]# make clean;make
PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled.
... Installing shared extensions: /usr/local/php/lib/php/extensions/debug-zts-20131226/ Installing PHP CLI binary: /usr/local/php/bin/ Installing PHP CLI man page: /usr/local/share/man/man1/ Installing PHP FPM binary: /usr/local/php/sbin/ Installing PHP FPM config: /usr/local/php/etc/ Installing PHP FPM man page: /usr/local/share/man/man8/ Installing PHP FPM status page: /usr/local/php/php/php/fpm/ Installing PHP CGI binary: /usr/local/php/bin/ Installing PHP CGI man page: /usr/local/share/man/man1/ Installing build environment: /usr/local/php/lib/php/build/ Installing header files: /usr/local/php/include/php/ Installing helper programs: /usr/local/php/bin/ program: phpize program: php-config Installing man pages: /usr/local/share/man/man1/ page: phpize.1 page: php-config.1 Installing PEAR environment: /usr/local/php/lib/php/ [PEAR] Archive_Tar - installed: 1.4.0 [PEAR] Console_Getopt - installed: 1.4.1 [PEAR] Structures_Graph- installed: 1.1.1 [PEAR] XML_Util - installed: 1.3.0 [PEAR] PEAR - installed: 1.10.1 Wrote PEAR system config file at: /usr/local/php/etc/pear.conf You may want to add: /usr/local/php/lib/php to your php.ini include_path /opt/php-5.6.21/build/shtool install -c ext/phar/phar.phar /usr/local/php/bin ln -s -f phar.phar /usr/local/php/bin/phar Installing PDO headers: /usr/local/php/include/php/ext/pdo
編譯安裝memcache擴展,此步驟非必須: wget http://pecl.php.net/get/memcache-2.2.7.tgz tar xf memcache-2.2.7.tar.gz cd memcache-2.2.7 /usr/local/php/bin/phpize ./configure --with-php-config=/usr/local/php/bin/php-config make make install
編譯安裝eaccelerator擴展
wget http://ufpr.dl.sourceforge.net/project/eaccelerator/eaccelerator/eAccelerator%200.9.6.1/eaccelerator-0.9.6.1.zip
tar xf eaccelerator-0.9.6.1.tar.bz2
cd eaccelerator-0.9.6.1
/usr/local/php/bin/phpiz
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install
編譯安裝mysqli
cd php-5.3.29/ext/mysqli
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install
編譯安裝pdo_mysql
wget http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz
/usr/local/php/bin/phpiz
./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr
make
make install
設置php.ini文件,這裏須要注意的是,由於在編譯時,我修改了php配置文件目錄路徑,因此存放時要放在編譯時制定的目錄--with-config-file-path=/usr/local/php/etc,而不是默認目錄:html
查看默認目錄:
[root@test /opt/php-5.3.29]# ./configure --help | grep -B 1 php.ini --with-config-file-path=PATH Set the path in which to look for php.ini [PREFIX/lib]
拷貝到制定的配置文件目錄中:
[root@test /opt/php-5.3.29]# cp php.ini-production /usr/local/php/etc/php.ini
編輯Nginx配置文件,添加如下配置(藍色部份內容):mysql
[root@test /usr/local/nginx]# egrep -v "^$|#" conf/nginx.conf user nginx; worker_processes 2; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; server_name localhost; location / { root html; index index.html index.htm; } location ~* \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_script_name; include fastcgi_params; }
error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } }
PS: nginx的SPEC打包安裝:http://www.cnblogs.com/jonsea/p/5481580.htmlnginx
mysql 5.7.12安裝:http://www.cnblogs.com/jonsea/p/5503267.htmlc++
製做服務腳本並啓動php-fpm:web
[root@test /opt/php-5.3.29]# cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
[root@test /opt/php-5.3.29]# chmod 755 /etc/rc.d/init.d/php-fpm [root@test /opt/php-5.3.29]# /etc/init.d/php-fpm start Starting php-fpm done
[root@test /opt/php-5.3.29]# ps -ef | grep php-fpm root 9410 1 0 17:53 ? 00:00:00 php-fpm: master process (/usr/local/php/etc/php-fpm.conf) nobody 9411 9410 0 17:53 ? 00:00:00 php-fpm: pool www nobody 9412 9410 0 17:53 ? 00:00:00 php-fpm: pool www
[root@test ~]# netstat -anlp | grep php-fpm
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 9533/php-fpm
[root@test /opt/php-5.3.29]# /etc/init.d/php-fpm stop
Gracefully shutting down php-fpm . done
[root@test /opt/php-5.3.29]# chkconfig --add php-fpm --level 35
#!/bin/bash # php-fpm startup script for php-fpm # # chconfig: - 82 14 # processname: php-fpm # ### BEGIN INIT INFO # Default-Start : 3 5 # Default-Sop: 0 1 2 4 6 # Short-Description: start and stop php-fpm ### END INIT INFO # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ "$NETWORKING" = "no" ] && exit 0 phpfpm="/usr/local/php/sbin/php-fpm" prog=$(basename ${phpfpm}) lockfile=/var/lock/subsys/phpfpm start() { [ -x ${phpfpm} ] || exit 5 echo -n $"Starting $prog: " daemon ${phpfpm} retval=$? echo [ $retval -eq 0 ] && touch $lockfile return $retval } stop() { echo -n $"Stopping $prog: " killproc $prog -QUIT retval=$? echo [ $retval -eq 0 ] && rm -f $lockfile return $retval } restart() { configtest || return $? stop start } reload() { configtest || return $? echo -n $"Reloading $prog: " killproc ${phpfpm} -HUP RETVAL=$? echo } force_reload() { restart } configtest() { ${phpfpm} -t } rh_status() { status $prog } rh_status_q() { rh_status >/dev/null 2>&1 } case "$1" in start) rh_status_q && exit 0 $1 ;; stop) rh_status_q || exit 0 $1 ;; restart|configtest) $1 ;; reload) rh_status_q || exit 7 $1 ;; status) rh_status ;; *) echo $"Usage: $0 {start|stop|status|restart|reload|configtest}" exit 2 esac
[root@test /opt/php-5.3.29]# /etc/init.d/fpm start Starting php-fpm: [ OK ] [root@test /opt/php-5.3.29]# ps -ef | grep php-fpm root 9473 1 0 18:04 ? 00:00:00 php-fpm: master process (/usr/local/php/etc/php-fpm.conf) nobody 9474 9473 0 18:04 ? 00:00:00 php-fpm: pool www nobody 9475 9473 0 18:04 ? 00:00:00 php-fpm: pool www [root@test /opt/php-5.3.29]# /etc/init.d/fpm stop Stopping php-fpm: [ OK ]
web測試代碼和mysql測試代碼sql
[root@test /usr/local/nginx/html]# cat t.php <?php phpinfo(); ?> [root@test /usr/local/nginx/html]# cat m.php <?php $link=mysql_connect("localhost","root","【你的mysql帳戶密碼】"); if(!$link) echo "FAILD!鏈接錯誤,用戶名密碼不對"; else echo "OK!能夠鏈接"; ?>
測試經過!!!數據庫