美文网首页
Centos7 安装 PHP7

Centos7 安装 PHP7

作者: 程序员的自我修养 | 来源:发表于2020-05-28 14:58 被阅读0次

方法一、简单安装(通过yum)

1.安装epel-release

1rpm -ivh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm

2.安装PHP7的rpm源

1rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

3.安装PHP7

1yuminstallphp70w

方法二、编译安装

1.下载php7

1wget -O php7.tar.gz http://cn2.php.net/get/php-7.1.1.tar.gz/from/this/mirror

2.解压php7

1tar-xvf php7.tar.gz

3.进入php目录

1cdphp-7.0.4

4.安装依赖包

# 直接复制下面一行(不包括本行)

yuminstalllibxml2 libxml2-devel openssl openssl-develbzip2bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel

5.编译配置(如果出现错误,基本都是上一步的依赖文件没有安装所致)

嫌麻烦的可以从这一步起参考PHP官方安装说明:http://php.net/manual/zh/install.unix.nginx.php

./configure \

--prefix=/usr/local/php \

--with-config-file-path=/etc \

--enable-fpm \

--with-fpm-user=nginx \

--with-fpm-group=nginx \

--enable-inline-optimization \

--disable-debug \

--disable-rpath \

--enable-shared \

--enable-soap \

--with-libxml-dir \

--with-xmlrpc \

--with-openssl \

--with-mcrypt \

--with-mhash \

--with-pcre-regex \

--with-sqlite3 \

--with-zlib \

--enable-bcmath \

--with-iconv \

--with-bz2 \

--enable-calendar \

--with-curl \

--with-cdb \

--enable-dom \

--enable-exif \

--enable-fileinfo \

--enable-filter \

--with-pcre-dir \

--enable-ftp \

--with-gd \

--with-openssl-dir \

--with-jpeg-dir \

--with-png-dir \

--with-zlib-dir \

--with-freetype-dir \

--enable-gd-native-ttf \

--enable-gd-jis-conv \

--with-gettext \

--with-gmp \

--with-mhash \

--enable-json \

--enable-mbstring \

--enable-mbregex \

--enable-mbregex-backtrack \

--with-libmbfl \

--with-onig \

--enable-pdo \

--with-mysqli=mysqlnd \

--with-pdo-mysql=mysqlnd \

--with-zlib-dir \

--with-pdo-sqlite \

--with-readline \

--enable-session \

--enable-shmop \

--enable-simplexml \

--enable-sockets \

--enable-sysvmsg \

--enable-sysvsem \

--enable-sysvshm \

--enable-wddx \

--with-libxml-dir \

--with-xsl \

--enable-zip \

--enable-mysqlnd-compression-support \

--with-pear \

--enable-opcache

./configure --prefix=/usr/local/php --with-config-file-path=/etc --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-soap --with-libxml-dir --with-xmlrpc --with-openssl --with-mcrypt --with-mhash --with-pcre-regex --with-sqlite3 --with-zlib --enable-bcmath --with-iconv --with-bz2 --enable-calendar --with-curl --with-cdb --enable-dom --enable-exif --enable-fileinfo --enable-filter --with-pcre-dir --enable-ftp --with-gd --with-openssl-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-freetype-dir --enable-gd-native-ttf --enable-gd-jis-conv --with-gettext --with-gmp --with-mhash --enable-json --enable-mbstring --enable-mbregex --enable-mbregex-backtrack --with-libmbfl --with-onig --enable-pdo --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-zlib-dir --with-pdo-sqlite --with-readline --enable-session --enable-shmop --enable-simplexml --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --with-libxml-dir --with-xsl --enable-zip --enable-mysqlnd-compression-support --with-pear --enable-opcache

./configure \

--prefix=/usr/local/php \

--with-config-file-path=/etc \

--enable-fpm \

--with-fpm-user=nginx \

--with-fpm-group=nginx \

