lnmp环境搭建--php编译安装

加油吧!Davidvivi

三、安装php7.1.8 

此次采用编译安装php7.1.8


1.下载

1.cd /usr/local
2.wget http://hk1.php.net/get/php-7.1.8.tar.gz/from/this/mirror
3.tar -zxvf mirror


2.编译 

编译之前需要安装一下依赖,否则会报错

# yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel MySQL pcre-devel
# yum -y install curl-devel
# yum -y install libxslt-devel

编译

./configure --prefix=/usr/local/php \
 --with-curl \
 --with-freetype-dir \
 --with-gd \
 --with-gettext \
 --with-iconv-dir \
 --with-kerberos \
 --with-libdir=lib64 \
 --with-libxml-dir \
 --with-mysqli \
 --with-openssl \
 --with-pcre-regex \
 --with-pdo-mysql \
 --with-pdo-sqlite \
 --with-pear \
 --with-png-dir \
 --with-xmlrpc \
 --with-xsl \
 --with-zlib \
 --enable-fpm \
 --enable-bcmath \
 --enable-libxml \
 --enable-inline-optimization \
 --enable-gd-native-ttf \
 --enable-mbregex \
 --enable-mbstring \
 --enable-opcache \
 --enable-pcntl \
 --enable-shmop \
 --enable-soap \
 --enable-sockets \
 --enable-sysvsem \
 --enable-xml \
 --enable-zip \
 --with-jpeg-dir \ 
 --disable-fileinfo


–with-jpeg-dir \ 安装这个防止Call to undefined function imagecreatefromjpeg()

–disable-fileinfo 防止小内存vps编译安装php时遇到virtual memory exhausted: Cannot allocate memory,很有可能会出现问题,因为编译过程是一个内存消耗较大的动作。


成功后会输出:

Thank you for using PHP.

3.make 

make完成后会出现以下内容


Generating phar.php
Generating phar.phar
PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled.
directorytreeiterator.inc
directorygraphiterator.inc
pharcommand.inc
clicommand.inc
invertedregexiterator.inc
phar.inc
Build complete.
Don't forget to run 'make test'.


4.make install 

完成后如下图所示

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/php-7.1.8/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/


5.配置文件


# cd /usr/local/php-7.1.8
# cp php.ini-development /usr/local/php/lib/php.ini

# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
# cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/ 

# cd /usr/local/php-7.1.8
# cp -R ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm



添加php-fpm启动脚本

chmod  +x /etc/init.d/php-fpm
chkconfig --add php-fpm
chkconfig --list php-fpm
chkconfig php-fpm on


启动服务

service php-fpm start
或/etc/init.d/php-fpm start


将php加入系统变量

sudo vi /etc/profile
export PATH=$PATH:/usr/local/php/bin #在文件后面添加这行
source /etc/profile #让修改生效


配置Nginx支持解析php,修改/usr/local/nginx/conf/nginx.conf,添加location ~ .php这段。


keepalive_timeout  65;
    #gzip  on;
    server {
        listen       80;
        server_name  localhost;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
    location ~ \.php {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index /index.php;
        include /usr/local/nginx/conf/fastcgi_params;
        fastcgi_split_path_info       ^(.+\.php)(/.+)$;
        fastcgi_param PATH_INFO       $fastcgi_path_info;
        fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

打赏,支持一下

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

Powered by WEIXIA.XIN,学的不仅是技术,更是梦想!!!

Davidvivi博客
请先登录后发表评论
  • 最新评论
  • 总共 0条评论