Home > Database > Mysql Tutorial > body text

How to deploy php7.1 and enable MySQL extension under CentOS7

WBOY
Release: 2023-05-28 15:01:06
forward
1602 people have browsed it

Simple installation (yum method)

Install software source

Add epel source

[root@opstrip.com opt]# rpm --import /etc/pki/rpm-gpg/rpm-gpg-key*
[root@opstrip.com opt]# rpm -uvh http://mirrors.rit.edu/fedora/epel//7/x86_64/e/epel-release-7-9.noarch.rpm
Copy after login

Add remi source

[root@opstrip.com opt]# rpm -uvh http://rpms.remirepo.net/enterprise/remi-release-7.rpm
Copy after login

Install and update the software

Install the yum-config-manager utility

[root@opstrip.com opt]# yum -y install yum-utils
Copy after login

Update the current software version of the system

[root@opstrip.com opt]# yum -y update
Copy after login

Update Once completed, you can install the required php version.

Install php

After the above preparations are completed, you can install the required php version.

For php5.4

[root@opstrip.com opt]# yum -y install php
Copy after login

Before installation, you can try yum search php54 to search for installable software packages.

For php7.0

[root@opstrip.com opt]# yum-config-manager --enable remi-php70
[root@opstrip.com opt]# yum -y install php php-opcache
Copy after login

Before installation, you can try yum search php70 to search for installable software packages.

For php7.1

[root@opstrip.com opt]# yum-config-manager --enable remi-php71
[root@opstrip.com opt]# yum -y install php php-opcache
Copy after login

Before installation, you can try yum search php71 to search for installable software packages.

After completion, you need to add common php extensions:

[root@opstrip.com 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
Copy after login

For nginx

[root@opstrip.com 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
Copy after login

It is still recommended to try yum search nginxSearch for installable software before installation Bag.

After the installation is complete, configure php and nginx and start it to test the phpinfo page. It should be displayed normally at this time.

Source code compilation and installation

Preparation before installation

Download the php installation package

[root@opstrip.com opt]# wget -o php-7.1.5.tar.gz http://cn2.php.net/distributions/php-7.1.5.tar.gz
Copy after login

Unzip

[root@opstrip.com opt]# tar xf php-7.1.5.tar.gz
Copy after login

Install dependency packages

[root@opstrip.com 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
Copy after login

Configuration and installation

Compile configuration

[root@opstrip.com opt]# cd php-7.1.5
[root@opstrip.com 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
Copy after login

For details, please refer to the official PHP installation instructions document:

Compile and install

[root@opstrip.com php-7.1.5]# make && make install
Copy after login

Configure environment variables:

Append export path=$path:/usr/local/php/bin at the end of /etc/profile, and then execute source /etc/profileCheck the php version after taking effect:

[root@opstrip.com 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
Copy after login

Configuration after installation

Configuration php-fpm

After the installation is complete, you can start php-fpm through sapi/fpm/php-fpm.server. However, for the convenience of future management, it is usually necessary to place the configuration files in the /etc directory and add php-fpm.server to the systemctl service. As follows:

[root@opstrip.com php-7.1.5]# mkdir -p /etc/php-fpm.d
[root@opstrip.com php-7.1.5]# cp php.ini-production /etc/php.ini
[root@opstrip.com php-7.1.5]# cp sapi/fpm/php-fpm.service /usr/lib/systemd/system/
[root@opstrip.com php-7.1.5]# cp sapi/fpm/www.conf /etc/php-fpm.d/
Copy after login

Then change the /usr/lib/systemd/system/php-fpm.service file to execute the correct path, as follows:

[root@opstrip.com 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
Copy after login

Start php-fpm

When you start the php service through systemctl for the first time, you need to enable the php-fpm service first:

[root@opstrip.com php-7.1.5]# systemctl enable php-fpm.service
[root@opstrip.com php-7.1.5]# systemctl start php-fpm.service
Copy after login

Compile and install nginx

See details, and configure and start nginx as needed. I won’t write it down here.

Enable mysql extension (only compile and install)

Since php7 has completely removed mysql extension support (replaced by mysqli and mysqlnd), some old software After upgrading the php version, an error similar to the undefined mysql_connect() function will be reported. It is generally recommended to use the new phpmysqli or pdo extension to replace it. Of course, you can also check out the legacy version of the php7 code that supports the mysql extension and compile and install it yourself. However, it should be noted that the mysql extension has no subsequent updates at all.

Preparation before installation

View the current extension
View the current php7.1 built-in extension:

[root@opstrip.com 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
Copy after login

You can see that the mysql extension has indeed been has been removed, we can directly check out the old php mysql extension code in the ext directory.

Get the php mysql extension source code

[root@opstrip.com 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.
Copy after login

Compile and install the mysql extension

Compile using phpize

[root@opstrip.com ext]# cd mysql
[root@opstrip.com 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
[root@opstrip.com mysql]# /usr/local/php/bin/phpize
configuring for:
php api version:   20151012
zend module api no:  20151012
zend extension api no: 320151012
[root@opstrip.com mysql]# ./configure --with-php-config=/usr/local/php/bin/php-config
Copy after login

Install

[root@opstrip.com mysql]# make && make install
[root@opstrip.com mysql]# ls /usr/local/php/lib/php/extensions/no-debug-non-zts-20160303/
mysql.so opcache.a opcache.so
Copy after login

After the installation is complete, you need to confirm whether the mysql extension is installed correctly.

Finally modify the php.ini configuration file and add a line:

extension = "mysql.so"
Copy after login

Restart the php-fpm service and you will see the mysql extension in phpinfo:

How to deploy php7.1 and enable MySQL extension under CentOS7

The above is the detailed content of How to deploy php7.1 and enable MySQL extension under CentOS7. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!