Split lamp platform Build-up

Source: Internet
Author: User
Tags php server keep alive server hosting

Lamp platform is a commonly used dynamic website platform, now in many cases, because of the reason for business requests to the Apache service, Mysql (MARIADB) service and PHP services respectively using their own Linux server hosting, I will summarize the split lamp platform build process. (I use the source code compiled installation)


First, the platform to build the preparation:

1, Centos 6.6 Final System three (basic installation, equipped with package group development Tools):

192.168.2.3 (Apache server)

192.168.2.5 (PHP server)

192.168.2.6 (MARIADB server)

2, software version selection:

apache:httpd-2.4.9 also includes apr-1.5.0 and apr-util-1.5.3

php:php-5.4.26

mariadb:mariadb-5.5.36

Also need to test the Platform software has database management software phpmyadmin-4.0.5-all-languages and Chinese blog WORDPRESS-4.2.2-ZH_CN


Second, build each server separately:


@ Install Apache server:

1. Install Apr:

#tar-XF apr-1.5.0.tar.bz2

#cd apr-1.5.0

#./configure--PREFIX=/USR/LOCAL/APR

#make && make Install

2, installation Apr-util:

#tar-XF apr-util-1.5.3.gz.bz2

#cd apr-util-1.5.3

#./configure--prefix=/usr/local/apr-util--WITH-APR=/USR/LOCAL/APR

#make && make Install

3, according to the new features of httpd-2.4, at compile time, we can also specify some specific options to achieve the corresponding performance. Let's summarize the new features and use some specific options when compiling the./configure.

①MPM supports loading at run time

② Support for Event MPM

③ asynchronous Read and write

④ use different log levels for each module and per directory

⑤ per-Request configuration;<if>,<elseif>

⑥ enhanced version of Expression Analyzer

⑦ millisecond-keep alive timeout

⑧ FQDN-based virtual host no longer requires NAMEVIRTUALHOST directive

⑨ enables users to use custom variables

The first option, which allows us to compile a multi-channel processing module that is no longer specific to a certain pattern, allows us to compile the schema currently supported by this system, and then run Apache as necessary to set it to the appropriate mode.

The second option allows our Apache processing module to run in a threaded manner.

#tar-XF httpd-2.4.9.tar.bz2

#cd httpd-2.4.9

#./configure--prefix=/usr/local/apache--sysconfdir=/etc/httpd24--enable-so--enable-ssl--enable-cgi-- Enable-rewrite--enable-deflate--with-zlib--with-pcre--with-apr=/usr/local/apr--with-apr-util=/usr/local/ apr-util/--enable-mpms-shared=all--with-mpm=event--enable-modules=most

#make && make Install

Check the environment under a given parameter, and install nothing. It is generally possible to pack xxx-devel.

As in the previous blog, the compilation installation must manually add the path variable, export the man manual, if you need two times to export the header file, export the library file, of course, the service script must be provided, and finally if necessary is to add services to the service list chkconfig.

This version of the configuration file has these:

#/etc/httpd24 Directory/etc/httpd24/httpd.conf # Master profile defined for compile-time installation

/etc/httpd24/extra/httpd-default.conf # Default profile (settings such as keepalive, Accessfilename, etc.)

/etc/httpd24/extra/httpd-userdir.conf # User Directory configuration file

/etc/httpd24/extra/httpd-mpm.conf # MPM configuration file

/etc/httpd24/extra/httpd-ssl.conf # SSL configuration file

/etc/httpd24/extra/httpd-vhosts.conf # Virtual Host configuration file

/etc/httpd24/extra/httpd-info.conf # server-status page configuration file                         

httpd2.4 no longer supports the use of order, allow, deny these mechanisms, but unified use of require for access control.


Oh, it's all done. Start the Apache service, but remember to close or release SELinux and iptables.


@ Install MARIADB server:

This server i directly download the binary package decompression configuration on the line. However, in order to ensure the security of the data and the convenience of other operations, it is necessary to set the database data storage directory alone, do not use the default.

The specific command will not write, just add a partition, format the required file system type, edit/etc/fstab, mount to the system a path, I here is/mydata/data.

Because it is the binary package decompression so installed, so in order to service the stability and system security, it is best to use a specific user to run.

#groupadd-R MySQL #创建一个系统用户组

#useradd-G mysql-r MySQL #创建以mysql用户组为基本用户组的系统用户mysql

#id MySQL #创建完了使用id命令查看结果

#chown-R Mysql.mysql/mydata/data #将数据存放目录的属主和属组修改成我们创建以运行mariadb的用户和其用户组

Then the decompression installation mariadb:

#tar-xf mariadb-5.5.36-linux-x86_64.tar.gz-c/usr/local/#-c specifies which directory to extract to

#cd/usr/local

