yum PHP7.1增加扩展的方法:1、通过yum安装PHP7.1;2、通过“yum -y install PHP-MysqL PHP-gd PHP-ldap PHP-odbc...”命令添加PHP常用扩展即可。
本文操作环境:centos7系统、PHP7.1版、DELL G3电脑
CentOS 7下部署PHP7.1和开启MysqL扩展的方法教程
前言
之前在CentOS7安装PHP7.1的时候有遇到PHP源及PHP7.1不支持MysqL扩展问题,上午抽空安装了下终于解决了这两个问题,特此记录备忘。
简单安装(yum方式)
安装软件源
添加epel源
[[email protected] opt]# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY* [[email protected] opt]# rpm -Uvh http://mirrors.rit.edu/fedora/epel//7/x86_64/e/epel-release-7-9.noarch.rpm
添加remi源
[[email protected] opt]# rpm -Uvh http://rpms.remirepo.net/enterprise/remi-release-7.rpm
安装并更新软件
安装yum-config-manager实用程序
[[email protected] opt]# yum -y install yum-utils
更新系统当前软件版本
[[email protected] opt]# yum -y update
更新完成后,就可以安装所需要的PHP版本了。
安装PHP
以上准备工作完成后,就可以安装所需的PHP版本了。
对于PHP5.4
[[email protected] opt]# yum -y install PHP
安装前可尝试yum search PHP54搜索可安装的软件包。
对于PHP7.0
[[email protected] opt]# yum-config-manager --enable remi-PHP70 [[email protected] opt]# yum -y install PHP PHP-opcache
安装前可尝试yum search PHP70搜索可安装的软件包。
对于PHP7.1
[[email protected] opt]# yum-config-manager --enable remi-PHP71 [[email protected] opt]# yum -y install PHP PHP-opcache
安装前可尝试yum search PHP71搜索可安装的软件包。
[[email protected] opt]# yum -y install PHP-MysqL PHP-gd PHP-ldap PHP-odbc PHP-pear PHP-xml PHP-xmlrpc PHP-mbstring PHP-soap curl curl-devel
对于Nginx
[[email protected] opt]# yum -y install Nginx Nginx-mod-http-perl Nginx-mod-stream Nginx-filesystem Nginx-mod-mail Nginx-mod-http-image-filter Nginx-all-modules Nginx-mod-http-geoip Nginx-mod-http-xslt-filter
安装前仍建议尝试yum search Nginx搜索可安装的软件包。
安装完成后配置PHP及Nginx并启动用以测试PHPinfo页面,这时候应该能正常显示。
源码编译安装
安装前的准备
下载PHP安装包
[[email protected] opt]# wget -O PHP-7.1.5.tar.gz http://cn2.PHP.net/distributions/PHP-7.1.5.tar.gz
解压
[[email protected] opt]# tar xf PHP-7.1.5.tar.gz
安装依赖包
[[email protected] PHP-7.1.5]# yum install -y libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-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
配置安装
编译配置
[[email protected] opt]# cd PHP-7.1.5 [[email protected] PHP-7.1.5]# ./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
具体可以参考PHP官方安装说明文档:http://PHP.net/manual/zh/install.unix.Nginx.PHP
编译安装
[[email protected] PHP-7.1.5]# make && make install
配置环境变量:
在/etc/profile末尾追加export PATH=$PATH:/usr/local/PHP/bin,然后执行source /etc/profile生效后查看PHP版本:
[[email protected] PHP-7.1.5]# PHP -v PHP 7.1.5 (cli) (built: May 31 2017 16:12:38) ( NTS ) copyright (c) 1997-2017 The PHP Group Zend Engine v3.1.0, copyright (c) 1998-2017 Zend Technologies
安装后的配置
配置PHP-fpm
安装完成后可以通过sapi/fpm/PHP-fpm.server来启动PHP-fpm了。不过为了以后管理方便,通常需要将配置文件统一放到/etc目录下,并将PHP-fpm.server添加至systemctl服务。如下:
[[email protected] PHP-7.1.5]# mkdir -p /etc/PHP-fpm.d [[email protected] PHP-7.1.5]# cp PHP.ini-production /etc/PHP.ini [[email protected] PHP-7.1.5]# cp sapi/fpm/PHP-fpm.service /usr/lib/systemd/system/ [[email protected] PHP-7.1.5]# cp sapi/fpm/www.conf /etc/PHP-fpm.d/
然后更改/usr/lib/systemd/system/PHP-fpm.service文件使其执行正确的路径,如下:
[[email protected] PHP-7.1.5]# vi /usr/lib/systemd/system/PHP-fpm.service # It's not recommended to modify this file in-place, because it # will be overwritten during upgrades. If you want to customize, # the best way is to use the systemctl edit command. [Unit] Description=The PHP FastCGI Process Manager After=network.target [Service] Type=simple PIDFile=/var/run/PHP-fpm.pid ExecStart=/usr/local/PHP/sbin/PHP-fpm --nodaemonize --fpm-config /etc/PHP-fpm.conf ExecReload=/bin/kill -USR2 $MAINPID PrivateTmp=true [Install] WantedBy=multi-user.target
启动PHP-fpm
第一次通过systemctl启动PHP服务时需要先将PHP-fpm服务enable:
[[email protected] PHP-7.1.5]# systemctl enable PHP-fpm.service [[email protected] PHP-7.1.5]# systemctl start PHP-fpm.service
编译安装Nginx
详见这篇文章,并根据需要配置并启动Nginx。这里就不在写了。
开启MysqL扩展(仅编译安装)
由于PHP7已经完全移除了MysqL的扩展支持(由MysqLi与MysqLnd取代),因此一些老的软件在升级PHP版本后会报类似MysqL_connect()函数未定义的错误,一般建议使用新的PHPMysqLi或者pdo扩展进行替换。当然也可以检出遗留版本的支持MysqL扩展的PHP7代码自行编译安装了,不过需要注意的就是MysqL扩展可是完全没有后续更新的了。
安装前准备
查看当前扩展
[[email protected] PHP-7.1.5]# ls ext bcmath dom gd json oci8 pdo_firebird posix skeleton sysvsem xmlwriter bz2 enchant gettext ldap odbc pdo_MysqL pspell snmp sysvshm xsl calendar exif gmp libxml opcache pdo_oci readline soap tidy zip com_dotnet ext_skel hash mbstring openssl pdo_odbc recode sockets tokenizer zlib ctype ext_skel_win32.PHP iconv mcrypt pcntl pdo_pgsql reflection spl wddx curl fileinfo imap MysqL pcre pdo_sqlite session sqlite3 xml date filter interbase MysqLi pdo pgsql shmop standard xmlreader dba ftp intl MysqLnd pdo_dblib phar simplexml sysvmsg xmlrpc
可以看到MysqL扩展确实已经被移除了,我们可以直接在ext目录下检出老的PHP MysqL扩展代码。
[[email protected] ext]# git clone https://github.com/PHP/pecl-database-MysqL MysqL --recursive cloning into 'MysqL'... remote: Counting objects: 145, done. remote: Total 145 (delta 0), reused 0 (delta 0), pack-reused 145 Receiving objects: 100% (145/145), 88.41 KiB | 0 bytes/s, done. Resolving deltas: 100% (65/65), done. Checking connectivity... done.
编译安装MysqL扩展
使用PHPize编译
[[email protected] ext]# cd MysqL [[email protected] MysqL]# ls config.m4 config.w32 CREDITS LICENSE MysqL.mak MysqL_MysqLnd.h package.xml PHP_MysqL.c PHP_MysqL.h PHP_MysqL_structs.h README.md tests [[email protected] MysqL]# /usr/local/PHP/bin/PHPize Configuring for: PHP Api Version: 20151012 Zend Module Api No: 20151012 Zend Extension Api No: 320151012 [[email protected] MysqL]# ./configure --with-PHP-config=/usr/local/PHP/bin/PHP-config
安装
[[email protected] MysqL]# make && make install [[email protected] MysqL]# ls /usr/local/PHP/lib/PHP/extensions/no-debug-non-zts-20160303/ MysqL.so opcache.a opcache.so
安装完成后需确认MysqL扩展安装是否正确。
extension = MysqL.so
重新启动PHP-fpm服务就能在PHPinfo里看到MysqL扩展了:
–本配置完。
推荐学习:《PHP教程》
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。