centos7 php7 httpd

安装php之前,要先安装几个

1.下载php源码:http://cn2.php.net/distributions/php-7.0.6.tar.gz。

2.然后使用命令:tar -zxvf php-7.0.6.tar.gz,进行解压。

3.使用php时还要先安装几个其他的东西,否则安装会出错,或者不生成php.so扩展文件,

  先从ftp://xmlsoft.org/libxml2/libxml2-2.7.2.tar.gz下载这个插件,注意不要下载最新版本除非需要,版本越新需要的依赖越多,下载完成后使用tar解压,

  执行1../configure,2.make,3.make install ,三个命令来编译安装这个东西。

  然后检查是否安装了httpd_devel,如果没有安装,执行yum install httpd-devel,进行安装,如果不安装的话,后期不会生成.so的扩展文件。

4.进入解压完的php文件,然后根据自己的需要,来配置./configure的参数

  

./configure \
--prefix=/usr/local/php7 \
--exec-prefix=/usr/local/php7 \
--bindir=/usr/local/php7/bin \
--sbindir=/usr/local/php7/sbin \
--includedir=/usr/local/php7/include \
--libdir=/usr/local/php7/lib/php \
--mandir=/usr/local/php7/php/man \
--with-config-file-path=/usr/local/php7/etc \
--with-mysql-sock=/var/run/mysql/mysql.sock \
--with-mcrypt=/usr/include \
--with-mhash \
--with-openssl \
--with-pdo-mysql=shared,mysqlnd \
--with-mysqli=shared,mysqlnd \
--with-pdo-mysql=shared,mysqlnd \
--with-gd \
--with-iconv \
--with-zlib \
--enable-zip \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-xml \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-mbregex \
--enable-mbstring \
--enable-ftp \
--enable-gd-native-ttf \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-soap \
--without-pear \
--with-gettext \
--enable-session \
--with-curl \
--with-jpeg-dir \
--with-freetype-dir \
--enable-fpm \
--without-gdbm \
--enable-opcache=no \
--disable-fileinfo

  注意,每个参数都可能会有依赖,比如:--with-zlib \ --enable-zip,是需要事先安装对应文件的,如果不需要,可以不指定对应参数,最好指定的编译参数是:--prefix --with-mysqli --with-apxs2 。

  编译完成如果么有错误,那就执行 make && make install .如果报错,看是否是缺少什么依赖,在重新编译前,先执行:make clean,否则可能会产生错误,错误信息:***lo' is not a valid libtool object。

5.复制配置文件:php的推荐配置文件,已经存在于源码文件中了,使用find命令查找一下,一般是两个:php.ini-production,php.ini-development,至于将那个当配置使用,就看自己的了。

6.根据安装位置,将对应的php文件位置添加到PATH中,文件位置:/etc/profile,在最后添加:

  PATH=$PATH:/usr/local/webserver/php/bin:/usr/local/webserver/mysql/bin -- 注意添加的不是php可执行的本身,而是上一级目录,否则不能使用,
  export PATH

  最后执行source /etc/profile 重新加载配置文件,然后echo $PATH,来看路径是否添加进了环境变量。

7.以上修改完毕之后应该是已经可以在本地执行php文件了,如果不能,则是有问题,要查看是php文件,还是path路径配置问题。

8.配置httpd.conf文件,

  在配置文件中搜素:  AddType 关键字,在其后面追加下面三行,如果不追加,httpd会直接打印php文件内容,不会调用php执行。

    AddType application/x-httpd-php .php
    AddType application/x-httpd-php .php .phtml .php3
    AddType application/x-httpd-php-source .phps

 接下来添加默认搜索php文件,在配置文件中查找DirectoryIndex 关键字,如果后面没有index.php,就在后面追加index.php,这样httpd才能默认访问php文件

   接下来添加对php的支持,搜索LoadModule关键字,添加:LoadModule php7_module modules/libphp7.so,如果后期出现不能加载libphp7.so,则表示php编译有问题,最大可能就是没添加--with-apxs2参数,或者设置错误,需要重编php源码文件,直到能    在系统内搜索到libphp7.so为止。

 在httpd.conf内最好手动执行php的配置文件位置,方式为PHPIniDir "/usr/local/php7/bin",这样能保证重启httpd服务的时候,重新装载对的php配置。

 以上完成之后应该是配置完毕,找到index.html正确位置,添加index.php文件并将其他命名为index的文件改成其他名字,否则默认不会加载index.php,在index.php中添加代码

 

<?php
phpinfo();
?>

然后重启httpd服务器,使用IP访问测试,如果不行,先检查防火墙是否关闭,或者开放了指定的端口。

测试端口是否打开:firewall-cmd --query-port=80/tcp

打开指定端口:firewall-cmd --add-port=80/tcp

 或者直接关闭防火墙:

  systemctl start firewalld.service#启动firewall
  systemctl stop firewalld.service#停止firewall
  systemctl disable firewalld.service#禁止firewall开机启动

 编译过程中可能出现的错误和解决办法:

运行之后遇到的问题:

error 1

checking for xml2-config path... 
configure: error: xml2-config not found. Please check your libxml2 installation.

(看提示就明白 是一个lib库没装  先用 yum search 名字 看是否能搜到名字 ,找到名字后 把软件包 开发包装上)

解决办法

yum install libxml2-devel.x86_64

error 2

checking for pkg-config... /usr/bin/pkg-config
configure: error: Cannot find OpenSSL's <evp.h>

这是ssl没装

解决办法

 yum  install  openssl.x86_64 openssl-devel.x86_64 -y

error 3

checking for BZip2 in default path... not found
configure: error: Please reinstall the BZip2 distribution

这是bzip2软件包没有安装

解决办法

yum install bzip2-devel.x86_64 -y

error 4

configure: error: Please reinstall the libcurl distribution -
    easy.h should be in <curl-dir>/include/curl/

curl和curl库文件没有安装

解决办法

yum install libcurl.x86_64 libcurl-devel.x86_64 -y

error 5

checking whether to enable JIS-mapped Japanese font support in GD... no
checking for fabsf... yes
checking for floorf... yes
configure: error: jpeglib.h not found

GD库没有安装

解决办法

yum install libjpeg.x86_64 libpng.x86_64 freetype.x86_64 libjpeg-devel.x86_64 libpng-devel.x86_64 freetype-devel.x86_64 -y

error 6

checking for stdarg.h... (cached) yes
checking for mcrypt support... yes
configure: error: mcrypt.h not found. Please reinstall libmcrypt.

libmcrypt库没有安装 ,要是不能用yun安装的话  就要去下载个gz包 自己编译安装

(编译安装  ./configure --piefix=/usr/local/libmcrypt   make && make install)

要是错误里面含有mysql的  那是mysql-devel 没有安装

posted @ 2016-05-20 14:06  扫地猿  阅读(7177)  评论(0编辑  收藏  举报