LAMP环境搭建三(centos7)PHP5和PHP7安装
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LAMP环境搭建三(centos7)PHP5和PHP7安装相关的知识,希望对你有一定的参考价值。
php其实是Apache的扩展模块。(需要最后安装)
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-5.6.30.tar.gz
cd 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
make && make install
cp php.ini-production /usr/local/php/etc/php.ini
实验流程:
[[email protected] src]# cd /usr/local/src/
[[email protected] src]# wget http://cn2.php.net/distributions/php-5.6.30.tar.gz
[[email protected] src]# du -h php-5.6.30.tar.gz
19M php-5.6.30.tar.gz
[[email protected] src]# tar zxvf php-5.6.30.tar.gz
[[email protected] php-5.6.30]# cd php-5.6.30/
[[email protected] php-5.6.30]# ./configure
--prefix=/usr/local/php //指定安装目录
--with-apxs2=/usr/local/apache2.4.7/bin/apxs //Apache的工具 模块相关(你的Apache目录)
--with-config-file-path=/usr/local/php/etc //指定配置文件所在路径
--with-mysql=/usr/local/mysql //指定mysql的路径
--with-pdo-mysql=/usr/local/mysql //
--with-mysqli=/usr/local/mysql/bin/mysql_config //这两个是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
报错详解:
1 configure: error: xml2-config not found. Please check your libxml2 installation.
[[email protected] php-5.6.30]# yum install -y libxml2-devel
2 configure: error: Cannot find OpenSSL‘s <evp.h>
[[email protected] php-5.6.30]# yum install -y openssl-devel
3 configure: error: Please reinstall the BZip2 distribution
[[email protected] php-5.6.30]# yum install -y bzip2-devel
4 configure: error: jpeglib.h not found.
[[email protected] php-5.6.30]# yum install -y libjpeg-turbo.x86_64 jpeginfo.x86_64 jpegoptim.x86_64 libjpeg-turbo-devel.x86_64
5 configure: error: freetype-config not found.
[[email protected] php-5.6.30]# yum install -y freetype freetype-devel
6 configure: error: mcrypt.h not found. Please reinstall libmcrypt.
[[email protected] php-5.6.30]# yum install -y epel-release //安装扩展源
[[email protected] php-5.6.30]# yum install -y libmcrypt-devel
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
[[email protected] php-5.6.30]# echo $?
0
[[email protected] php-5.6.30]#
编译参数配置完毕!!
[[email protected] php-5.6.30]#make
make的时候会报很多的错,基本上都是缺少库文件,直接下载相应的库即可
或者 复制粘贴到搜索引擎搜索
Build complete.
Don‘t forget to run ‘make test‘.
[[email protected] php-5.6.30]# echo $?
0
很奇怪,我的没有报错。
[[email protected] php-5.6.30]# make install
[[email protected] php-5.6.30]# echo $?
0
[[email protected] php-5.6.30]# ls /usr/local/php/ //PHP下的目录
bin etc include lib php
[[email protected] php-5.6.30]# ls /usr/local/php/bin/ //bin下是重要的文件
pear peardev pecl phar phar.phar php php-cgi php-config phpize
[[email protected] php-5.6.30]# du -sh /usr/local/php/bin/php
36M /usr/local/php/bin/php
[[email protected] php-5.6.30]# du -sh /usr/local/apache2.4.7/modules/libphp5.so
37M /usr/local/apache2.4.7/modules/libphp5.so //37M 这个就是我们要的扩展模块
[[email protected] php-5.6.30]# /usr/local/php/bin/php -m //查看PHP加载的模块 都是静态模块
[PHP Modules]
..
最后复制配置文件
[[email protected] php-5.6.30]# cp php.ini-production /usr/local/php/etc/php.ini
安装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
实验
cd /usr/local/src/
[[email protected] src]# wget http://cn2.php.net/distributions/php-7.1.6.tar.bz2
[[email protected] src]# tar jxf php-7.1.6.tar.bz2
[[email protected] src]# cd php-7.1.6/
[[email protected] php-7.1.6]# ./configure --prefix=/usr/local/php7 --with-apxs2=/usr/local/apache2.4.7/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
几分钟之后
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
[[email protected] php-7.1.6]# echo $?
0
[[email protected] php-7.1.6]# ./configure --prefix=/usr/local/php7 --with-apxs2=/usr/local/apache2.4.7/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
[[email protected] php-7.1.6]# make
[[email protected] php-7.1.6]# make install
OK
Linux下查看nginx、Napache、MySQL、PHP的编译参数的命令如下:
1、nginx编译参数:
#/usr/local/nginx/sbin/nginx -V
2、apache编译参数:
# cat /usr/local/apache/build/config.nice
3、php编译参数:
# /usr/local/php/bin/php -i |grep configure
4、mysql编译参数:
# cat /usr/local/mysql/bin/mysqlbug|grep configure
本文出自 “13348833” 博客,请务必保留此出处http://13358833.blog.51cto.com/13348833/1969422
以上是关于LAMP环境搭建三(centos7)PHP5和PHP7安装的主要内容,如果未能解决你的问题,请参考以下文章
Docker 基于centos7 的LAMP环境搭建 (实验一)