Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces "how to deploy php7.1 and open MySQL extension under CentOS7". In daily operation, I believe many people have doubts about how to deploy php7.1 and open MySQL extension under CentOS7. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubt of "how to deploy php7.1 and open MySQL extension under CentOS7". Next, please follow the editor to study!

Simple installation (yum mode)

Install the software source

Add epel Feed

[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

Add remi Feed

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

Install and update the software

Install the yum-config-manager utility

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

Update the current software version of the system

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

After the update is complete, you can install the required version of php.

Install php

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

For php5.4

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

Try yum search php54 to search for installable packages before installation.

For php7.0

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

Try yum search php70 to search for installable packages before installation.

For php7.1

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

Try yum search php71 to search for installable packages before installation.

When you are finished, you also need to add php common 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

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

It is still recommended that you try yum search nginx to search for installable packages before installation.

After the installation is complete, configure php and nginx and launch the test phpinfo page, which should display normally.

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

Decompression

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

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

Configuration and installation

Compilation 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

For more information, please see the official installation documentation of php:

Compilation and installation

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

Configure environment variables:

Append export path=$path:/usr/local/php/bin to the end of / etc/profile, and then execute source / etc/profile to check the php version after it takes effect:

[root@opstrip.com php-7.1.5] # php- vphp 7.1.5 (cli) (built: may 31 2017 16:12:38) (nts) copyright (c) 1997-2017 the php groupzend engine v3.1.0, copyright (c) 1998-2017 zend technologies

Configuration after installation

Configure php-fpm

After the installation is complete, you can start php-fpm through sapi/fpm/php-fpm.server. However, for ease of management later, it is usually necessary to unify the configuration files into 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/

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 managerafter=network.target [service] type=simplepidfile=/var/run/php-fpm.pidexecstart=/usr/local/php/sbin/php-fpm-- nodaemonize-- fpm-config / etc/php-fpm.confexecreload=/bin/kill-usr2 $mainpidprivatetmp=true [install] wantedby=multi-user.target

Start php-fpm

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

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

Compile and install nginx

See for details and configure and start nginx as needed. It's not written here.

Open the mysql extension (compile and install only)

Since php7 has completely removed mysql extension support (replaced by mysqli and mysqlnd), some old software will report errors similar to the undefined mysql_connect () function after upgrading the php version, and it is generally recommended to replace it with a new phpmysqli or pdo extension. Of course, you can also check out the legacy version of the php7 code that supports the mysql extension to compile and install itself, but it is important to note that there are no subsequent updates for the mysql extension.

Pre-installation preparation

View current extension

View the extension that comes with the current php7.1:

[root@opstrip.com php-7.1.5] # ls extbcmath dom gd json oci8 pdo_firebird posix skeleton sysvsem xmlwriterbz2 enchant gettext ldap odbc pdo_mysql pspell snmp sysvshm xslcalendar exif gmp libxml opcache pdo_oci readline soap tidy zipcom_dotnet ext_skel hash mbstring openssl pdo_odbc recode sockets tokenizer zlibctype ext_skel_win32.php iconv mcrypt pcntl pdo_pgsql reflection spl wddxcurl fileinfo imap mysql pcre pdo_sqlite session sqlite3 xmldate filter interbase mysqli pdo pgsql Shmop standard xmlreaderdba ftp intl mysqlnd pdo_dblib phar simplexml sysvmsg xmlrpc

You can see that the mysql extension has indeed been removed, and we can check out the old php mysql extension code directly 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-- recursivecloning into 'mysql'...remote: counting objects: 145, done.remote: total 145 (delta 0), reused 0 (delta 0), pack-reused 145receiving objects: 100% (145 delta), 88.41 kib | 0 bytes/s, done.resolving deltas: 100% (65 delta 65), done.checking connectivity... Done.

Compile and install the mysql extension

Compile with phpize

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

Installation

[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.an opcache.so

After the installation is complete, verify that the mysql extension is installed correctly.

Finally, modify the php.ini configuration file by adding one line:

Extension = "mysql.so"

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

At this point, the study on "how to deploy php7.1 and open MySQL extension under CentOS7" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report