PHP7源码安装

1、下载php源码

     wget http://am1.php.net/get/php-7.2.4.tar.gz/from/this/mirror

   重命名: mv mirror php-7.2.4.tar.gz

  使用 tar zxvf php-7.2.4.tar.gz 解压

  如果解压重命名后发现 使用tar命令出错如下: Child returned status 1 这种,应该是wget下载的时候出错,或者我们的链接地址有错,导致文件不完整,我们从官网上找一个可以下载的或者我们下载好php源码上传到服务器上面,也可以


2、 配置

      cd php-7.2.4/

     然后进行配置相关命令:     

./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/lib/mysql/mysql.sock \
--with-mcrypt=/usr/include \
--with-mhash \
--with-openssl \
--with-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-opcache \
--enable-redis \
--enable-fpm \
--enable-fastcgi \
--with-fpm-user=www \
--with-fpm-group=www \
--without-gdbm \
--disable-fileinfo

出现报错: 

缺少libxml2相关:

configure: error: libxml2 not found. Please check your libxml2 installation.

解决: 

yum -y install libxml2-devel

重新执行上面配置:

出现: configure: error: Cannot find OpenSSL's <evp.h>

解决: yum install openssl-devel 

出现: checking for cURL 7.10.5 or greater... configure: error: cURL version 7.10.5 or later is required to compile php with cURL support

解决:  yum -y install curl-devel   

出现: configure: error: jpeglib.h not found.

解决: yum install libjpeg-devel  


出现: configure: error: freetype-config not found.

 yum -y install freetype-devel 


解决过上面报错信息,我们重新执行一下上面./configure 的所有命令: 

出现   Thank you for using PHP. 证明我们配置成功了

configure: creating ./config.status

creating main/internal_functions.c
creating main/internal_functions_cli.c
+--------------------------------------------------------------------+
| License:                                                           |
| This software is subject to the PHP License, available in this     |
| distribution in the file LICENSE.  By continuing this installation |
| process, you are bound by the terms of this license agreement.     |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point.                            |
+--------------------------------------------------------------------+


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/fpm/php-fpm.conf
config.status: creating sapi/fpm/www.conf
config.status: creating sapi/fpm/init.d.php-fpm
config.status: creating sapi/fpm/php-fpm.service
config.status: creating sapi/fpm/php-fpm.8
config.status: creating sapi/fpm/status.html
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

configure: WARNING: unrecognized options: --with-mcrypt, --with-mysql, --enable-gd-native-ttf, --enable-redis, --enable-fastcgi

//这里会出现上面的warning 是因为configure命令没有识别出来,这个configure大家根据自己需求进行配置,我是参考其他人的使用的

3、编译和编译安装

   make && make install 

  最后结果如下:

Installing shared extensions:     /usr/local/php7/lib/php/extensions/no-debug-non-zts-20170718/
Installing PHP CLI binary:        /usr/local/php7/bin/
Installing PHP CLI man page:      /usr/local/php7/php/man/man1/
Installing PHP FPM binary:        /usr/local/php7/sbin/
Installing PHP FPM defconfig:     /usr/local/php7/etc/
Installing PHP FPM man page:      /usr/local/php7/php/man/man8/
Installing PHP FPM status page:   /usr/local/php7/php/php/fpm/
Installing phpdbg binary:         /usr/local/php7/bin/
Installing phpdbg man page:       /usr/local/php7/php/man/man1/
Installing PHP CGI binary:        /usr/local/php7/bin/
Installing PHP CGI man page:      /usr/local/php7/php/man/man1/
Installing build environment:     /usr/local/php7/lib/php/build/
Installing header files:          /usr/local/php7/include/php/
Installing helper programs:       /usr/local/php7/bin/
  program: phpize
  program: php-config
Installing man pages:             /usr/local/php7/php/man/man1/
  page: phpize.1
  page: php-config.1
/usr/local/src/php-7.2.4/build/shtool install -c ext/phar/phar.phar /usr/local/php7/bin
ln -s -f phar.phar /usr/local/php7/bin/phar
Installing PDO headers:           /usr/local/php7/include/php/ext/pdo/


[root@localhost php-7.2.4]# echo $?

0

证明我们安装成功了


4. 使用编译后未经优化处理的配置

 cp /usr/local/src/php-7.2.4/php.ini-production /usr/local/php7/etc/php.ini                                                                       cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf  

cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/ php7/etc/php-fpm.d/www.conf                                     cp /usr/local/src/php-7.2.4/sapi/fpm/php-fpm.service /lib/systemd/system/php-fpm.service       

5. 运行脚本

  vi test.php

  test.php 内容如下:

  <?php

           echo 123;

           echo PHP_EOL;

 运行:        /usr/local/php7/bin/php test.php 

   结果如下:

123


5、 将php加入环境变量

        echo -e '\nexport PATH=/usr/local/php7/bin:/usr/local/php7/sbin:$PATH\n' >> /etc/profile && source /etc/profile                                                                                                                                                                                               

然后运行 php test.php

结果就和上面一样了。

参考文章:

     https://typecodes.com/web/centos7compilephp7.html?utm_source=tuicool&utm_medium=referral 

     https://blog.csdn.net/u012027999/article/details/73744032  

    http://www.51ask.org/article/261                                                       

猜你喜欢

转载自blog.csdn.net/zpf_nevergiveup/article/details/79990602