广告:宝塔Linux面板高效运维的服务器管理软件 点击【 https://www.bt.cn/p/uNLv1L 】立即购买
centos 7 编译安装 php-7.2.11的步骤
在官网下载php-7.2.11的php压缩包,centos 7 安装 php-7.2.11的步骤,http://cn2.php.net/distributions/php-7.2.11.tar.gz
cd /usr/local/srcwget -c http://cn2.php.net/distributions/php-7.2.11.tar.gz登录后复制
下载好后解压 php-7.2.11.tar.gz 压缩包,并进入解压后的目录
tar -xzvf php-7.2.11.tar.gzcd php-7.2.11登录后复制
安装PHP7需要的一些依赖库包 libxml2和一些其他依赖的扩展库
推荐(免费):PHP7
yum -y install libxml2 yum -y install libxml2-devel yum -y install openssl yum -y install openssl-devel yum -y install curl-devel yum -y install libjpeg-devel yum -y install libpng-devel yum -y install freetype-develyum -y install bzip2-develyum -y install libmcrypt libmcrypt-develyum -y install postgresql-develyum -y install aspell-develyum -y install readline-develyum -y install libxslt-develyum -y install net-snmp-develyum -y install unixODBC-develyum -y install libicu-develyum -y install libc-client-develyum -y install libXpm-develyum -y install libvpx-develyum -y install enchant-develyum -y install openldapyum -y install openldap-develyum -y install db4-develyum -y install gmp-develyum -y install sqlite-develyum -y install mysql-devel登录后复制
yum install oniguruma-devel -y登录后复制
安装前的环境配置检查,php7的一些依赖包的检查和php扩展的启动,这个过程如果缺少php依赖的库包会有报错提示。
添加用户和组: (此处用户和组为 nginx, 我 nginx 用的用户名 ) groupadd -r nginx && useradd -r -g nginx -s /sbin/nologin
php 安装配置
请根据以下 A B C 选择合适的一项进行安装配置
A. PHP 7.2.10 单选模式
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-soap --with-xmlrpc --with-openssl --with-mcrypt --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-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
B. PHP 7.2.10 多行模式
./configure \--prefix=/usr/local/php \--with-config-file-path=/usr/local/php/etc \--enable-fpm \ --with-fpm-user=nginx \--with-fpm-group=nginx \ --enable-inline-optimization \--disable-debug \--disable-rpath \--enable-shared \--enable-soap \--with-xmlrpc \--with-openssl \--with-mcrypt \--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-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登录后复制
C. PHP 7.4.10
./configure \--prefix=/usr/local/php \--with-config-file-path=/usr/local/php/etc \--enable-fpm \--with-fpm-user=nginx \--with-fpm-group=nginx \--enable-inline-optimization \--disable-debug \--disable-rpath \--enable-shared \--enable-soap \--with-xmlrpc \--with-openssl \--with-mcrypt \--with-pcre-regex \--with-sqlite3 \--with-zlib \--enable-bcmath \--with-iconv \--with-kerberos \--with-libdir=lib64 \--with-bz2 \--enable-calendar \--with-curl \--with-cdb \--enable-dom \--enable-exif \--enable-fileinfo \--enable-filter \--with-pcre-dir \--enable-ftp \--enable-gd \--with-openssl-dir \--with-jpeg-dir \--with-png-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 \--with-zip \--enable-xml \--enable-mysqlnd-compression-support \--with-pear \--enable-opcache \--enable-pcntl登录后复制
从 PHP 7.4.0 开始,必须在编译 PHP 时用 --with-zip 配置选项来提供 zip 支持。之前的 PHP 版本,需要使用 --enable-zip 选项。
对php7进行编译和安装的操作
make && make install
( 如果出现 make: *** [sapi/cli/php] Error 1 的错误,通过继续执行 make ZEND_EXTRA_LIBS='-liconv' 命令解决
编译成功,查看php版本
/usr/local/php/bin/php -v
运行php-fpm
/usr/local/php/sbin/php-fpm
启动php-fpm可能会遇到的错误,基本都是配置文件配置和重命名的问题:
错误一:缺少www.conf配置文件(WARNING: Nothing matches the include pattern /usr/local/php/etc/php-fpm.d/*.conf),需要把/usr/local/php/etc/php-fpm.d/*.conf目录中的www.conf.default重命名为www.conf。
错误二:缺少php-fpm.conf配置文件 需要在/usr/local/php/etc/php-fpm.conf 把默认的配置文件php-fpm.conf.default改成php-fpm.conf
错误三:缺少php.ini配置文件 php7编译安装好后会发现没有php.ini配置文件,需要在解压包的根目录中复制php.ini-production或php.ini-development并重命名为php.ini到php编译好的安装目录中的/usr/local/php/etc文件夹即可。
其它错误的解决: error: Package requirements (sqlite3 > 3.7.4) were not met
yum install libsqlite3x-devel -y登录后复制error: Package requirements (oniguruma) were not met
yum install oniguruma-devel -y登录后复制当yum install 提示 "没可用软件包"
yum install -y epel-release登录后复制off_t undefined 报错
configure: error: off_t undefined; check your library configuration登录后复制configure: WARNING: unrecognized options: --with-mcrypt, --enable-gd-native-ttf
php7.2以后不支持–with-mcrypt, --enable-gd-native-ttf 这两个参数,需要去掉
在centos7中编译安装好php后,系统重启后并不会对php进行开机启动,所以需要对centos7添加开机启动脚本对php进行开机启动服务。
php7编译安装方法:http://zixuephp.net/article-207.html
手动启动:
/usr/local/php/sbin/php-fpm开机自动启动:
#找到php-fpm.conf配置文件/usr/local/php/etc/php-fpm.conf#开启pid ,去掉分号注释pid = run/php-fpm.pid开启配置php-fpm pid
安装后要进行的操作:
tar -xzvf php-7.2.11.tar.gzcd php-7.2.110登录后复制
PHP 7.4.10 安装 ZIP
tar -xzvf php-7.2.11.tar.gzcd php-7.2.111登录后复制
创建开机启动脚本
在Linux中将php-fpm配置成服务的方法
PHP 源文件路径: /usr/local/src/php-7.2.11/ PHP 安装后路径: /usr/local/php/
1、配置 php-fpm.conf
vim /usr/local/php/etc/php-fpm.conf
php-fpm.pid 目录必须指向:/usr/local/php/var/run/php-fpm.pid
2、拷贝php-fpm脚本至/etc/init.d目录
cp /usr/local/src/php-7.2.11/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
tar -xzvf php-7.2.11.tar.gzcd php-7.2.112登录后复制
3、设置权限并启动php-fpm:
chmod 755 /etc/init.d/php-fpm
/etc/init.d/php-fpm start
chkconfig –add php-fpm
最后,给出php-fpm以服务的方式启动、停止和重启:
service php-fpm start
service php-fpm stop
service php-fpm reload
PHP-FPM 自启动配置服务: vim /etc/rc.d/rc.local
查看开机启动的所有服务
chkconfig --list
nginx demo 配置:(不要忘记chown www-data:www-data 网站目录 不然没权限)
tar -xzvf php-7.2.11.tar.gzcd php-7.2.113登录后复制
php-fpm配置 (重命名两个文件 其他看实际情况配置(略。。。)) www.conf.default -> www.conf php-fpm.conf.default -> php-fpm.conf 启动: php-fpm -D nginx -s reload
以上就是讲解Centos安装PHP7及配置php-fpm开机启动的详细内容,更多请关注9543建站博客其它相关文章!
发表评论