search
HomeBackend DevelopmentPHP TutorialLNMP source code compilation and installation php-5.5.32 instance

This article mainly shares with you the LNMP source code compilation and installation example of php-5.5.32. I hope it can help you.

1 What is CGI

  • The full name of CGI is "Common Gateway Interface" (Common Gateway Interface), which serves programs on HTTP
    servers and other machines A tool for communication, CGI programs must run on a network server.

  • The main disadvantage of the traditional CGI interface method is poor performance, because every time the HTTP server encounters a dynamic program, it needs to restart the parser to perform parsing, and then the result will be Returned to the HTTP server. This is almost unavailable when dealing with high concurrent access, so FastCGI was born. In addition, the traditional CGI interface method has poor security, so it is rarely used now.

2 What is FastCGI

  • FastCGI is a scalable, high-speed communication interface between HTTP servers and dynamic scripting languages ​​(in Under Linux, the FastCGI interface is a socket, which can be a file socket or an IP socket). The main advantage is to separate the dynamic language and the HTTP server. Most popular HTTP servers support FastCGI. Including Apache, Nginx and Lighttpd, etc.

  • At the same time, FastCGI is also supported by many scripting languages, one of the more popular scripting languages ​​is PHP. The FastCGI interface adopts the C/S (Client/Server) architecture, which can separate the HTTP server and the script parsing server, and can also start one or more scripts on the script parsing server to parse the daemon process. When the HTTP server encounters a dynamic program, it can be delivered directly to the FastCGI process for execution, and then the result is returned to the browser. This method allows the HTTP server to exclusively handle static requests, or return the results of the dynamic script server to the client, which greatly improves the performance of the entire application system.

3 The operating principle of Nginx FastCGI

Nginx does not support direct calling or parsing of external dynamic programs. All external programs (including PHP) must pass the FastCGI interface. transfer. The FastCGI interface is a socket under Linux. In order to call a CGI program, a FastCGI wrapper is also needed (which can be understood as a program used to start another program). This wrapper is bound to a fixed socket, such as a port or file socket. . When Nginx sends a CGI request to this socket, through the FastCGI interface, the wrapper receives the request and then spawns a new thread. This thread calls the interpreter or external program processing script to read the returned data; then, the wrapper then The returned data is passed to Nginx through the FastCGI interface and along the fixed socket; finally, Nginx sends the returned data to the client. This is the entire operation process of Nginx+FastCGI. The detailed process is shown below.

LNMP source code compilation and installation php-5.5.32 instance

4 LNMP PHP (Fastcgi) service installation preparation

4.1 Check the installation of Nginx and MySQL

[root@web01 ~]# netstat -lntup |egrep "nginx|mysql"tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      1568/mysqld         
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      1694/nginx          
[root@web01 ~]# cat /etc/redhat-release CentOS release 6.9 (Final)
[root@web01 ~]# uname -r2.6.32-696.el6.x86_64
[root@web01 ~]# uname -mx86_64

4.2 Check the installation of PHP Required lib library

# When the PHP program is developed and run, it will call some function libraries such as zlib, gd, etc., so you need to confirm whether the LIB library has been installed. The execution command is as follows:

rpm -qa zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel
rpm -qa freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel

Tip: libjpeg-turbo-devel is the new name of the early libjpeg-devel, and libcurl-devel is the new name of the early curl-devel.
Each lib generally has a corresponding package named "-devel". After installing the corresponding "-devel" package, the corresponding lib package will be automatically installed. For example, if you install gd-devel, it will be installed. gd.

# 这些lib库也不是必须安装的,但是目前的企业环境下一般都需要安装。否则,PHP程序运行有问题,例如验证码无法显示等。[root@web01 ~]# rpm -qa freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel[root@web01 ~]# [root@web01 ~]# rpm -qa zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-develzlib-devel-1.2.3-29.el6.x86_64# 一般都没有安装,需要yum安装下yum -y install zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel
yum -y install freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel# 再次检查,发现没有libiconv-devel这个包,需要手动安装下[root@web01 tools]# rpm -qa zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-develzlib-devel-1.2.3-29.el6.x86_64
libjpeg-turbo-devel-1.2.1-3.el6_5.x86_64
libxml2-devel-2.7.6-21.el6_8.1.x86_64
[root@web01 tools]# rpm -qa freetype-devel libpng-devel gd-devel libcurl-devel libxslt-develfreetype-devel-2.3.11-17.el6.x86_64
libpng-devel-1.2.49-2.el6_7.x86_64
libcurl-devel-7.19.7-53.el6_9.x86_64
libxslt-devel-1.1.26-2.el6_3.1.x86_64
gd-devel-2.0.35-11.el6.x86_64
[root@web01 ~]# cd /home/oldboy/tools/ [root@web01 tools]# wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz[root@web01 tools]# tar -zxf libiconv-1.14.tar.gz [root@web01 tools]# cd libiconv-1.14[root@web01 libiconv-1.14]# ./configure --prefix=/usr/local/libiconv[root@web01 libiconv-1.14]# make && make install# 安装php的相关扩展库,需要先安装epel源# 安装libmcrypt库,这是一个使用动态加载的模块化的库,这个不是必须的库,在开发的时候需要用到[root@web01 tools]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo[root@web01 tools]# yum install -y libmcrypt-devel# 安装mhash加密扩展库[root@web01 tools]# yum install -y mhash# 安装mcrypt加密扩展库[root@web01 tools]# yum install -y mcrypt# 检查[root@web01 tools]# rpm -qa libmcrypt mcrypt mhashmcrypt-2.6.8-10.el6.x86_64
libmcrypt-2.5.8-9.el6.x86_64
mhash-0.9.9.9-3.el6.x86_64

