Lamp Base Construction

Source: Internet
Author: User
Tags zts

Lamp is the most basic framework of Web server, understanding its main principles can help us to learn and operate at a higher level of the multiplier.

The composition of lamp:
A:apache (httpd)
M:mysql, MARIADB
p:php or Perl or Python (this time using PHP)

Database (MySQL, mariadb):

As a database, CentOS 6 and CentOS 7 operation is not much different, only, a 6 called MySQL, process called mysqld,7 called MARIADB, process called Mariadb.service. And I think, since it is a library, do not move back and forth places, just need to build a good, different types of PHP can be installed on different hosts, but can point to this library. This time I put the database on CentOS 7.2, the 7 IP is 172.16.0.215, direct yum install Mariadb-server.

Then modify the L Config file:/etc/my.cnf
Add the following fields after the "[MySQL]" column:
Innodb_file_per_table=on
Skip_name_resolve=on
Adddefaultcharset UTF-8

Note: This action is not supported on 6

After that, Systemctl start Mariadb.service.

(Of course, you can also systemctl enable Mariadb.service to set the boot up)

CentOS 6 is the service mysqld start (boot is chkconfig mysqld on)

I ran the mysql_secure_installation after the configuration, its role is to delete the anonymous login user rights and test library, and set the password, to tell the truth, as an experiment, run does not work is OK, Anyway, there is no important information (and the operation is full of English, password settings are very messy, it is better to complete those operations themselves).

The next step is to set the password (or the peace of mind of your own operation, and set it again for root).

Input command: MySQL, if there is no previous configuration, can go in directly;

Then type: SET PASSWORD for ' root ' @ ' localhost ' =password (' mageedu ')

Note: This root is the root of MySQL, not the root user

And then authorization, we're just going to build it, so use root and the library named MySQL

GRANT all on mysql.* to ' root ' @ ' 172.16.%.% ' identified by ' mageedu ';

% stands for any character of any length, this is equivalent to this network segment authorized

httpd

First we determine whether the installed version is the most suitable version of the current 2.4, or installed on this host, yum install, and then start the service and boot up, its basic configuration before the blog mentioned before, not to repeat. And if on 6, the httpd-2.4 version needs to be compiled and installed

Php

The way HTTP is combined with PHP:
CGI: Universal Gateway Interface: Common Gatway Interface

Modules (compile PHP into a httpd module)

FASTCGI:FPM:C/S architecture, via socket communication

Currently we are mainly used in two ways, that is, modular PHP and PHP-FPM, and modular PHP, if the httpd mpm for prefork,php using the libphp5.so module, if the other two, it is libphp5-zts.so.

Well, since the modular PHP must be on the same host as httpd, we are still doing yum install PHP on this host computer. and httpd configuration I did not modify, is the default prefork, so do not install libphp5-zts.so this module redundant.

At the same time, on another CentOS 7 host with IP 172.16.0.214, we install PHP-FPM, same as Yum install. The PHP on CentOS 7 is version 5.4, and if you want to use the same version on 6, you need to compile the installation.

It is important to note that the modular PHP and PHP-FPM are incompatible, and PHP-FPM is a management program that implements the CGI protocol, not a module, which conflicts.

We have two kinds of PHP installed on different host, avoid the conflict, and another important point is: Put PHP-FPM on another host, you can achieve cross-host build lamp way, and on the 172.16.0.215 is the same host built. We have just mentioned that fastcgi is a socket communication, when the user requests a PHP file, httpd as a reverse proxy through the CGI protocol, the parsing of the completed PHP file map to the page page, and the text file is in the httpd local rather than the database, HTTPD is the direct communication with the PHP-FPM, and the database communication object is also PHP-FPM, so the httpd and the database are placed on the same host, as long as php-fpm elsewhere, two and three hosts are no different. Of course, we also have to install Php-mysql on two hosts to contact PHP and the database separately.

In fact, the above is the basic environment of lamp, almost change some configuration can be set up, and here, I build virtual httpd server, and through the script implementation, directly:

650) this.width=650; "style=" Float:none; "title=" Image 005.png "alt=" wkiom1em6thasgqwaabksh8lwfe674.png-wh_50 "src=" Http://s3.51cto.com/wyfs02/M00/84/52/wKiom1eM6tHAsgQWAABKSh8LwfE674.png-wh_500x0-wm_3-wmp_4-s_2911862537.png "/ >

