Linux 6 under Compile and install configuration lamp platform

Source: Internet
Author: User
Tags fpm install php php server

The LAMP (linux-apache-mysql-php) website architecture is currently a popular international web framework that includes: Linux operating system, Apache Web server, MySQL database, Perl, PHP or Python programming language, All components are open source software, is an internationally mature architecture framework, many popular commercial applications are to adopt this architecture, and JAVA/J2EE architecture, lamp with rich web resources, lightweight, rapid development features, Microsoft's. NET architecture, lamp has a common, cross-platform, high-performance, low-cost advantages, so lamp whether it is performance, quality or price is the preferred platform for enterprises to build websites. This paper mainly describes the central architecture of lamp and the installation lamp environment, where p refers to PHP.

One, lamp architecture request Description
client http(请求index.php或者index.html)        --->apache(httpd web服务器响应,如果是静态文件,则直接响应,如果是动态请求则转向下一步)             --->php 接受请求(php解释器通过fastcgi响应,如果需要查询数据则转向一下)                         --->透过mysql客户端查询数据库(mysql驱动)                                       --->mysql服务器响应数据库查询(返回查询结果)
Second, lamp deployment common scenarios
LAMP根据业务访问量可以将其部署在一台机器上面,也可以分离部署到不通的机器,如下:整合方案:LAMP分离方案:        LA + P + M        LAP + M        LA + M + P        LAM + P
III. compilation and installation procedures and dependencies
由于php有相关依赖性因此建议:    安装次序为httpd或mysql,再装php。httpd把.php资源的请求“反向代理”至php服务器;httpd依赖于反向代理模块以及专用于fastcgi反向代理模块httpd-2.2默认没有附带专用fastcgi反向代理模块,所以需要独立安装;httpd-2.4已自带fastcgi反向模块,此模块为mod_proxy_fcgi.so,它其实是作为mod_proxy.so模块的扩充       httpd-2.4
Iv. compiling the installation process 1, compiling and installing httpd

Direct reference: Linux under Compile and install Apache HTTPD 2.4

2. Compile and install MySQL

Direct reference: Linux under the MySQL source installation full version

3. Compile and install PHP

Direct reference: Linux 6 under compile and install PHP 5.6

V. Configuration Note 1, lamp fully integrated configuration on a single server
# vim/etc/httpd24/httpd.conf # # #注意此处, I'm here to compile the httpd2.4 version of the installation separately, so the paths are differentLoadModule Proxy_module Modeles/mod_proxy. soLoadModule Proxy_fcgi_module modules/mod_proxy_fcgi. so        # # #在 <ifmodule mime_module> module addedAddType application/x-httpd-php. PHPAddType application/x-httpd-php-source. PhpsProxyrequests OFF# # #关闭正向代理, turn on the downstream reverse proxyProxypassmatch ^/(. *\. PHP) $ fcgi://127.0. 0. 1:9000/usr/local/apache/htdocs/$1DirectoryIndex Index. PHPIndex. html
2, lamp separation mode to the configuration of the server is not through
Aapache 需要按照上面的方法装载模块以及添加类型Aapache 在配置反向代理时,应指定PHP服务器的IP地址及相应端口号,前后端路径可以不一致,后端应指定绝对路径    如前端为/var/www/html,后端为/website/www,则fcgi://127.0.0.1:9000/website/www/$1        PHP进程服务的配置文件php-fpm.conf配置文件中应修改监听配置        如假定PHP服务器的IP为192.168.1.253,此IP可接受外网请求            httpd.conf    fcgi://192.168.1.253:9000            php-fpm.conf    =192.168.1.253:9000
Six, Apache and PHP connection mode
1、动态模块方式:  prefork模式使用libphp5模块    worker和event模式则使用libphp5-zts模块2、CGI方式:CGI(Common Gateway Interface 简称通用网关接口)。CGI是外部应用程序(CGI程序)与Web服务器之间的接口标准,是在CGI程序和Web服务器之间传递信息的过程。CGI规范允许Web服务器执行外部程序,并将它们的输出发送给Web浏览器,    CGI将Web的一组简单的静态超媒体文档变成一个完整的新的交互式媒体。其工作流程如下:a、浏览器通过HTML表单或超链接请求指向一个CGI应用程序的URL。b、服务器收发到请求。c、服务器执行指定CGI应用程序(开启进程)d、CGI应用程序执行所需要的操作,通常是基于浏览者输入的内容。e、CGI应用程序把结果格式化为网络服务器和浏览器能够理解的文档(通常是HTML网页)。f、网络服务器把结果返回到浏览器中(销毁进程)