#ln-sv mariadb-5.5.36-linux-x86_64 MySQL #创建软链接方便使用

#chown-R mysql.msyql./mysql #将程序目录的属主和属组修改成我们创建以运行mariadb的用户和其用户组

The next step is to provide the configuration file and initialize the database.

#mkdir/etc/mysql #创建数据库配置文件的目录, not directly under/etc to facilitate the distinction

#cp/usr/local/mysql/support-files/my-large.cnf/etc/mysql/my.cnf

#vim/etc/mysql/my.cnf

Twice times the number of CPUs after modifying the value of Thread_concurrency

Add DataDir =/mydata/data to indicate where the data file is stored

Initialize Database #/usr/local/mysql/scripts/mysql_install_db--user=mysql--datadir=/mydata/data


Then of course also provide scripts, join the service list, add path variable, export man manual, library file and header file, you can start the service normally.

Service script is #cp/usr/local/mysql/support-files/mysql.server/etc/rc.d/init.d/mysqld

#chmod +x/etc/rc.d/init.d/mysqld


@ Install PHP Server


It is also best to solve the dependency problem first by loading the bzip2-devel and Libmcrypt-devel development packages.

The same steps:

#tar-XF php-5.4.26.tar.bz2

#cd php-5.4.26

#./configure--prefix=/usr/local/php--with-mysql=mysqlnd--with-pdo-mysql=mysqlnd--with-mysqli=mysqlnd-- Enable-mbstring--with-freetype-dir--with-jpeg-dir--with-png-dir--with-zlib--with-libxml-dir=/usr--enable-xml-- Enable-sockets--enable-fpm--with-mcrypt--with-config-file-path=/etc--WITH-CONFIG-FILE-SCAN-DIR=/ETC/PHP.D-- WITH-BZ2--with-openssl

#make && make Install

Because it's a separate type, and PHP version is 5.4 version, so do not specify the MySQL location, unified use PHP's own development of MYSQLND this driver to connect to the remote MySQL server,--with-jpeg and PNG can make the request faster response, mbstring can use different types of character sets, Enabl E-FPM enable the FAST-CGI process Manager.

The same provision of service scripts, configuration files, because lamp is working in a php-fpm way, so the configuration file is 2 copies.

#cp/php-5.4.26/php.ini-production/etc/php.ini

The PHP-FPM configuration file is:

#cp/usr/local/php/etc/php-fpm.conf.default/usr/local/php/etc/php-fpm.conf

PHP-FPM Service Script

#cp/PHP-5.4.26/SAPI/FTP/INIT.D.PHP-FPM/ETC/RC.D/INIT.D/PHP-FPM

The PHP-FPM configuration file modifies the following sections:

PID =/usr/local/php/var/run/php-fpm.pid

Listen = 172.16.10.110:9000

Pm.max_children = #最大子进程数

Pm.start_servers = 5 #开机预启动子进程数

Pm.min_spare_servers = 2 #最小空闲子进程数

Pm.max_spare_servers = 6 #最大空闲子进程数

After joining the Service list, start the service,

Using #ss-tnl | grep 9000 to see if the service has started properly.


@ Connect httpd, PHP and mariadb three servers


First, we turn off or release the iptables and SELinux of the three servers first.


Then, modify the configuration of the HTTPD server to allow it to work with PHP:

Load the corresponding module so that the request dynamic content such as PHP page can reverse proxy

#vim httpd.conf

LoadModule Proxy_module modules/mod_proxy.so

LoadModule Proxy_fcgi_module modules/mod_proxy_fcgi.so

If you want to use a virtual host, you have to comment out the main configuration file

#DocumentRoot "/usr/local/apache/htdocs" #这样来关闭主服务器

Add Include/etc/httpd24/extra/httpd-vhost at the same time to open the virtual host

In order to support PHP, you have to include the following in the main configuration file:

Find AddType Add the following

AddType application/x-httpd-php. php

AddType Application/x-httpd-php-source. Phps

Also find directory

Add index.php to the default home page after adding the site.


Whether it is a virtual host or a master server configuration, to connect to PHP you have to close the forward proxy matching, enable the reverse proxy all the requested PHP page.

This is achieved within the configuration section:

Proxyrequests Off #关闭正向代理

Proxypassmatch ^/(. *\.php) $ fcgi://172.16.10.110:9000/web/pma/$1 #代理至php服务器


This almost completes the construction of the split lamp platform.

There are also some tips:

If each server is installed, you can test the server alone will not be able to use, such as httpd write a test page to visit; mariadb Connect to the server to try, yes, the remote host Connection database server to do the corresponding user add and set in the database Oh;

Separate lamp platform, it is best to put the site directory using a shared file system, so that the httpd server and PHP Server site Directory content is the same, there is no experiment ha.





Split lamp platform Build-up

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.