650) this.width=650; "style=" Float:none; "title=" Image 006.png "alt=" wkiol1em6tkz-su6aabpzkfbdda621.png-wh_50 "src=" Http://s1.51cto.com/wyfs02/M01/84/52/wKioL1eM6tKz-su6AABPzkFBDDA621.png-wh_500x0-wm_3-wmp_4-s_1552510133.png "/ >

650) this.width=650; "style=" Float:none; "title=" Image 007.png "alt=" wkiom1em6tpcivn5aabc2jt7wcg386.png-wh_50 "src=" Http://s1.51cto.com/wyfs02/M02/84/52/wKiom1eM6tPCivn5AABC2Jt7WCg386.png-wh_500x0-wm_3-wmp_4-s_1595565723.png "/ >

This script can be used in the case of PHP modularization, the earliest is learning httpd, want to quickly configure the virtual server to write small script, later found that as long as the addition of not a lot of things, you can complete a simple lamp frame, so there is such a thing, named Xhttpd, followed by create ' Name ' can create a httpd virtual machine with a PHP page connected to MySQL, and if add is followed by two numbers, then a httpd virtual machine named www# is created in bulk (for example, add 1 10, which is to create WWW1 to WWW10). Del and list are deleted and viewed, plus-A is all;

Since the amp is all on the same host, there's really nothing to say. To tell the truth, the script is very low, even to the perfectionist to bring a little discomfort, but it can be used, and very convenient, minutes to make a virtual server, a word of the server deleted will not be distressed (of course, there is a front of the environment to do the foundation, the program did not install anything bad to make).

Not to forget, we also have a php-fpm cross-host build, I made some changes on the basis of the previous script, but still can't overnight, because after all, the script on the httpd host, and PHP-FPM on another host (IP tail number is 214 of the host).

650) this.width=650; "style=" Float:none; "title=" Image 005.png "alt=" wkiol1em8pjcgwzjaabx7hsay1k577.png-wh_50 "src=" Http://s4.51cto.com/wyfs02/M00/84/52/wKioL1eM8PjCgwZjAABX7hSaY1k577.png-wh_500x0-wm_3-wmp_4-s_1354156958.png "/ >

650) this.width=650; "style=" Float:none; "title=" Image 006.png "alt=" wkiom1em8pmxp1umaabgtacqyeq600.png-wh_50 "src=" Http://s4.51cto.com/wyfs02/M01/84/52/wKiom1eM8PmxP1UMAABGtACqYEQ600.png-wh_500x0-wm_3-wmp_4-s_790277735.png "/ >

650) this.width=650; "style=" Float:none; "title=" Image 007.png "alt=" wkiol1em8pngf5ykaaba64nsm7k460.png-wh_50 "src=" Http://s1.51cto.com/wyfs02/M00/84/52/wKioL1eM8PngF5YkAABa64nsM7k460.png-wh_500x0-wm_3-wmp_4-s_3403143090.png "/ >

Visible from the diagram, only the function part has made some changes, the path has changed, but the name is similar, the main path is the same, as for the usage is just a hair.

The problem here is that I don't provide parsing of PHP files on my httpd host, So I put the generated index.php function commented out, instead of generating a simple text page, and then when the PHP-FPM can be on this host, the parsing of the path of PHP and the main page to write the same, you can change back.