Workflow diagram

3、FastCGI方式:   FastCGI像是一个常驻(long-live)型的CGI,它可以一直执行着,只要激活后,不会每次都要花费时间去fork一次。       (这是CGI最为人诟病的fork-and-execute 模式)。   ServerServerServer时,FastCGI进程管理器选择并连接到一个CGI解释器。    serverServer。    当FastCGI子进程关闭连接时,请求便告处理完成。   Server中)的下一个连接。   在CGI模式中,php-cgi在此便退出了。

FastCGI Workflow Diagram

4、CGI与FastCGI两者差异主要在于:        CGI在处理任何一个请求需要开启进程,销毁进程,开销较大        FastCGI会在初始化的时候启动多个cgi进程,监听来自网络的请求;        当处理完毕任务后则由FastCGI进程管理器回收管理,省去反复创建回收的开销。
Vii. Verification
The following is a separate architecture of lamp after the installation of the environment1, Web server# cat/etc/redhat-releaseCentOS Linux Release7.2. 1511(Core)# httpd-vServer version:apache/2.4. 6(CentOS) Server Built:may A  . Ten: -: at# ifconfig|grep inet |head-1inet192.168. 1. 244Netmask255.255. 255. 0Broadcast192.168. 1. 255# # #配置# grep-e "proxy|php"/etc/httpd/conf/httpd.confDirectoryIndex index.php index.html addtype application/x-httpd-php. php AddType application/x-httpd-php-s Ource. Phpsproxyrequests Off proxypassmatch ^/(. *\.php) $ fcgi://192.168.1.245:9000/usr/local/apache/htdocs/tmp/$12, MySQL server# cat/etc/redhat-releaseCentOS Release6.7(Final)# mysql-vMySQL Ver14.14Distrib5.6. the, forLinux (x86_64)usingEditline Wrapper# ifconfig|grep inet |head-1inet Addr:192.168. 1. 242Bcast:192.168. 1. 255Mask:255.255. 255. 03, PHP server# more/etc/redhat-release # # Author:leshamiCentOS Release6.7(Final) # # # Blog:http://blog.csdn.net/leshami#./php-vPhp5.6. 9(CLI) (Built:jul -  .  -: $: -) Copyright (c)1997- -ThePHPGroupzend Engine v2. 6. 0, Copyright (c)1998- -Zend Technologies# ifconfig|grep inet |head-1inet Addr:192.168. 1. 245Bcast:192.168. 1. 255Mask:255.255. 255. 0# grep-ve "; |^#"/usr/local/php/etc/php-fpm.conf|grep ListenListen =192.168. 1. 245:9000# # # test page on the PHP server# vim/var/www/html/connmysql.php<?php $conn = mysql_connect (' 192.168.1.242 ',' Root ',' * * * '); if ($conn) echo"SUCC";ElseEcho"Failure"; Mysql_close ();? >4, verify the test page on the DB server# ifconfig|grep inet |head-1inet Addr:192.168. 1. 242Bcast:192.168. 1. 255Mask:255.255. 255. 0# Curl Http://192.168.1.244/connmysql.phpSucc

Linux 6 under Compile and install configuration lamp platform

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.