Home Backend Development PHP Tutorial Compile and install PHP7 on CentOS 71

Compile and install PHP7 on CentOS 71

Jul 29, 2016 am 08:59 AM
enable nbsp php with

1 Create a php user and user group, and download the php7 source code from GitHub
First create a user named php without login permission and a user group named php, and then go to GitHub to download the php7 source code package.
#######Create new php user and php group
[root@typecodes ~]# groupadd -r php && useradd -r -g php -s /bin/false -d /usr/local/php7 -M php
######Download the php7 installation package from GitHub
[root@typecodes ~]# wget -c --no-check-certificate -O php7-src-master.zip https://github.com/php/ php-src/archive/master.zip
######Start decompressing the php7 package
[root@typecodes ~]# unzip -q php7-src-master.zip && cd php-src-master
#### #Install the dependency packages needed to compile php7
[root@typecodes php-src-master]# yum -y install libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel
2 Configuration of PHP7 compilation parameters
After the preparations are completed, the formal configuration of the installation details of php7 begins.Note, you must first remove the comment text added after the backslash "" below! ! !
######Start generating configuration file
[root@typecodes php-src-master]# ./buildconf
buildconf: checking installation...
buildconf: autoconf version 2.69 (ok)
rebuilding aclocal.m4
rebuilding Configureurebuilding main/pHP_config.h.in
##### Start configuration
[root@typecodes pHP-SRC-MASTER]#./configure





















































