Home Database Mysql Tutorial How to deploy php7.1 and enable MySQL extension under CentOS7

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

May 28, 2023 pm 03:01 PM
mysql php centos7

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!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1663
14
PHP Tutorial
1266
29
C# Tutorial
1237
24
MySQL and phpMyAdmin: Core Features and Functions MySQL and phpMyAdmin: Core Features and Functions Apr 22, 2025 am 12:12 AM

MySQL and phpMyAdmin are powerful database management tools. 1) MySQL is used to create databases and tables, and to execute DML and SQL queries. 2) phpMyAdmin provides an intuitive interface for database management, table structure management, data operations and user permission management.

The Compatibility of IIS and PHP: A Deep Dive The Compatibility of IIS and PHP: A Deep Dive Apr 22, 2025 am 12:01 AM

IIS and PHP are compatible and are implemented through FastCGI. 1.IIS forwards the .php file request to the FastCGI module through the configuration file. 2. The FastCGI module starts the PHP process to process requests to improve performance and stability. 3. In actual applications, you need to pay attention to configuration details, error debugging and performance optimization.

Explain the purpose of foreign keys in MySQL. Explain the purpose of foreign keys in MySQL. Apr 25, 2025 am 12:17 AM

In MySQL, the function of foreign keys is to establish the relationship between tables and ensure the consistency and integrity of the data. Foreign keys maintain the effectiveness of data through reference integrity checks and cascading operations. Pay attention to performance optimization and avoid common errors when using them.

SQL vs. MySQL: Clarifying the Relationship Between the Two SQL vs. MySQL: Clarifying the Relationship Between the Two Apr 24, 2025 am 12:02 AM

SQL is a standard language for managing relational databases, while MySQL is a database management system that uses SQL. SQL defines ways to interact with a database, including CRUD operations, while MySQL implements the SQL standard and provides additional features such as stored procedures and triggers.

Compare and contrast MySQL and MariaDB. Compare and contrast MySQL and MariaDB. Apr 26, 2025 am 12:08 AM

The main difference between MySQL and MariaDB is performance, functionality and license: 1. MySQL is developed by Oracle, and MariaDB is its fork. 2. MariaDB may perform better in high load environments. 3.MariaDB provides more storage engines and functions. 4.MySQL adopts a dual license, and MariaDB is completely open source. The existing infrastructure, performance requirements, functional requirements and license costs should be taken into account when choosing.

How to safely store JavaScript objects containing functions and regular expressions to a database and restore? How to safely store JavaScript objects containing functions and regular expressions to a database and restore? Apr 19, 2025 pm 11:09 PM

Safely handle functions and regular expressions in JSON In front-end development, JavaScript is often required...

What happens if session_start() is called multiple times? What happens if session_start() is called multiple times? Apr 25, 2025 am 12:06 AM

Multiple calls to session_start() will result in warning messages and possible data overwrites. 1) PHP will issue a warning, prompting that the session has been started. 2) It may cause unexpected overwriting of session data. 3) Use session_status() to check the session status to avoid repeated calls.

How does MySQL differ from Oracle? How does MySQL differ from Oracle? Apr 22, 2025 pm 05:57 PM

MySQL is suitable for rapid development and small and medium-sized applications, while Oracle is suitable for large enterprises and high availability needs. 1) MySQL is open source and easy to use, suitable for web applications and small and medium-sized enterprises. 2) Oracle is powerful and suitable for large enterprises and government agencies. 3) MySQL supports a variety of storage engines, and Oracle provides rich enterprise-level functions.

See all articles