在Linux下安装PHP5与PHP7共存。 PHP5安装
PHP官网
当前主流版本为5.6/7.1
进入存储源码包的目录: [root@linuxidc ~]# cd /usr/local/src
下载php的源码包:
地址:wget
5.解压压缩包:
[root@linuxidc src]# tar -zxvf php-5.6.30.tar.gz6.进入安装目录:
[root@linuxidc src]# cd php-5.6.30 [root@linuxidc php-5.6.30]#7.安装php:
[root@linuxidc 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-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 [root@linuxidc php-5.6.30]# echo $? //安装完成没有错误用这个检查 0解释说明个别参数:
--prefix:指定安装目录。 --with-apxs2:Apache的工具,指定工具的地址,可以帮我们自动配置一些模块,不用人工干涉。 --with-config-file-path:指定配置文件的路径。 --with-mysql:指定mysql路径。安装报错:
缺少libxml2这个库,安装命令:yum install -y libxml2-devel
缺少openssl库,安装命令:yum install -y openssl-devel
缺少bzip2包,安装命令:yum install -y bzip2-devel
缺少jpeglid包,安装命令:yum install -y libjpeg-devel
缺少libpng包,安装命令:yum install -y libpng-devel
缺少freetype包,安装命令:yum install -y freetype-devel
缺少libmcrypt包,安装命令:yum install -y libmcrypt-devel,如果你没有安装epel-release这个扩展源,就需要先安装这个扩展源,因为libmcrypt是在这个扩展源里面,安装扩展源命令:yum install -y epel-release
8.编译安装
[root@linuxidc php-5.6.30]# make [root@linuxidc php-5.6.30]# make install [root@linuxidc php-5.6.30]# echo $? 0备注:Apache和php结合的通过图中的libphp5.so模块
9.查看php加载的模块(都是静态的):
[root@linuxidc php-5.6.30]# /usr/local/php/bin/php -m [PHP Modules] bz2 Core ctype date dom ereg exif fileinfo filter gd hash iconv json libxml mbstring mcrypt mysql mysqli openssl pcre PDO pdo_mysql pdo_sqlite Phar posix Reflection session SimpleXML soap sockets SPL sqlite3 standard tokenizer xml xmlreader xmlwriter zlib [Zend Modules]10.PHP是做为apache的模块存在,查看模块:
[root@linuxidc php-5.6.30]# /usr/local/apache2.4/bin/httpd -M AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 218.93.250.18. 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@linuxidc php-5.6.30]# ls -l /usr/local/apache2.4/modules/libphp5.so //模块文件 -rwxr-xr-x 1 root root 37752872 12月 18 17:09 /usr/local/apache2.4/modules/libphp5.so