🎜 🎜 🎜 🎜 🎜 🎜 🎜 🎜 🎜 🎜 🎜 🎜 🎜 🎜 🎜 🎜 🎜 🎜 🎜 🎜 🎜 🎜 🎜 🎜 🎜 🎜 🎜 🎜 🎜 🎜 🎜 🎜 🎜 🎜 🎜-” directory]🎜--exec-prefix=/usr/local/php7 🎜--bindir=/usr/local/php7/bin 🎜--sbindir=/usr/local/php7/sbin 🎜--includedir=/usr/local /php7/include 🎜--libdir=/usr/local/php7/lib/php 🎜--mandir=/usr/local/php7/php/man 🎜--with-config-file-path=/usr/local/ php7/etc                                                                                                                                                                                                                                                       with-mhash 🎜--with-openssl                                                                                                                                                                                                                                                                                     ​                                                                                               [PHP7 depends on the mysql library] 🎜--with-gd 🎜 --with-iconv 🎜--with-zlib 🎜--enable-zip 🎜--enable-inline-optimization 🎜--disable-debug 🎜--disable-rpath 🎜--enable-shared 🎜--enable-xml 🎜 --enable-bcmath 🎜--enable-shmop 🎜--enable-sysvsem 🎜--enable-mbregex 🎜--enable-mbstring 🎜--enable-ftp 🎜--enable-gd-native-ttf 🎜--enable- pcntl 🎜--enable-sockets 🎜--with-xmlrpc 🎜--enable-soap 🎜--without-pear 🎜--with-gettext 🎜--enable-session                                                    🎜--with-curl                                                                        Allow Curl extension] 🎜-with-JPEG-DIR 🎜-With-FreeType-DIR 🎜 --Nable -opcache = No [Use OPCACHE cache] 🎜 --nable-FPM 🎜-WITH-FPM-User = nginx [ php-fpm user]🎜--with-fpm-group=nginx                                                                                                                                                                                                                  Use /usr/local/php7 --exec-prefix=/usr/local/php7 --bindir=/usr/local/php7/bin --sbindir=/usr/local/php7/sbin --includedir=/usr/local /php7/include --libdir=/usr/local/php7/lib/php --mandir=/usr/local/php7/php/man --with-config-file-path=/usr/local/php7/etc --with-mysql-sock=/var/run/mysql/mysql.sock --with-mcrypt=/usr/include --with-mhash --with-openssl --with-mysqli=shared,mysqlnd --with -pdo-mysql=shared,mysqlnd --with-gd --with-iconv --with-zlib --enable-zip --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-mbregex --enable-mbstring --enable-ftp --enable-gd-native-ttf - -enable-pcntl --enable-sockets --with-xmlrpc --enable-soap --without-pear --with-gettext --enable-session --with-curl --with-jpeg-dir --with-freetype-dir --enable-opcache=no --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --without-gdbm - -disable-fileinfo🎜Error message: configure: error: mcrypt.h not found. Please reinstall libmcrypt🎜Solution: Download libmcrypt-2.5.8.tar.gz and then compile and install🎜Download address: http://sourceforge.net/ projects/mcrypt/files/Libmcrypt/🎜If you recompile libmcrypt, remember the installation directory, and then compile the php item --with-mcrypt=your libmcrypt installation directory🎜./configure --prefix=/usr/local/php7 --exec-prefix=/usr/local/php7 --bindir=/usr/local/php7/bin --sbindir=/usr/local/php7/sbin --includedir=/usr/local/php7/include --libdir=/usr/local/php7/lib/php --mandir=/usr/local/php7/php/man --with-config-file-path=/usr/local/php7/etc --with-mysql-sock=/var/run/mysql/mysql.sock --with-mcrypt=/usr/local/libmcrytp/ --with-mhash --with-openssl --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-gd --with-iconv --with-zlib --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-mbregex --enable-mbstring --enable-ftp --enable-gd-native-ttf --enable-pcntl --enable-sockets --with-xmlrpc --enable-soap --without-pear --with-gettext --enable-session --with-curl --with-jpeg-dir --with-freetype-dir --enable-opcache --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --without-gdbm --disable-fileinfo
编译时遇到问题:Don't know how to define struct flock on this system, set --enable-opcache=no
解决方法:(我最终用这些方法还是没有解决)
一、yum groupinstall "Development Tools"。
二、编辑 /etc/ld.so.conf 加入/usr/local/lib,在执行ldconfig -v
提示:我在/usr/lib 看到libmysqlclient.so  所以在编辑/etc/ld.so.conf的时候,需要看一下,里面是否存在这个
3 开始编译和安装PHP7
相对编译安装MySQL的大量CPU和内存消耗,PHP7的编译安装轻松多了,整个过程大约1个小时左右。
在编译的时候,把--enable-opcache=no设为no,去掉了--enable-zip,所在安装完成之后,需要单独把这两个作为扩展安装
[root@typecodes php-src-master]# make clean && make && make install
如果遇到错误可参考:http://blog.chinaunix.net/uid-20776139-id-5421615.html
4 选做步骤:执行make test命令进行测试
这是一个非必需的操作步骤,执行make test命令。
有趣的一件事就是:在test期间,会和一个IP地址72.52.91.14建立tcp连接,它对应着php官网http://www.php.net。
5 查看编译成功后的PHP7安装目录
由于需要和MySQL进行通信,所以需要特别查看PHP7安装后的lib扩展库目录(/usr/local/php7/lib/php/extensions/no-debug-non-zts-20141001/)。需要确保至少存在mysqli.so、pdo_mysql.so这两个动态库文件。
6 开始设置PHP7的配置文件php.ini、php-fpm.conf、www.conf和php-fpm脚本
可以用编译后的配置文件复制到PHP7的配置目录(/usr/local/php7/etc/),推荐使用《PHP7中php.ini、php-fpm和www.conf的配置》文中整理的3个PHP7配置文件和php-fpm服务控制脚本。
#######方法一:直接使用编译后未经优化处理的配置
[root@typecodes php-src-master]# cp php.ini-production /usr/local/php7/etc/php.ini
[root@typecodes php-src-master]# cp /php-src-master/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@typecodes php-src-master]# cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
[root@typecodes php-src-master]# cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
#######方法二:使用https://typecodes.com/web/php7configure.html文中的配置 
[root@typecodes php-src-master]# mv ~/php.ini /usr/local/php7/etc/php.ini && mv ~/php-fpm /etc/init.d/php-fpm
[root@typecodes php-src-master]# mv ~/php-fpm.conf /usr/local/php7/etc/php-fpm.conf && mv ~/www.conf /usr/local/php7/etc/php-fpm.d/www.conf
7 添加php的环境变量
将php编译生成的bin目录添加到当前Linux系统的环境变量中
[root@typecodes ~]# echo -e 'nexport PATH=/usr/local/php7/bin:/usr/local/php7/sbin:$PATHn' >> /etc/profile && source /etc/profile
8 设置PHP日志目录和php-fpm进程文件(php-fpm.sock)目录
其中,设置php-fpm进程目录的用户和用户组为nginx,并创建php会话session目录。
#######Set the PHP log directory and the directory of the running process ID file (php-fpm.sock) of php-fpm
[root@typecodes ~]# mkdir -p /var/log/php-fpm/ && mkdir -p /var/run/php-fpm && cd /var/run/ && chown -R nginx:nginx php-fpm
#######Modify the directory configuration of the session
[root@typecodes etc]# mkdir -p /var/lib/php/session
[root@typecodes etc]# chown -R nginx:nginx /var/lib/php
9 Set up PHP startup and test whether the configuration file is correct
######Configuration Start automatically at boot and add to host sysV service
[root@typecodes php-src-master]# chmod +x /etc/init.d/php-fpm
[root@typecodes php-src-master]# chkconfig --add php-fpm
[root@typecodes php-src-master]# chkconfig php-fpm on
######Test whether the PHP configuration file is correct and legal
[root@typecodes sbin]# php-fpm -t
[ 03-May-2015 17:50:04] NOTICE: configuration file /usr/local/php7/etc/php-fpm.conf test is successful
10 Start the php service
After completing the above operations, you can officially use php Served. The command to start the php process service is as follows:
[root@typecodes sbin]# service php-fpm start
Starting php-fpm done
11 Install opcache
Tutorial: http://blog.jjonline.cn/linux/135.html
Tutorial: http://blog.ich8.com/post/4142
Tutorial: http://my.oschina.net/u/919580/blog/406900 Practice has proven that this is available
Installation:
Linux
Install Zend Opcache (pecl Version):
Remove eaccelerator, xcache, apc:
yum remove php-eaccelerator php-xcache php-apcu
Skip if not used.
Upgrade the system:
yum update
Install Zend Opcache (pecl version)
yum install php-pecl-zendopcache PS: However, the php-pecl-zendopcache extension is still not found on centos7, so the following cannot be continued
Generated during installation The opcache configuration file is located in the default /etc/php.d directory:
opcache-default.blacklist
opcache.ini
This configuration file basically uses the recommended settings in the README, and only a few places need to be modified.
vi /etc/php.d/opcache.ini
Just modify and save the recommended configuration as follows:
opcache.memory_c>opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
opcache.fast_shutdown= 1
opcache.enable_cli=1
There is no need to modify the php.ini configuration. Restart the Apache service to make it take effect:
service httpd restart
Check to see if it is started correctly:
php -v
The output result is similar to:
PHP 7 (cli) (built: Apr 11 2013 11:04:35)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
with Zend OPcache v7.0.1 , Copyright (c) 1999-2013, by Zend Technologies

The above introduces the compilation and installation of PHP7 on CentOS 71, including the relevant aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

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)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

7 PHP Functions I Regret I Didn't Know Before 7 PHP Functions I Regret I Didn't Know Before Nov 13, 2024 am 09:42 AM

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

PHP Program to Count Vowels in a String PHP Program to Count Vowels in a String Feb 07, 2025 pm 12:12 PM

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? Apr 03, 2025 am 12:03 AM

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

See all articles