Lamp Separation Deployment

Source: Internet
Author: User


1. Host Planning


There are at least 3 virtual machines in the configuration, and the operating system is CentOS network segment in 172.16.27.0/16


The allocation is as follows:


1 httpd Server 172.16.27.20


1 PHP-FPM Server 172.16.27.30


1 db Server 172.16.27.40


2. Working mode


First, the client initiates the request, the request divides into 2 kinds, one kind is the static request it can directly by the Apache direct response return; the other is the dynamic request, such as contains in PHP or Perl this kind of script explanatory language, By the Apache server through the FASTCGI protocol call PHP Server execution and return to Apache returned by Apache to explain the results of execution, if the process involves the operation of the data, the PHP server will also call the MySQL server through the MySQL protocol.


3. Compile and install Apache (172.16.27.20)


Pre-deployment preparation

Yum Groupinstall "Development Tools"

Yum Install Apr-util-devel

Yum Install Pcre-devel openssl-devel libevent-devel

mkdir-pv/data/web/www{1,2}


Start extracting httpd and compiling

[Email protected] tmp]# TAR-VXF httpd-2.4.6.tar.bz2

[Email protected] tmp]# CD httpd-2.4.6/

[Email protected] httpd-2.4.6]#/configure--prefix=/usr/local/apache--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

[[email protected] httpd-2.4.6]# make-j 2 && make install

[[email protected] local]# ln-sv apache2.4.6/apache (create soft connection)


Create users and groups for Apache


[Email protected] local]# groupadd-g Apache

[Email protected] local]# useradd apache-u 800-g 800-m-s/sbin/nologin

Creating Mailbox File:file exists

[[email protected] local]# ID Apache

uid=800 (Apache) gid=800 (Apache) groups=800 (Apache)


Launch Apache Service


[Email protected] local]# cat/etc/profile.d/httpd.sh

Export Path=/usr/local/apache/bin: $PATH

[[email protected] local] apachectl start

Enter the IP address in the browser to access, show it works on behalf of our HTTPD server has been built. (Turn off firewall and SELinux)


4 Compiling and installing Php+xcache (172.16.27.30)


(1) Compile and install PHP


Resolving PHP dependencies


# yum Install libxml2-devel gd-devel freetype-devellibmcrypt-devel openssl-devel bzip2 bzip2-devel


Compiling and installing php5.5


# Tar XF php-5.5.30.tar.gz

./configure--prefix=/data/soft/php-5.5.30--with-mysql=/data/soft/mariadb--with-openssl--with-mysqli=/data/soft /mariadb/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-config-file-path=/etc /PHP.INI--WITH-CONFIG-FILE-SCAN-DIR=/ETC/PHP.D--with-bz2--ENABLE-FPM

# make

# make Install

# LN-SV php5.5.30 php5


Add php.ini and PHP-FPM files

(1) Provide a configuration file for PHP

Copy the Php.ini-production file from the php-5.5.30 unpacking package

# Cp/tools/php-5.5.30/php.ini-production/etc/php.ini

Providing configuration files for PHP-FPM

# CD php5.5/etc/

# CP Php-fpm.conf.defaultphp-fpm.conf


Configuring the PHP-FPM File


[Email protected] php5.5]# vim etc/php-fpm.conf

PID = Run/php-fpm.pid

listen= 172.16.27.30:9000

listen.allowed_clients= 172.16.27.20 #web服务器地址

Pm.max_children = 1024

Pm.start_servers = 16

Pm.min_spare_servers = 5

Pm.max_spare_servers = 20

Pm.process_idle_timeout = 15s

Pm.max_requests = 2048


Start the PHP-FPM service


(1) Setting the PATH environment variable

# cat/etc/profile.d/php-fpm.sh

Export path=/data/soft/php5.5/sbin/: $PATH

(2) Provide startup script for PHP-FPM


# CP/TOOLS/PHP-5.5.30/SAPI/FPM/INIT.D.PHP-FPM/ETC/INIT.D/PHP-FPM

# chmod +X/ETC/INIT.D/PHP-FPM

# chkconfig--add php-fpm

# Chkconfig PHP-FPM on

(3) Start php-fpm, view the number of PHP-FPM processes


# service PHP-FPM Start

# Ps-ef |grep-c php-fpm


Set up Apache virtual host to connect PHP

Configuring Apache Support fcgi


[Email protected] ~]# vim/etc/httpd24/httpd.conf

LoadModule Proxy_module modules/mod_proxy.so

LoadModule proxy_fcgi_modulemodules/mod_proxy_fcgi.so



(5) Editing a virtual host (172.16.27.20)


<virtualhost *:80>


ServerAdmin [email protected]


DocumentRoot "/DATA/VHOST/WWW1"


ServerName ww1.ssl.com


Errorlog "/data/vhost/www1/www1.errorlog"


Customlog "/data/vhost/www1/www1.customlog" combined


Proxyrequests off #关闭正向代理


