PHP在CentOS7上的编译安装

CentOS 7.4 编译安装 PHP 5.6

    

    First, wget the source code to local Directory

       You can access  the  php official site.

        然后使用 wget  http://au1.php.net/get/php-5.6.36.tar.bz2/from/this/mirror

这个从官方网站下载下来的文件名名为mirror,直接在当前目录使用tar展开即可  tar xf  mirror , 之后即可显示出响应的php对应版本文件夹

1.解决依赖关系:

        首先,配置好yum源(包含epel)后执行以下命令

        yum -y groupinstall "Desktop Platform Development"

        yum -y install bzip2-devel   libmcrypt-devel  openssl-devel  libxml2-devel  libxml2

    

2. 编译安装php-5.6.36

    ./configure --prefix=/usr/local/php  --with-mysql --with-openssl --with-mysqli --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --with-apxs2 --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2  --enable-maintainer-zts 

   

make -j 4 && make install

安装完成后会显示以下信息

chmod 755 /usr/lib64/httpd/modules/libphp5.so
[activating module `php5' in /etc/httpd/conf/httpd.conf]
Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-zts-20131226/
Installing PHP CLI binary:        /usr/local/php/bin/
Installing PHP CLI man page:      /usr/local/php/php/man/man1/
Installing PHP CGI binary:        /usr/local/php/bin/
Installing PHP CGI man page:      /usr/local/php/php/man/man1/
Installing build environment:     /usr/local/php/lib/php/build/
Installing header files:           /usr/local/php/include/php/
Installing helper programs:       /usr/local/php/bin/
Installing PEAR environment:      /usr/local/php/lib/php/

Wrote PEAR system config file at: /usr/local/php/etc/pear.conf
You may want to add: /usr/local/php/lib/php to your php.ini include_path
/root/php-5.6.36/build/shtool install -c ext/phar/phar.phar /usr/local/php/bin
ln -s -f phar.phar /usr/local/php/bin/phar

Installing PDO headers:           /usr/local/php/include/php/ext/pdo/

要牢记这些信息,尤其是一些配置文件

说明:
1、这里为了支持apache的worker或event这两个MPM,编译时使用了--enable-maintainer-zts选项。
2、如果使用PHP5.3以上版本,为了链接MySQL数据库,可以指定mysqlnd,这样在本机就不需要先安装MySQL或MySQL开发包了。mysqlnd从php 5.3开始可用,可以编译时绑定到它(而不用和具体的MySQL客户端库绑定形成依赖),但从PHP 5.4开始它就是默认设置了。

# ./configure --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd

3.为php提供配置文件:

# cp php.ini-production /etc/php.ini

3、 编辑apache配置文件httpd.conf,以apache支持php
 
 # vim /etc/httpd/httpd.conf
 1、添加如下二行
   AddType application/x-httpd-php  .php
   AddType application/x-httpd-php-source  .phps

 2、定位至DirectoryIndex index.html 
   修改为:
    DirectoryIndex  index.php  index.html


而后重新启动httpd,或让其重新载入配置文件即可测试php是否已经可以正常使用。


测试页面index.php示例如下:
    <?php
      $link = mysql_connect('127.0.0.1','root','');
      if ($link)
        echo "Success...";
      else
        echo "Failure...";
      mysql_close();
    ?>




猜你喜欢

转载自blog.csdn.net/zhangyexinaisurui/article/details/80412489