码迷,mamicode.com
首页 > Web开发 > 详细

LAMP环境搭建三(centos7)PHP5和PHP7安装

时间:2017-09-29 00:35:41      阅读:268      评论:0      收藏:0      [点我收藏+]

标签:linux   lamp   搭建   

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

实验流程:

[root@lyon-01 src]# cd /usr/local/src/

[root@lyon-01 src]#  wget  http://cn2.php.net/distributions/php-5.6.30.tar.gz

[root@lyon-01 src]# du -h php-5.6.30.tar.gz

19M php-5.6.30.tar.gz

[root@lyon-01 src]# tar zxvf php-5.6.30.tar.gz

[root@lyon-01 php-5.6.30]# cd php-5.6.30/

[root@lyon-01 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.

[root@lyon-01 php-5.6.30]# yum install -y libxml2-devel

2  configure: error: Cannot find OpenSSL‘s <evp.h>

[root@lyon-01 php-5.6.30]# yum install -y openssl-devel

3 configure: error: Please reinstall the BZip2 distribution

[root@lyon-01 php-5.6.30]# yum install -y bzip2-devel

4  configure: error: jpeglib.h not found.

[root@lyon-01 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.

[root@lyon-01 php-5.6.30]# yum install -y freetype freetype-devel

6  configure: error: mcrypt.h not found. Please reinstall libmcrypt.

[root@lyon-01 php-5.6.30]# yum install -y epel-release    //安装扩展源

[root@lyon-01 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

[root@lyon-01 php-5.6.30]# echo $?

0

[root@lyon-01 php-5.6.30]#

编译参数配置完毕!!

[root@lyon-01 php-5.6.30]#make

make的时候会报很多的错,基本上都是缺少库文件,直接下载相应的库即可

或者 复制粘贴到搜索引擎搜索

Build complete.

Don‘t forget to run ‘make test‘.

[root@lyon-01 php-5.6.30]# echo $?

0

很奇怪,我的没有报错。

[root@lyon-01 php-5.6.30]# make install

[root@lyon-01 php-5.6.30]# echo $?

0

[root@lyon-01 php-5.6.30]# ls /usr/local/php/                     //PHP下的目录

bin  etc  include  lib  php

[root@lyon-01 php-5.6.30]# ls /usr/local/php/bin/               //bin下是重要的文件

pear  peardev  pecl  phar  phar.phar  php  php-cgi  php-config  phpize

[root@lyon-01 php-5.6.30]# du -sh /usr/local/php/bin/php

36M /usr/local/php/bin/php

[root@lyon-01 php-5.6.30]# du -sh /usr/local/apache2.4.7/modules/libphp5.so

37M /usr/local/apache2.4.7/modules/libphp5.so                //37M 这个就是我们要的扩展模块

[root@lyon-01 php-5.6.30]# /usr/local/php/bin/php -m       //查看PHP加载的模块  都是静态模块

[PHP Modules]

..

最后复制配置文件

[root@lyon-01 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/

[root@lyon-01 src]# wget http://cn2.php.net/distributions/php-7.1.6.tar.bz2

[root@lyon-01 src]# tar jxf php-7.1.6.tar.bz2

[root@lyon-01 src]# cd php-7.1.6/

[root@lyon-01 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

[root@lyon-01 php-7.1.6]# echo $?

0

[root@lyon-01 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

[root@lyon-01 php-7.1.6]# make

[root@lyon-01 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安装

标签:linux   lamp   搭建   

原文地址:http://13358833.blog.51cto.com/13348833/1969422

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!