Background introduction
Lamp is the LNMP structure before the popular long-lasting structure, this series on from scratch a little bit about the installation of lamp compilation. First, this series of topology diagram 650) this.width=650; "Src=" http://s2.51cto.com/wyfs02/M00/89/67/wKioL1gSH_fySE_ Saaci6-jb-za681.png "title=" 1.png "style=" Float:none; alt= "Wkiol1gsh_fyse_saaci6-jb-za681.png"/>
At this point, the server responds to client access can be divided into several response methods: 650) this.width=650; "Src=" http://s2.51cto.com/wyfs02/M01/89/6A/wKiom1gSH_ Errw6taabhddfe5ie860.png "title=" 2.png "style=" Float:none; alt= "Wkiom1gsh_errw6taabhddfe5ie860.png"/>
1. Client initiated request to server side
2. Server-side view request type, when a static page request, return the results directly
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/89/67/wKioL1gSH_fQQeQJAABXhObw7NQ052.png "title=" 3.png " Style= "Float:none;" alt= "Wkiol1gsh_fqqeqjaabxhobw7nq052.png"/>
1. Client initiated request to server side
2. Server-side view request type, when for dynamic page request, through the configuration file set in the reverse proxy, via FCGI protocol To the back-end PHP server
The PHP-FPM service is enabled on the 3.PHP server, the listener wants to use the request on a socket, and feeds the results back to the HTTPD server
The 4.HTTPD server, through its Rewirte technology, feeds the results back to the client in the form of pseudo-static pages
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/89/67/wKioL1gSH_fhHZICAABmLh6Sk3A391.png "title=" 4.png " Style= "Float:none;" alt= "Wkiol1gsh_fhhzicaabmlh6sk3a391.png"/>
1. Client initiated request to server side
2. Server-side view request type, when for dynamic page request, hand over to backend PHP server
3. If the client needs access to the database in the request, the PHP server will transfer the request to the MySQL server, which should be noted here: The PHP server itself does not request MySQL , but the request is forwarded for the user, so PHP needs to enable--WITH-MYSQL=MYSQLND--with-pdo-mysql=mysqlnd when compiling the installation
--with-mysqli=mysqlnd These 3 options, at this time the MYSQLND is similar to a driver, can make PHP connect to MYSAQL server, if PHP and MySQL server for Same Host , take the--with-mysql option as an example, and you need to indicate the MySQL installation path--with-mysql=/path/to/mysql
4.Mysql Server feeds the results of data processing to the PHP server
The 5.PHP server feeds the results back to the HTTPD server
The 6.HTTPD server, through its Rewirte technology, feeds the results back to the client in the form of pseudo-static pages
Apche2.4 Introduction
The Apache2.2 version of the CENTOS6 series is used by default, and later releases of the Apache2.4 version have been further enhanced functionally than before, mainly as follows:
1.MPM supports load at run time
2. Support Event
3. Asynchronous read and write
4. Specify the log level on each module and per directory
5. Configure:<if> <Elseif> per request
6. Enhanced version of the expression parser
7. KeepAlive timeout at the millisecond level
8. Host name-supported virtual host does not require namevirtualhost instructions
9. Support for using custom variables
10. Add some modules: Mod_proxy_fcgi,mod_ratelimit,mod_request,mod_remoteip
11. Modifications to IP-based access are not made using order,allow,deny mechanisms; they are used uniformly require, such as require granted and require denied
Experiment Description
Operating system: CentOS6.8
SOURCE Bundle: HTTPD-2.4.23.TAR.BZ2,APR-1.5.2.TAR.BZ2,APR-UTIL-1.5.4.TAR.BZ2
Preparation: Install Pcre-devel package, Apache2.4 need to use when compiling
Experimental purpose
1. Compile and install Apache2.4
2. Test the MPM module for dynamic switching
3. Test the virtual host implementation
4. Adding the compiled service to the service control
Experimental steps
First, compile and install
1. Install prerequisites and unzip the source package
Yum-y Install pcre-devel# Pcre-devel Package
For i in apr-1.5.2.tar.bz2 apr-util-1.5.4.tar.bz2 httpd-2.4.23.tar.bz2;do tar-xf $i-C/usr/local/src/;d One
#将apr -1.5.2.tar.bz2 apr-util-1.5.4.tar.bz2 httpd-2.4.23.tar.bz2 Compressed package to the/USR/LOCAL/SRC directory
2. Installing apr-1.5.2
cd/usr/local/src/apr-1.5.2# into the apr-1.5.2 directory
./configure--prefix=/usr/local/apr-1.5.2# checking the compilation environment
Make && make install# compile and install
3. Installing apr-util-1.5.4
cd/usr/local/src/apr-util-1.5.4# into the apr-1.5.2 directory
./configure--prefix=/usr/local/apr-util-1.5.4--with-apr=/usr/local/apr-1.5.2# Check the compilation environment
Make && make install# compile and install
4. Installing Apache2.4
cd/usr/local/src/httpd-2.4.23# into the httpd-2.4.23 directory
./configure--prefix=/usr/local/apache--sysconfdir=/etc/httpd--enable-so--enable--ssl--enable-cgi-- Enable-rewrite--with-zlib--with-pcre--with-apr=/usr/local/apr-1.5.2--with-apr-util=/usr/local/apr-util-1.5.4-- Enable-modeles=most--enable-mpms-shared=all--with-mpm=event# checking the compilation environment
Make && make install# compile and install
5. Path output
echo "Export Path=/usr/local/apache/bin: $PATH" >/etc/profile.d/apache.sh
source/etc/profile.d/apache.sh
6. header file output
ln-sv/usr/local/apache/include//usr/include/apache
7. library file output
apche2.4 after compiling the installation in the/usr/local/apache/directory without the Lib directory, this step skipped, there is the use of echo "/usr/local/apache/lib >/etc/ld.so.conf.d/ apche.conf "For library file output, then use Ldconfig-v to view
8.MAN Document output
Vim/etc/man.config
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/89/6A/wKiom1gSH_jzOPlRAAAm5KIWDWo933.png "title=" 5.png " Style= "Float:none;" alt= "Wkiom1gsh_jzoplraaam5kiwdwo933.png"/>
9. Start and check the Apche
/usr/local/apache/bin/apachectl start# Start-up service
netstat-ntl# See if Port 80 is listening properly
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/89/6A/wKiom1gSH_jBp4bkAAAOtZ98M58714.png "title=" 6.png " Style= "Float:none;" alt= "Wkiom1gsh_jbp4bkaaaotz98m58714.png"/>
Second, dynamic switch MPM module
Apache2.4 MPM is implemented in modular mode, supports DSO dynamic loading and unloading, and the event model is set at compile time, from the main configuration file/etc/httpd/ Httpd.conf can see the currently enabled MPM module, the switch MPM model is to enable the corresponding model module, change before the gap first stop service 650) this.width=650; "Src=" http://s2.51cto.com/wyfs02/M00 /89/67/wkiol1gsh_ixzctbaaac2zarilg324.png "title=" 7.png "style=" Float:none; "alt=" Wkiol1gsh_ Ixzctbaaac2zarilg324.png "/>
Note:/etc/httpd/extra/httpd-mpm.conf configuration file is modified MPM model parameters, if only modify this file will be found to not take effect, the reason is that the configuration file under the main configuration file is logged off by default, the activation will not take effect
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/89/6A/wKiom1gSH_igjWnkAAARNAN699I320.png "title=" 8.png " Style= "Float:none;" alt= "Wkiom1gsh_igjwnkaaarnan699i320.png"/>
Third, test the virtual host
1.apche2.4 no longer has the virtual host Switch option, the main profile is unregistered Central host 650) this.width=650; "Src=" http://s2.51cto.com/wyfs02/M02/89/67/wKioL1gSH_ Ihq42saaa7yvshnp0906.png "title=" 9.png "style=" Float:none; alt= "Wkiol1gsh_ihq42saaa7yvshnp0906.png"/>
2. Like the MPM module, you need to enable the virtual host profile in the master configuration file. If the virtual host profile resides in the httpd.conf master profile, you do not need to enable the virtual host configuration file. It is recommended that you separate the configuration file and the master profile for the virtual host. After testing, if the central host and the virtual host are both stored in the Httpd.conf Master profile and enabled at the same time, the virtual host takes effect . 650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/89/6A/wKiom1gSH_nypzmOAAAMzi0AMfU142.png "title=" 10.png "Style=" Float:none; "alt=" Wkiom1gsh_nypzmoaaamzi0amfu142.png "/>
3.vim/etc/httpd/extra/httpd-vhosts.conf Edit the virtual host Profile 650) this.width=650; "Src=" http://s2.51cto.com/wyfs02/M01/89/67 /wkiol1gsh_nz1jd_aaaziz1rilo091.png "title=" 11.png "style=" Float:none; "alt=" wkiol1gsh_nz1jd_aaaziz1rilo091.png "/ >
4. Create a master page for www.vhost.com
Mkdir-p/var/www/vhost
echo "www.vhost.com" >/var/www/vhost/index.html650) this.width=650; "Src=" http://s1.51cto.com/wyfs02/M02/89/6A/ Wkiom1gsh_ms8rnyaaadbhwx31w686.png "title=" 12.png "style=" Float:none; "alt=" wkiom1gsh_ms8rnyaaadbhwx31w686.png "/ >
At this point, you will find that access is denied, because Apche2.4 start each site needs to configure directory permissions, add to the normal access to 650) this.width=650; "Src=" http://s1.51cto.com/wyfs02/M02/89/67 /wkiol1gsh_nslr86aabnahoa_we114.png "title=" 13.png "style=" Float:none; "alt=" wkiol1gsh_nslr86aabnahoa_we114.png "/ >
Apche2.4 no longer uses the previous Oeder allow deny mechanism, the visit is based on IP access control by the Require:
Allow all hosts access: Require all granted
Deny all host access: Require all denied
Control access to a host, either as a single IP address or as a network segment:
Require IP ipaddr
Require not IP ipaddr
Use host name control, either an FQDN or an entire domain:
Require Host $HOSTNAME
Require not host $HOSTNAME
Iv. Adding a startup script
The service script can refer to CentOS6.8 's own httpd2.2 script, copy it to/ETC/RC.D/INIT.D directory, ensure execution permission, and make the following changes, mainly the path modification 650) this.width=650; src= http:/ /s1.51cto.com/wyfs02/m00/89/67/wkiol1gsh_mhuuwhaabfhykkycm115.png "title=" 14.png "style=" Float:none; "alt=" Wkiol1gsh_mhuuwhaabfhykkycm115.png "/>
650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/> Then add a line to the main configuration file Pidfile to 650) this.width=650; "Src=" http://s1.51cto.com/wyfs02/M00/89/6A/wKiom1gSH_ Ng8qaoaabfthq_ahe735.png "title=" 15.png "style=" Float:none; alt= "Wkiom1gsh_ng8qaoaabfthq_ahe735.png"/>
650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/> then use chkconfig--add httpd, Chkconfig httpd on, you can use the service control, and the operation is complete.
The experiment found a phenomenon that does not understand: according to understanding, HTTPD service should read the main configuration file httpd, and then read the script file, but the main configuration file specified Lockfile file location, through the Httpd-t check the syntax will be error, do not add after startup will follow the settings in the script to use /VAR/LOCK/SUBSYS/HTTPD; If the Pidfile file is not added to the master profile, the HTTPD service can be started normally with service, but the script file will not be read, which will not generate/var/run/ Httpd.pid file, unable to use service httpd stop after startup, prompt for no PID file
This article from "Rabbit-like rabbit sen Broken" blog, please be sure to keep this source http://arkling.blog.51cto.com/2844506/1866548
Lamp Compile and install (i)--install Apache2.4