


Detailed introduction to the sample code for compiling and installing PHP7 on CentOS7 (picture)
Create php user and user group
First create a user named php without login permission and a user group named php
#######新建php用户和php组[root@localhost ~] # groupadd -r php && useradd -r -g php -s /bin/false -d /usr/local/php7 -M php
Compile the dependencies required to install php 7
Compile and install libmcrypt, mhash, mcrypt binary source package
The reason why libmcrypt is compiled and installed here is because the yum installation seems to report an error
######编译安装libmcrypt-2.5.7 [root@localhost ~]# tar zxvf libmcrypt-2.5.7.tar.gz [root@localhost ~]# cd libmcrypt-2.5.7 [root@localhost libmcrypt-2.5.7]# ./configure --prefix=/usr/local/related/libmcrypt [root@localhost libmcrypt-2.5.7]# make && make install [root@localhost libmcrypt-2.5.7]# cd ~ [root@localhost ~]# rm -rf libmcrypt-2.5.7*
######编译安装mhash-0.9.9.9 [root@localhost ~]# tar zxf mhash-0.9.9.9.tar.gz [root@localhost ~]# cd mhash-0.9.9.9 [root@localhost mhash-0.9.9.9]# ./configure --prefix=/usr/local/related/mhash [root@localhost mhash-0.9.9.9]# make && make install [root@localhost mhash-0.9.9.9]# cd ~ [root@localhost ~]# rm -rf mhash-0.9.9.9*
######编译安装mcrypt-2.6.8 [root@localhost ~]# tar zxf mcrypt-2.6.8.tar.gz && cd mcrypt-2.6.8 [root@localhost mcrypt-2.6.8]# export LD_LIBRARY_PATH=/usr/local/related/libmcrypt/lib:/usr/local/related/mhash/lib [root@localhost mcrypt-2.6.8]# export LDFLAGS="-L/usr/local/related/mhash/lib -I/usr/local/related/mhash/include/" [root@localhost mcrypt-2.6.8]# export CFLAGS="-I/usr/local/related/mhash/include/" [root@localhost mcrypt-2.6.8]# ./configure --prefix=/usr/local/related/mcrypt --with-libmcrypt-prefix=/usr/local/related/libmcrypt [root@localhost mcrypt-2.6.8]# make && make install [root@localhost mcrypt-2.6.8]# cd ~ [root@localhost ~]# rm -rf mcrypt-2.6.8*
######其他依赖yum安装[root@localhost ~] # yum -y install libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel
Configuration of PHP 7 compilation parameters
Note that during operation, you must first remove the comment text added after the backslash "\" below! ! !
######生成配置文件 [root@localhost ~]# tar -zxf php-7.0.0.tar.gz && cd php-7.0.0 [root@localhost php-7.0.0]# ./buildconf --force Forcing buildconf Removing configure caches buildconf: checking installation... buildconf: autoconf version 2.69 (ok) rebuilding configure rebuilding main/php_config.h.in ######开始配置 [root@localhost php-7.0.0]# ./configure \ --prefix=/usr/local/php7 \ [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 \ [PHP7的配置目录] --with-mysql-sock=/var/run/mysql/mysql.sock \ [PHP7的Unix socket通信文件] --with-mcrypt=/usr/include \ --with-mhash \ --with-openssl \ --with-mysql=shared,mysqlnd \ [PHP7依赖mysql库] --with-mysqli=shared,mysqlnd \ [PHP7依赖mysql库] --with-pdo-mysql=shared,mysqlnd \ [PHP7依赖mysql库] --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 \ [允许php会话session] --with-curl \ [允许curl扩展] --with-jpeg-dir \ --with-freetype-dir \ --enable-opcache \ [使用opcache缓存] --enable-fpm \ --enable-fastcgi \ --with-fpm-user=nginx \ [php-fpm的用户] --with-fpm-group=nginx \ [php-fpm的用户组] --without-gdbm \ --with-mcrypt=/usr/local/related/libmcrypt \ [指定libmcrypt位置] --disable-fileinfo
The results of executing the above configuration command are as follows:
Start compiling and installing PHP 7
[root@localhost php-7.0.0]# make clean && make && make install
PHP 7 was compiled and installed successfully
Optional steps: execute the make test command for testing
This is an optional step, execute the make test command
Check the PHP7 installation directory after successful compilation
Since you need to communicate with MySQL, you need to specifically check the lib extension library directory after PHP7 is installed (/usr/local/php7/lib/php/ extensions/no-debug-non-zts-20151012/). You need to ensure that at least two dynamic library files mysqli.so and pdo_mysql.so exist, as shown in the figure below.
[root@localhost php-7.0.0]# ls -lrt /usr/local/php7/lib/php/extensions/no-debug-non-zts-20151012/
Start setting up the PHP7 configuration files php.ini, php-fpm.conf, www.conf and php-fpm scripts
can be compiled with Copy the configuration file to the PHP7 configuration directory (/usr/local/php7/etc/). It is recommended to use the configuration in github. This configuration comes from "Configuration of php.ini, php-fpm and www.conf in PHP7"
#######方法一:直接使用编译后未经优化处理的配置 [root@localhost php-7.0.0]# cp php.ini-production /usr/local/php7/etc/php.ini [root@localhost php-7.0.0]# cp /root/php-7.0.0/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm [root@localhost php-7.0.0]# cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf [root@localhost php-7.0.0]# cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf #######方法二:使用https://github.com/lizer2014/mylnmp/tree/master/PHP文中的配置 [root@localhost php-7.0.0]# mv ~/php.ini /usr/local/php7/etc/php.ini && mv ~/php-fpm /etc/init.d/php-fpm [root@localhost php-7.0.0]# mv ~/php-fpm.conf /usr/local/php7/etc/php-fpm.conf && mv ~/www.conf /usr/local/php7/etc/php-fpm.d/www.conf
Note: You need to modify the parameters in the php.ini configuration and change extension_dir to your own
extension_dir = "/usr/local/php7/lib/php/extensions/no-debug-non-zts-20151012/"
In /etc/init.d/php-fpm, there must be a make /var/run/php-fpm command before the daemon process of the start function. Otherwise, restarting the server will cause the startup to fail. In nginx Configuration also has this problem
Add php environment variables
[root@localhost php-7.0.0]# echo -e '\nexport PATH=/usr/local/php7/bin:/usr/local/php7/sbin:$PATH\n' >> /etc/profile && source /etc/profile
Set the PHP log directory and the php-fpm process file (php-fpm.sock) directory
Among them, set php -The user and user group of the fpm process directory are nginx, and create a php session session directory
#######设置PHP日志目录和php-fpm的运行进程ID文件(php-fpm.sock)目录 [root@localhost php-7.0.0] # groupadd -r nginx && useradd -r -g nginx -s /bin/false -M nginx [root@localhost php-7.0.0] # mkdir -p /var/log/php-fpm/ && mkdir -p /var/run/php-fpm && cd /var/run/ && chown -R nginx:nginx php-fpm #######修改session的目录配置 [root@localhost run]# mkdir -p /var/lib/php/session [root@localhost run] # chown -R nginx:nginx /var/lib/php
Set up PHP startup and test whether the configuration file is correct
######配置开机自启动,增加到主机sysV服务 [root@localhost run]# chmod +x /etc/init.d/php-fpm [root@localhost run]# chkconfig --add php-fpm [root@localhost run]# chkconfig php-fpm on ######测试PHP的配置文件是否正确合法 [root@localhost run]# php-fpm -t [05-Dec-2015 17:33:03] NOTICE: configuration file /usr/local/php7/etc/php-fpm.conf test is successful
Start the php service
After completing the above operations, you can officially use the php service. The command to start the php process service is as follows:
[root@localhost init.d]# service php-fpm startStarting php-fpm done
Then you can check whether it is successful through the command ps -aux|grep php (the number of php-fpm processes and the process user nginx in the picture are both determined by pm in www.conf. The values of start_servers and user are determined respectively):
View PHP7 version information
Finally, you can view the current PHP version information through the command php -v, as shown in Figure You can see that currently PHP7 also uses Zend OPcache cache because the zend_extension=opcache.so configuration was added to the php.ini file.
Related articles:
Mac uses the php installed by itself by default
centos6.7 installation Detailed introduction to php7
The above is the detailed content of Detailed introduction to the sample code for compiling and installing PHP7 on CentOS7 (picture). For more information, please follow other related articles on the PHP Chinese website!