Proxypassmatch ^/(. *.php) $ fcgi://172.16.27.30:9000/var/vhost/www1/$1


<directory "/DATA/VHOST/WWW1" >


Options None


AllowOverride None


Require all granted


</Directory>


</VirtualHost>




<virtualhost *:80>


ServerAdmin [email protected]


DocumentRoot "/DATA/VHOST/WWW2"


ServerName www2.ssl.com


Errorlog "/data/vhost/www2/www2.errorlog"


Customlog "/data/vhost/www2/www2.customlog" combined


Proxyrequests off #关闭正向代理


Proxypassmatch ^/(. *.php) $ fcgi://172.17.27.30/data/vhost/www2/$1


<directory "/DATA/VHOST/WWW2" >


Options None


AllowOverride None


Require all granted

</Directory>


</VirtualHost>



6 to improve the performance of PHP installation XCache

# TAR-XVF XCACHE-3.2.0.TAR.BZ2

# CD xcache-3.2.0

#./configure--enable-xcache--with-php-config=/data/soft/ph

# Make && Makeinstall

# Ls/data/soft/php-5.5.30/lib/php/extensions/no-debug-non

Consolidate PHP and XCache, copy xcache configuration files to php.d directory, enable PHP to read XCache configuration files


# MKDIR/ETC/PHP.D

# CP Xcache.ini/etc/php.d/

Edit the/etc/php.d/xcache.ini file to specify the location of the xcache.so


# sed-n ' 4p '/etc/php.d/xcache.ini

Extension =/data/soft/php-5.5.30/lib/php/extensions/no-debug-non-zts-20121212/xcache.so



Deploying MARIADB Services

Using MySQL binary installation mode


Create MySQL users and groups


# groupadd-g 306 MySQL

# useradd-u 306-g mysql-s/sbin/nologin-m MySQL


Decompression mariadb-5.5.46-linux-x86_64.tar.gz


# Tar XF mariadb-5.5.46-linux-x86_64.tar.gz-c/data/soft/

# LN-SV MARIADB-5.5.46-LINUX-X86_64/MARIADB

' Mariadb ', ' mariadb-5.5.46-linux-x86_64/'


Create MySQL Data directory and authorize


Mkdir/data/mydata-p

Chown-r Mysql.mysql/data/mydata


Initializing the database file

# Chown-r root.mysql/data/soft/mariadb/

# CD/DATA/SOFT/MARIADB

# Scripts/mysql_install_db--user=mysql--datadir=/data/mydata/--basedir=/data/soft/mariadb

Configuring the MARIADB Master profile my.cnf

Copy the my-large.cnf file under the/data/soft/mariadb/support-files directory to the/etc/directory, overwriting the original MySQL configuration file my.cnf (Note: You need to manually back up before overwriting):


# CP SUPPORT-FILES/MY-LARGE.CNF/ETC/MY.CNF


Modify the/etc/my.cnf file, specify the DataDir, Basedir path, and open port 3306


[Mysqld]

Port = 3306

Basedir =/data/soft/mariadb

DataDir =/data/mydata

innodb_file_per_table = 1 #让innodb表每个表一个表空间文件.


Copy MySQL startup script to/etc/init.d/mysqld


# Cp/data/soft/mariadb/support-files/mysql.server/etc/init.d/mysqld

# chmod 755/etc/init.d/mysqld


Modifying the PATH environment variable


[Email protected] mariadb]# cat/etc/profile.d/mysql.sh

Export MYSQL_HOME=/DATA/SOFT/MARIADB

Export path= $mysql _home/bin: $PATH

Start the MySQL service


[Email protected] mariadb]# chkconfig--add mysqld

[Email protected] mariadb]# chkconfig mysqld on

[[Email protected] mariadb]# service mysqld start

Starting MySQL ... success!



Enter the PHP host to edit the contents of the index.php file as follows:



<?php


$link =mysql_connect (' 172.16.27.40 ', ' WordPress ', ' WordPress ');


if ($link) {


echo "success. Wordpress! ";


}else{


echo "failed. Wordpress! ". Mysql_error ();


}


Mysql_close ($link);


Phpinfo ();


?>


Success appears. frank! success, if the failure to see the cause of failure to carry out the relevant operation!


Remember to turn off the firewall!


(10) Configuration phpMyAdmin


Create a folder in either the Frank directory or a random virtual host directory on the PHP host and the HTTP host


For example, in a directory on a PHP host


Unzip Phpmyadmin-4.4.10-all-languages.zip


Can. The two hosts operate the same.


The next step is to configure the phpMyAdmin on the PHP host.


CP config.sample.inc.php config.inc.php


Vim config.inc.php


Mainly found


$cfg [' Servers '] [$i] [' Host ']= ' 172.16.27.40 ' IP address of the database server


$cfg [' blowfish_secret '] = ' 77777 '; Here the characters are arbitrary, this is primarily to distinguish between cookies.


Then restart the services on the three hosts to test.




Lamp Separation Deployment

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.