4.3 Obtain the php software package, compile and install it

# 获取php-5.5.32
[root@web01 tools]# wget http://mirrors.sohu.com/php/php-5.5.32.tar.gz
# 解压配置php
[root@web01 tools]# tar -xf php-5.5.32.tar.gz 
[root@web01 tools]# cd php-5.5.32
# 编译;注意每一行后边的反斜线(\)后边不能有任何特殊字符包括空格
# --with-fpm-user=www & --with-fpm-group=www 这两个模块的www是在Nginx安装时候创建的用户
./configure \
--prefix=/application/php5.5.32 \--with-mysql=/application/mysql/ \--with-pdo-mysql=mysqlnd \--with-iconv-dir=/usr/local/libiconv \--with-freetype-dir \--with-jpeg-dir \--with-png-dir \--with-zlib \--with-libxml-dir=/usr \--enable-xml \--disable-rpath \--enable-bcmath \--enable-shmop \--enable-sysvsem \--enable-inline-optimization \--with-curl \--enable-mbregex \--enable-fpm \--enable-mbstring \--with-mcrypt \--with-gd \--with-openssl \--with-mhash \--enable-gd-native-ttf \--enable-pcntl \--enable-sockets \--with-xmlrpc \--enable-soap \--enable-short-tags \--enable-static \--with-xsl \--with-fpm-user=www \--with-fpm-group=www \--enable-ftp \--enable-opcache=no[root@web01 php-5.5.32]# echo $?
0
# 在make install之前需要先做以下操作
[root@web01 php-5.5.32]# ln -s /application/mysql/lib/libmysqlclient.so.18 /usr/lib64/
[root@web01 php-5.5.32]# touch ext/phar/phar.phar
[root@web01 php-5.5.32]# vim /etc/ld.so.conf
[root@web01 php-5.5.32]# tail -1 /etc/ld.so.conf/application/mysql/lib/[root@web01 php-5.5.32]# ldconfig
# make && make install(make -j可以指定多颗CPU,在CPU颗数多的情况下),时间比较长。
[root@web01 php-5.5.32]# make
......

Build complete.
Don't forget to run 'make test'.    # 这样make完毕(等了许久)

[root@web01 php-5.5.32]# make install
......
ln -s -f phar.phar /application/php5.5.32/bin/phar
Installing PDO headers:          /application/php5.5.32/include/php/ext/pdo/        # make install完毕
[root@web01 php-5.5.32]# ln -s /application/php5.5.32/ /application/php
[root@web01 php-5.5.32]# ls /application/php
bin  etc  include  lib  php  sbin  var
[root@web01 php-5.5.32]# ls php.ini* -l
-rw-r--r-- 1 1001 1001 69236 Feb  2  2016 php.ini-development   #开发环境的配置文件-rw-r--r-- 1 1001 1001 69266 Feb  2  2016 php.ini-production    #生产环境的配置文件[root@web01 php-5.5.32]# cp php.ini-production /application/php/lib/php.ini #php配置文件默认路径
[root@web01 php-5.5.32]# cd /application/php/etc/
[root@web01 etc]# cp php-fpm.conf.default php-fpm.conf
[root@web01 etc]# /application/php/sbin/php-fpm 
[root@web01 etc]# lsof -i :9000
COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
php-fpm 15200 root    7u  IPv4 127921      0t0  TCP localhost:cslistener (LISTEN)
php-fpm 15201  www    0u  IPv4 127921      0t0  TCP localhost:cslistener (LISTEN)
php-fpm 15202  www    0u  IPv4 127921      0t0  TCP localhost:cslistener (LISTEN)
[root@web01 etc]# ps -ef |grep php-fpm
root      15200      1  0 21:35 ?        00:00:00 php-fpm: master process (/application/php5.5.32/etc/php-fpm.conf)
www       15201  15200  0 21:35 ?        00:00:00 php-fpm: pool www            
www       15202  15200  0 21:35 ?        00:00:00 php-fpm: pool www            
root      15205   1668  0 21:35 pts/0    00:00:00 grep php-fpm
# 到此为止php安装完毕

The above is the detailed content of LNMP source code compilation and installation php-5.5.32 instance. For more information, please follow other related articles on the PHP Chinese website!

Statement
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
The Continued Use of PHP: Reasons for Its EnduranceThe Continued Use of PHP: Reasons for Its EnduranceApr 19, 2025 am 12:23 AM

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python: Exploring Their Similarities and DifferencesPHP and Python: Exploring Their Similarities and DifferencesApr 19, 2025 am 12:21 AM

PHP and Python are both high-level programming languages ​​that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP and Python: Different Paradigms ExplainedPHP and Python: Different Paradigms ExplainedApr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python: A Deep Dive into Their HistoryPHP and Python: A Deep Dive into Their HistoryApr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Choosing Between PHP and Python: A GuideChoosing Between PHP and Python: A GuideApr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Frameworks: Modernizing the LanguagePHP and Frameworks: Modernizing the LanguageApr 18, 2025 am 12:14 AM

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHP's Impact: Web Development and BeyondPHP's Impact: Web Development and BeyondApr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

How does PHP type hinting work, including scalar types, return types, union types, and nullable types?How does PHP type hinting work, including scalar types, return types, union types, and nullable types?Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

See all articles

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

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.