And on PHP-FPM host, because it is a process, so will generate configuration file/etc/php-fpm.conf,/etc/php-fpm.d/*.conf;

/etc/php-fpm.conf There is nothing to modify, and/etc/php-fpm.d/only a default www.conf, then change it:

Listen = 127.0.0.1:9000
Listen.allowed_clients = 127.0.0.1
user = Apache
Group = Apache

This is the default value; Change listen.allowed_clients to the IP of the httpd host 172.16.0.215 (can also change the listen cost machine 172.16.0.214, the insurance point is not wrong); user and group relate to session permissions;

There are also PM mode static and dynamic, the default is dynamic, set the value is OK, do not change;

Finally, the PHP process for PM mode stores the path of the session:
Php_value[session.save_handler] = files
Php_value[session.save_path] =/var/lib/php/session

Note, however, that the session path itself does not exist.

So we save the configuration and create the Session directory, and then make sure that the user running the PHP-FPM process has read and write access to the directory;
# mkdir/var/lib/php/session
# chown Apache.apache/var/lib/php/session

Then, notice that the script on the httpd host fcgi path/data/fpm-vhosts/, create a link to the MySQL page index.php, the script can be copied and pasted, but do not forget to remove the backslash.

In this way, combined with my fhttpd script, you can also build a cross-host lamp framework, as long as the two frameworks can be resolved to the PHP file of the path to the program file, you can run various programs in the framework.

The following are two cases of the use of AB's pressure measurement comparison, the same as the 172.16.0.215 host, concurrent 100, Request 1000 (visual This is the limit, very slow, did not dare to add)

650) this.width=650; "style=" Float:none; "title=" Image 000.png "alt=" wkiol1em-qchflekaacak0io2oq132.png-wh_50 "src=" Http://s5.51cto.com/wyfs02/M00/84/52/wKioL1eM-QChFLEkAACAk0io2OQ132.png-wh_500x0-wm_3-wmp_4-s_3592205475.png "/ >

650) this.width=650; "style=" Float:none; "title=" Image 001.png "alt=" wkiom1em-qhblaxzaacoxxcxwb8251.png-wh_50 "src=" Http://s5.51cto.com/wyfs02/M01/84/52/wKiom1eM-QHBLaXZAACoxxcXWb8251.png-wh_500x0-wm_3-wmp_4-s_1497953872.png "/ >

650) this.width=650; "style=" Float:none; "title=" Image 002.png "alt=" wkiol1em-qgtsfflaacew9xifck942.png-wh_50 "src=" Http://s5.51cto.com/wyfs02/M01/84/52/wKioL1eM-QGTSfFLAACeW9Xifck942.png-wh_500x0-wm_3-wmp_4-s_3419252711.png "/ >

650) this.width=650; "style=" Float:none; "title=" Image 003.png "alt=" wkiol1em-qlxworbaab5c6zwelq464.png-wh_50 "src=" Http://s1.51cto.com/wyfs02/M02/84/52/wKioL1eM-QLxworBAAB5c6zwELQ464.png-wh_500x0-wm_3-wmp_4-s_2937158246.png "/ >

The first two diagrams of PHP modular situation, about 10 per second, very embarrassing, the latter two is the php-fpm situation, a 21, once 37, but after all stable in 35, 36, no Save the diagram, but even 21 is the former twice times, stand up.

Then I deployed the xcache in both frameworks, but it turned out to be a piece of hair! Apparently failed to deploy XCache for PHP modularity

650) this.width=650; "title=" Image 004.png "alt=" wkiom1em-kdq3qshaabaym4ocem400.png-wh_50 "src=" http://s5.51cto.com/ Wyfs02/m02/84/52/wkiom1em-kdq3qshaabaym4ocem400.png-wh_500x0-wm_3-wmp_4-s_3679547150.png "/>

PHP-FPM is a bit of a function no, the picture is not affixed.

Finally, the compilation and installation and configuration of httpd-2.4 and php-5.4

Install httpd-2.4:

CentOS 6 Dedicated:
(1) Apr
#./configure--PREFIX=/USR/LOCAL/APR
# Make && make install
(2) Apr-util
#./configure--prefix=/usr/local/apr-util--WITH-APR=/USR/LOCAL/APR
# Make && make install

Note: When you compile the main body, Apr and Apr-util are going to write the path of the actual compiled installation

CentOS 7 Dedicated:
# yum Install Apr-devel Apr-util-devel

# yum Install pcre-devel openssl-devel libevent-devel

#./configure--prefix=/usr/local/apache24--sysconfdir=/etc/httpd24--enable-so--enable-ssl--enable-cgi-- Enable-rewrite--enable-modules=most--enable-mpms-shared=all--with-mpm=prefork--with-pcre--with-zlib--with-apr= /usr--with-apr-util=/usr
# make-j #
# make Install

installation php-5.4:
   # yum Install libxml2-devel gd-devel Freetype-devel libmcrypt-devel
  
   #./configure--PREFIX=/USR/LOCAL/PHP54-- With-mysql=/usr/local/mysql--with-openssl--with-mysqli=/usr/local/mysql/bin/mysql_config--enable-mbstring-- Enable-xml--enable-sockets--with-freetype-dir--with-gd--with-libxml-dir=/usr--with-zlib--with-jpeg-dir-- With-png-dir--with-mcrypt--with-apxs2=/usr/local/apache24/bin/apxs--with-config-file-path=/etc/php54.ini-- WITH-CONFIG-FILE-SCAN-DIR=/ETC/PHP54.D
   # make-j #
   # make install
    
    cp php.ini-production /etc/php54.ini

Note: If HTTPD uses the line program MPM, the PHP should be compiled with extra--enable-maintainer-zts;

Configuration httpd:
LoadModule Php5_module modules/libphp5.so
AddType application/x-httpd-php. php
DirectoryIndex index.php index.html

The above is my configuration, if there is a mistake, please correct me.

Lamp Base Construction

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.