美文网首页
linux下编译安装php

linux下编译安装php

作者: 月圆星繁 | 来源:发表于2019-08-18 11:30 被阅读0次

    公司的项目用的框架(非目前的主流框架)不支持PHP5.4以上的版本,导致在迁移项目的时候就需要指定特定的版本进行安装,故将安装的过程记录下来,以便后续的翻阅,遇到坑也可以查看。
    大致是信息:

    php 5.4.45
    nginx 1.14.2
    mysql 5.6
    centos7

    准备工作:

    先安装如下依赖包
    yum -y install gcc automake autoconf libtool make gcc-c++ glibc
    yum -y install libmcrypt-devel mhash-devel libxslt-devel \
    libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel \
    zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel \
    ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel \
    krb5 krb5-devel libidn libidn-devel openssl openssl-devel
    
    创建用户组和用户
    groupadd www
    useradd -r www -g www
    
    下载并解压php
    cd /usr/local/src
    yum install wget
    wget https://museum.php.net/php5/php-5.4.45.tar.gz
    tar zxvf php-5.4.4.tar.gz
    cd php-5.4.4
    
    配置configure

    因为环境问题导致的项目跑不起来,或者出错的情况还是比较的多,所以我尽量和线上的配置查不多吧。

    ./configure --prefix=/usr/local/php --with-pdo-pgsql 
    --with-zlib-dir --with-freetype-dir --enable-mbstring 
    --with-libxml-dir=/usr --enable-soap --enable-calendar 
    --with-curl --with-mcrypt=/usr/local/bin/libmcrypt 
    --with-gd --with-pgsql --disable-rpath --enable-inline-optimization 
    --with-bz2 --with-zlib --enable-sockets --enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex --enable-exif 
    --enable-bcmath --with-mhash --enable-zip --with-pcre-regex 
    --with-jpeg-dir=/usr/lib --with-png-dir=/usr/lib --enable-gd-native-ttf 
    --with-openssl --with-fpm-user=www --with-fpm-group=www 
    --enable-ftp --with-gettext --with-xmlrpc --with-xsl --enable-fpm 
    --with-iconv --with-xpm-dir=/usr/bin --enable-pdo --with-mysql=mysqlnd
    --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd
    

    运行上面的configure发现报错了:

    checking for mcrypt support... yes
    configure: error: mcrypt.h not found. Please reinstall libmcrypt.
    

    那就去解决咯

    wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/attic/libmcrypt/libmcrypt-2.5.7.tar.gz  
    tar -zxvf libmcrypt-2.5.7.tar.gz  
    cd libmcrypt-2.5.7  
    ./configure --prefix=/usr/local/bin/libmcrypt  
    make && make install 
    

    然后配置configure为:
    --with-mcrypt=/usr/local/bin/libmcrypt

    然后还是报错:

    configure: error: libXpm.(a|so) not found.
    

    那就安装咯:

    yum -y install libxpm-dev
    

    然后并没有预期的解决,好伤心,只能接着一顿操作。

    这解决的方法大多不生效,看这个可以 文章https://www.cnblogs.com/wusong/p/4694938.html

    大致内容:

    centos 6.5
    安装php时老是报错,找了很久答案都是千篇一律且不起作用,最后找到一个答案,特记录在此
    configure: error: libXpm.(a|so) not found.
    解决方法:
    1,按网络上说的执行yum -y install libXpm-devel,表示最新版本已存在,无需安装。
    2,查找usr/lib,根本就是没有libXpm.(a|so) 文件,也没有所谓的/usr/lib/x86_64-linux-gnu目录
    3,查找usr/lib64,终于看到好多libxpm文件。于是软链接 ln -s /usr/lib64/libXpm.so* /usr/lib/
    再执行,搞定。
    其实原因:
    configure一般的搜索编译路径为/usr/lib/下,因为php默认就在/usr/lib/下找相关库文件
    linkto: http://blog.csdn.net/buutterfly/article/details/5630203
    so,
    注: 主机是x64平台,
    ln -s /usr/lib64/libXpm.so* /usr/lib/
    并且编译时指定, --with-xpm-dir=/usr/lib64/x11
    注意我的编译时指定是--with-xpm-dir=/usr/lib64/x11

    最后我在/usr/lib下面查了为x86_64-linux-gnu目录确实没有,就按使用了他说的软连接,在查看软连接生效,然后在 configure 设置 --with-xpm-dir=/usr/lib

    然后接着configure,但是又又又报错啦:

    configure: error: Cannot find libpq-fe.h. 
    Please specify correct PostgreSQL installation path
    

    那就接着执行咯:

    yum -y install postgresql-devel
    

    然后接着执行configure,成功信息如下:

    Generating files
    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 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/fpm/php-fpm.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
    

    编译安装

    那就来执行编译的makemake install,这可以分开执行也可以一起执make && make install
    我分开执行的,想看下执行之后输出的内容

    执行make后的内容:
    Generating phar.php
    Generating phar.phar
    PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled.
    clicommand.inc
    directorygraphiterator.inc
    directorytreeiterator.inc
    invertedregexiterator.inc
    pharcommand.inc
    phar.inc
    
    Build complete.
    Don't forget to run 'make test'.
    
    执行make install之后的内容
    [root@localhost php-5.4.45]# make install
    Installing PHP CLI binary:        /usr/local/php/bin/
    Installing PHP CLI man page:      /usr/local/php/php/man/man1/
    Installing PHP FPM binary:        /usr/local/php/sbin/
    Installing PHP FPM config:        /usr/local/php/etc/
    Installing PHP FPM man page:      /usr/local/php/php/man/man8/
    Installing PHP FPM status page:      /usr/local/php/php/fpm/
    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/
      program: phpize
      program: php-config
    Installing man pages:             /usr/local/php/php/man/man1/
      page: phpize.1
      page: php-config.1
    Installing PEAR environment:      /usr/local/php/lib/php/
    [PEAR] Archive_Tar    - installed: 1.3.12
    [PEAR] Console_Getopt - installed: 1.3.1
    [PEAR] Structures_Graph- installed: 1.0.4
    [PEAR] XML_Util       - installed: 1.2.3
    [PEAR] PEAR           - installed: 1.9.5
    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
    /usr/local/src/php-5.4.45/build/shtool install -c ext/phar/phar.phar /usr/local/php/bin
    ln -s -f /usr/local/php/bin/phar.phar /usr/local/php/bin/phar
    Installing PDO headers:          /usr/local/php/include/php/ext/pdo/
    

    配置php

    [root@localhost php-5.4.45]# find / -name php.ini-development
    /usr/local/src/php-5.4.45/php.ini-development
    

    如果发现没有php.ini文件可以参考:
    有些人./configure的时候设置了这个文件--with-config-file-path=/etc
    但是我没有配置,应该有默认位置,然后就百度,发现了这个文章:https://www.cnblogs.com/jie-fang/p/10677565.html

    那么参考那篇文章就往下操作:

    [root@localhost php]# php -r "phpinfo();" | grep 'php.ini'
    -bash: php: 未找到命令
    [root@localhost php]# /usr/local/php/bin/php -r "phpinfo();" | grep 'php.ini'
    Configuration File (php.ini) Path => /usr/local/php/lib
    
    [root@localhost php-5.4.45]# cp php.ini-development /usr/local/php/lib/php.ini
    
    [root@localhost ~]# cd  /usr/local/php/etc/
    [root@localhost etc]# cp php-fpm.conf.default php-fpm.conf
    [root@localhost ~]# cd  /usr/local/php/etc/php-fpm.d
    [root@localhost php-fpm.d]# cp www.conf.default www.conf
    

    测试PHP环境

    • 安装完成执行:./bin/php -m , 返回php安装的扩展
    • 也可以测试:vim test.php ,里面写上内容可以是echo 'hello';等内容,执行./bin/php test.php

    报错

    [root@63daaf1861b7 sbin]# ./php-fpm 
    [01-Jan-2020 19:09:50] WARNING: Nothing matches the include pattern '/usr/local/php/etc/php-fpm.d/*.conf' from /usr/local/php/etc/php-fpm.conf at line 125.
    [01-Jan-2020 19:09:50] ERROR: No pool defined. at least one pool section must be specified in config file
    [01-Jan-2020 19:09:50] ERROR: failed to post process the configuration
    [01-Jan-2020 19:09:50] ERROR: FPM initialization failed
    

    文件处理:

    [root@63daaf1861b7 php-fpm.d]# cp www.conf.default www.conf
    [root@dafd40d8aa7e php-fpm.d]# ./usr/local/php/sbin/php-fpm -t
    bash: ./usr/local/php/sbin/php-fpm: No such file or directory
    [root@dafd40d8aa7e php-fpm.d]# /usr/local/php/sbin/php-fpm -t
    [01-Jan-2020 18:21:11] NOTICE: configuration file /usr/local/php/etc/php-fpm.conf test is successful
    

    相关文章

      网友评论

          本文标题:linux下编译安装php

          本文链接:https://www.haomeiwen.com/subject/bicrsctx.html