TooptimizePHPcodeforreducedmemoryusageandexecutiontime,followthesesteps:1)Usereferencesinsteadofcopyinglargedatastructurestoreducememoryconsumption.2)LeveragePHP'sbuilt-infunctionslikearray_mapforfasterexecution.3)Implementcachingmechanisms,suchasAPC

PHPisusedforsendingemailsduetoitsintegrationwithservermailservicesandexternalSMTPproviders,automatingnotificationsandmarketingcampaigns.1)SetupyourPHPenvironmentwithawebserverandPHP,ensuringthemailfunctionisenabled.2)UseabasicscriptwithPHP'smailfunct

The best way to send emails is to use the PHPMailer library. 1) Using the mail() function is simple but unreliable, which may cause emails to enter spam or cannot be delivered. 2) PHPMailer provides better control and reliability, and supports HTML mail, attachments and SMTP authentication. 3) Make sure SMTP settings are configured correctly and encryption (such as STARTTLS or SSL/TLS) is used to enhance security. 4) For large amounts of emails, consider using a mail queue system to optimize performance.

CustomheadersandadvancedfeaturesinPHPemailenhancefunctionalityandreliability.1)Customheadersaddmetadatafortrackingandcategorization.2)HTMLemailsallowformattingandinteractivity.3)AttachmentscanbesentusinglibrarieslikePHPMailer.4)SMTPauthenticationimpr

Sending mail using PHP and SMTP can be achieved through the PHPMailer library. 1) Install and configure PHPMailer, 2) Set SMTP server details, 3) Define the email content, 4) Send emails and handle errors. Use this method to ensure the reliability and security of emails.

ThebestapproachforsendingemailsinPHPisusingthePHPMailerlibraryduetoitsreliability,featurerichness,andeaseofuse.PHPMailersupportsSMTP,providesdetailederrorhandling,allowssendingHTMLandplaintextemails,supportsattachments,andenhancessecurity.Foroptimalu

The reason for using Dependency Injection (DI) is that it promotes loose coupling, testability, and maintainability of the code. 1) Use constructor to inject dependencies, 2) Avoid using service locators, 3) Use dependency injection containers to manage dependencies, 4) Improve testability through injecting dependencies, 5) Avoid over-injection dependencies, 6) Consider the impact of DI on performance.

PHPperformancetuningiscrucialbecauseitenhancesspeedandefficiency,whicharevitalforwebapplications.1)CachingwithAPCureducesdatabaseloadandimprovesresponsetimes.2)Optimizingdatabasequeriesbyselectingnecessarycolumnsandusingindexingspeedsupdataretrieval.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 Linux new version
SublimeText3 Linux latest version
