1.4 php5.6安装:

1.4 php5.6安装:

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.ini

[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扩展源(主)

[root@Dasoncheng src]# yum install -y epel-release
[root@Dasoncheng src]# yum makecache
[root@Dasoncheng src]# yum install -y libmcrypt-devel
##安装epel扩展源就可以安装了!

或者,下载mcrypt源:

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的 不能保证来源的安全性;

继续编译php

[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
##安装成功!

查看php安装目录结构!

[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的安装,敬请期待哦……

1.5 php7.安装:

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.ini

[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.的安装也就完成了!

查看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,我们怎么用呢?

##编辑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)

mark

php中mysql,mysqli,mysqlnd,pdo到底是什么 http://blog.csdn.net/u013785951/article/details/60876816
查看编译参数 http://ask.apelearn.com/question/1295

猜你喜欢

转载自my.oschina.net/u/3651233/blog/1622642