--enable-inline-optimization \

--disable-debug \

--disable-rpath \

--enable-shared \

--enable-soap \

--with-libxml-dir \

--with-xmlrpc \

--with-openssl \

--with-mcrypt \

--with-mhash \

--with-pcre-regex \

--with-sqlite3 \

--with-zlib \

--enable-bcmath \

--with-iconv \

--with-bz2 \

--enable-calendar \

--with-curl \

--with-cdb \

--enable-dom \

--enable-exif \

--enable-fileinfo \

--enable-filter \

--with-pcre-dir \

--enable-ftp \

--with-gd \

--with-openssl-dir \

--with-jpeg-dir \

--with-png-dir \

--with-zlib-dir \

--with-freetype-dir \

--enable-gd-native-ttf \

--enable-gd-jis-conv \

--with-gettext \

--with-gmp \

--with-mhash \

--enable-json \

--enable-mbstring \

--enable-mbregex \

--enable-mbregex-backtrack \

--with-libmbfl \

--with-onig \

--enable-pdo \

--with-mysqli=mysqlnd \

--with-pdo-mysql=mysqlnd \

--with-zlib-dir \

--with-pdo-sqlite \

--with-readline \

--enable-session \

--enable-shmop \

--enable-simplexml \

--enable-sockets \

--enable-sysvmsg \

--enable-sysvsem \

--enable-sysvshm \

--enable-wddx \

--with-libxml-dir \

--with-xsl \

--enable-zip \

--enable-mysqlnd-compression-support \

--with-pear \

--enable-opcache

手动编译libmcrypt:

wgethttps://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz

tar -zxvf libmcrypt-2.5.8.tar.gz

cd libmcrypt-2.5.8

./configure

make && make install

对PHP的编译过程中,一直报错

configure: error: Don't know how to define struct flock on this system, set --enable-opcache=no

Don't know how to define struct flock on this system, set --enable-opcache=n

最后解决方法:

# export LD_LIBRARY_PATH=/usr/local/mysql/lib

或则执行下面一条命令就行了:【注意,下面这条语句仅对当前命令框有用】

# export LD_LIBRARY_PATH=/lib/:/usr/lib/:/usr/local/lib

6.正式安装

1make&&makeinstall

7.配置环境变量

1vi/etc/profile

在末尾追加

PATH=$PATH:/usr/local/php/bin

exportPATH

执行命令使得改动立即生效

1source/etc/profile

8.配置php-fpm

cpphp.ini-production/etc/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/www.conf

cpsapi/fpm/init.d.php-fpm/etc/init.d/php-fpm

chmod+x/etc/init.d/php-fpm

9.启动php-fpm

1/etc/init.d/php-fpmstart

php-fpm  启动报错:

Starting php-fpm [10-May-2018 10:41:21] ERROR: [pool www] cannot get uid for user 'nginx'

[10-May-2018 10:41:21] ERROR: FPM initialization failed

failed

解决方法:

vim  /usr/local/php/etc/php-fpm.d/www.conf

user = nobody

group = nobody

设置开机自启动:

1、在/etc/init.d/目录下创建脚本

1vim/etc/init.d/php-fpm

2、更改脚本权限

1chmod775/etc/init.d/php-fpm

3、设置开机启动

1#chkconfig php-fpm on

可用命令 chkconfig 查看开机启动服务列表

问题及处理:

1.配置nginx后.php  文件  提示  not find :

  location ~ \.php$ {                   #开启php解析

            root           html;

            fastcgi_pass   127.0.0.1:9000;

            fastcgi_index  index.php;

           # fastcgi_param  SCRIPT_FILENAME          script$fastcgi_script_name

          改为:

            fastcgi_param  SCRIPT_FILENAME/usr/local/nginx/html$fastcgi_script_name;  #指定路径

            include         fastcgi_params;

        }

相关文章

网友评论

      本文标题:Centos7 安装 PHP7

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