PHP官網www.php.net
當前主流版本爲5.6/7.1
cd /usr/local/src/
wget http://cn2.php.net/distributions/php-5.6.30.tar.gz
tar zxf php-6.6.30.tar.gz
cd php-5.6.30
./configure
--prefix=/usr/local/php //指定安裝路徑
--with-apxs2=/usr/local/apache2.4/bin/apxs //apxs工具自動配置加載php到apache配置文件(安裝其擴展模塊)
--with-config-file-path=/usr/local/php/etc //指定php的配置文件!
--with-mysql=/usr/local/mysql //指定mysql路徑(老版本,c7直接拋棄了)
--with-pdo-mysql=/usr/local/mysql //指定mysql路徑
--with-mysqli=/usr/local/mysql/bin/mysql_config //指定mysql路徑:定義mysql相關函數或驅動(這三個mysql都是差很少的)(新版本)
--with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif //指定php須要的一些模塊!
make && make install
cp php.ini-production /usr/local/php/etc/php.iniphp
[root@Dasoncheng ~]# cd /usr/local/src/ [root@Dasoncheng src]# wget http://cn2.php.net/distributions/php-5.6.30.tar.gz [root@Dasoncheng src]# tar -zxf php-5.6.30.tar.gz [root@Dasoncheng src]# ls apr-1.5.2 httpd-2.4.27 php-5.6.30 apr-1.5.2.tar.gz httpd-2.4.27.tar.gz php-5.6.30.tar.gz apr-util-1.5.4 mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz apr-util-1.5.4.tar.gz mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz [root@Dasoncheng src]# cd php-5.6.30 [root@Dasoncheng php-5.6.30]# ./configure \ > --prefix=/usr/local/php \ > --with-apxs2=/usr/local/apache2.4/bin/apxs \ > --with-config-file-path=/usr/local/php/etc \ > --with-mysql=/usr/local/mysql/ \ > --with-pdo-mysql=/usr/local/mysql/ \ > --with-mysqli=/usr/local/mysql/bin/mysql_config \ > --with-libxml-dir \ > --with-gd \ > --with-jpeg-dir \ > --with-freetype-dir \ > --with-iconv-dir \ > --with-zlib-dir \ > --with-bz2 \ > --with-openssl \ > --with-mcrypt \ > --enable-gd-native-ttf \ > --enable-soap \ > --enable-mbstring \ > --enable-sockets \ > --enable-exif …… …… configure: error: xml2-config not found. Please check your libxml2 installation. [root@Dasoncheng php-5.6.30]# yum install -y libxml2-devel openssl-devel bzip2-devel libjpeg-turbo-devel libpng-devel freetype-devel libmcrypt-devel
到這裏2016年你會發現:libmcrypt-devel已經安裝不了了,聽說是由於mcrypt已經版權化了 centos就沒有自帶mcrypt的包了;
那麼,怎麼處理呢?
安裝epel擴展源(主)mysql
[root@Dasoncheng src]# yum install -y epel-release [root@Dasoncheng src]# yum makecache [root@Dasoncheng src]# yum install -y libmcrypt-devel ##安裝epel擴展源就能夠安裝了!
或者,下載mcrypt源:linux
wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/attic/libmcrypt/libmcrypt-2.5.7.tar.gz tar -zxvf libmcrypt-2.5.7.tar.gz cd libmcrypt-2.5.7 mkdir -p /usr/local/libmcrytp ./configure prefix=/usr/local/libmcrytp/ make make install ##不過,ftp的 不能保證來源的安全性;
[root@Dasoncheng php-5.6.30]# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2.4/bin/apxs --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql/ --with-pdo-mysql=/usr/local/mysql/ --with-mysqli=/usr/local/mysql/bin/mysql_config --with-libxml-dir --with-gd --with-jpeg-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-gd-native-ttf --enable-soap --enable-mbstring --enable-sockets --enable-exif …… +--------------------------------------------------------------------+ | 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/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@Dasoncheng php-5.6.30]# echo $? 0 [root@Dasoncheng php-5.6.30]# /usr/local/php/bin/php -i |less phpinfo() PHP Version => 5.6.30 System => Linux localhost.localdomain 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 22 16:42:41 UTC 2016 x86_64 Build Date => Feb 22 2018 06:51:45 Configure Command => './configure' '--prefix=/usr/local/php' '--with-apxs2=/usr/local/apache2.4/bin/apxs' '--with-config-file-path=/usr/local/php/etc' '--with-mysql=/usr/local/mysql/' '--with-pdo-mysql=/usr/local/mysql/' '--with-mysqli=/usr/local/mysql/bin/mysql_config' '--with-libxml-dir' '--with-gd' '--with-jpeg-dir' '--with-freetype-dir' '--with-iconv-dir' '--with-zlib-dir' '--with-bz2' '--with-openssl' '--with-mcrypt' '--enable-gd-native-ttf' '--enable-soap' '--enable-mbstring' '--enable-sockets' '--enable-exif' Server API => Command Line Interface Virtual Directory Support => enabled Configuration File (php.ini) Path => /usr/local/php/etc Loaded Configuration File => /usr/local/php/etc/php.ini …… [root@Dasoncheng php-5.6.30]# /usr/local/php/bin/php -i |grep 'Loaded Configuration File' Loaded Configuration File => /usr/local/php/etc/php.ini ##php的配置文件在這裏,但是目錄/usr/local/php/etc/php.ini裏面沒有 ,咱們須要拷貝一份過去! [root@Dasoncheng php-5.6.30]# ls php.* php.gif php.ini-development php.ini-production [root@Dasoncheng php-5.6.30]# cp php.ini-production /usr/local/php/etc/php.ini ##安裝成功!
[root@Dasoncheng php]# ls /usr/local/php/bin/ pear peardev pecl phar phar.phar php php-cgi php-config phpize [root@Dasoncheng php]# du -sh /usr/local/php/bin/php 36M /usr/local/php/bin/php [root@Dasoncheng php]# du -sh /usr/local/php/bin/ 71M /usr/local/php/bin/ [root@Dasoncheng php]# /usr/local/php/bin/php -m [PHP Modules] bz2 Core ctype date dom ereg exif fileinfo filter gd hash …… [Zend Modules] [root@Dasoncheng php]# /usr/local/apache2.4/bin/apachectl -M AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message Loaded Modules: core_module (static) so_module (static) http_module (static) mpm_event_module (static) authn_file_module (shared) authn_core_module (shared) authz_host_module (shared) authz_groupfile_module (shared) authz_user_module (shared) authz_core_module (shared) access_compat_module (shared) auth_basic_module (shared) reqtimeout_module (shared) filter_module (shared) mime_module (shared) log_config_module (shared) env_module (shared) headers_module (shared) setenvif_module (shared) version_module (shared) unixd_module (shared) status_module (shared) autoindex_module (shared) dir_module (shared) alias_module (shared) php5_module (shared) [root@Dasoncheng php]# ls /usr/local/apache2.4/modules/libphp5.so /usr/local/apache2.4/modules/libphp5.so [root@Dasoncheng php]# du -sh /usr/local/apache2.4/modules/libphp5.so 37M /usr/local/apache2.4/modules/libphp5.so [root@Dasoncheng php]# grep php5_module /usr/local/apache2.4/conf/httpd.conf ##httpd的配置文件裏面已經有了php5模塊了; LoadModule php5_module modules/libphp5.so ##整個php5的安裝 到這裏就結束了哦!
接下來會繼續php7的安裝,敬請期待哦……sql
cd /usr/local/src/
wget http://cn2.php.net/distributions/php-7.1.6.tar.bz2
tar zxf php-7.1.6.tar.bz2
cd php-7.1.6
./configure --prefix=/usr/local/php7 --with-apxs2=/usr/local/apache2.4/bin/apxs --with-config-file-path=/usr/local/php7/etc --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif
make && make install
ls /usr/local/apache2.4/modules/libphp7.so
cp php.ini-production /usr/local/php7/etc/php.iniapache
[root@Dasoncheng ~]# cd /usr/local/src/ [root@Dasoncheng src]# ls apr-1.5.2 httpd-2.4.27.tar.gz apr-1.5.2.tar.gz mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz apr-util-1.5.4 mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz apr-util-1.5.4.tar.gz php-5.6.30 httpd-2.4.27 php-5.6.30.tar.gz [root@Dasoncheng src]# tar -jxf php-7.1.6.tar.bz2 tar (child): bzip2: Cannot exec: No such file or directory tar (child): Error is not recoverable: exiting now tar: Child returned status 2 tar: Error is not recoverable: exiting now [root@Dasoncheng src]# yum provides bzip2 [root@Dasoncheng src]# yum install -y bzip2 [root@Dasoncheng src]# tar -jxf php-7.1.6.tar.bz2 [root@Dasoncheng src]# ls apr-1.5.2 mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz apr-1.5.2.tar.gz mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz apr-util-1.5.4 php-5.6.30 apr-util-1.5.4.tar.gz php-5.6.30.tar.gz httpd-2.4.27 php-7.1.6 httpd-2.4.27.tar.gz php-7.1.6.tar.bz2 [root@Dasoncheng src]# cd php-7.1.6 [root@Dasoncheng php-7.1.6]# ./configure \ > --prefix=/usr/local/php7 \ > --with-apxs2=/usr/local/apache2.4/bin/apxs \ > --with-config-file-path=/usr/local/php7/etc \ > --with-pdo-mysql=/usr/local/mysql \ > --with-mysqli=/usr/local/mysql/bin/mysql_config \ > --with-libxml-dir \ > --with-gd \ > --with-jpeg-dir \ > --with-png-dir \ > --with-freetype-dir \ > --with-iconv-dir \ > --with-zlib-dir \ > --with-bz2 \ > --with-openssl \ > --with-mcrypt \ > --enable-soap \ > --enable-gd-native-ttf \ > --enable-mbstring \ > --enable-sockets \ > --enable-exif +--------------------------------------------------------------------+ | 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 php7.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/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@Dasoncheng php-7.1.6]# echo $? 0 [root@Dasoncheng php-7.1.6]# make && make install …… Wrote PEAR system config file at: /usr/local/php7/etc/pear.conf You may want to add: /usr/local/php7/lib/php to your php.ini include_path /usr/local/src/php-7.1.6/build/shtool install -c ext/phar/phar.phar /usr/local/php7/bin ln -s -f phar.phar /usr/local/php7/bin/phar Installing PDO headers: /usr/local/php7/include/php/ext/pdo/ [root@Dasoncheng php-7.1.6]# echo $? 0 [root@Dasoncheng php-7.1.6]# cp php php7.spec php.gif php.ini-production php7.spec.in php.ini-development [root@Dasoncheng php-7.1.6]# cp php.ini-production /usr/local/php7/etc/php.ini ##到這裏php7.的安裝也就完成了!
[root@Dasoncheng php-7.1.6]# ls /usr/local/apache2.4/modules/libphp7.so /usr/local/apache2.4/modules/libphp7.so [root@Dasoncheng php-7.1.6]# du -sh /usr/local/apache2.4/modules/libphp7.so 37M /usr/local/apache2.4/modules/libphp7.so [root@Dasoncheng php-7.1.6]# /usr/local/apache2.4/bin/apachectl -M |grep php AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message php5_module (shared) php7_module (shared)
那麼如今問題就來了,同時安裝了2個版本的php,咱們怎麼用呢?vim
##編輯httpd.conf,找到php7模塊 前面加上「#」號,註釋掉便可! [root@Dasoncheng php-7.1.6]# vim /usr/local/apache2.4/conf/httpd.conf LoadModule php5_module modules/libphp5.so #LoadModule php7_module modules/libphp7.so [root@Dasoncheng php-7.1.6]# /usr/local/apache2.4/bin/apachectl -M |grep php ##沒有從新加載Apache配置,模塊即停用了哦! php5_module (shared)
php中mysql,mysqli,mysqlnd,pdo究竟是什麼 http://blog.csdn.net/u013785951/article/details/60876816
查看編譯參數 http://ask.apelearn.com/question/1295centos