Apache, PHP, MySQL each work on the independent host of the Lamp Platform implementation

Source: Internet
Author: User
Tags bz2 chmod configuration php fpm install php php server

Lab Environment:

vm1:192.168.1.132, for Apache servers

vm2:192.168.1.134, for PHP server

vm3:192.168.1.137, User mariadb server

Software version: httpd-2.4.9,php-5.4.26,mariadb-5.5.39

First, compile and install httpd-2.4.9

1. Solve the dependency relationship

# yum-y Install Pcre-devel

# yum-y Install Mod_ssl

# yum Groupinstall-y "Development tools"

# yum Groupinstall-y "Server Platform Development"

Compiling and installing apr-1.5.0.tar.bz2

# Tar XF apr-1.5.0.tar.bz2

# CD apr-1.5.0

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

# Make && make install

Compiling and installing apr-until-1.5.3.tar.bz2

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

# CD apr-util-1.5.3

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

# Make && make install

2. Compile and install httpd-2.4.9

# 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--with-zlib--with-pcre--with-apr=/usr/local/apr--with-apr-util=/usr/local/apr-util-- Enable-modules=most--enable-mpms-shared=all--with-mpm=event

# Make && make install

3. Modify the httpd configuration file

Enable the FCGI module

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/46/31/wKioL1PuGtvhXD7rAAEYzLEf40E632.jpg "title=" 2014-08-15 22_30_16-root@httpd__mnt-xshell 4.jpg "alt=" Wkiol1pugtvhxd7raaeyzlef40e632.jpg "/>

Add the following statement to the configuration file to allow Apache to support PHP-formatted pages and support PHP-formatted home page

AddType application/x-httpd-php. php

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

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/46/2F/wKiom1PuGhjwqUa7AABulSjX1MI739.jpg "title=" 2014-08-15 22_31_55-root@httpd__mnt-xshell 4.jpg "alt=" Wkiom1pughjwqua7aabulsjx1mi739.jpg "/>

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/46/2F/wKiom1PuHQ6jThCmAAJdxjUiydA874.jpg "title=" 2014-08-15 22_44_30-root@httpd__mnt-xshell 4.jpg "alt=" Wkiom1puhq6jthcmaajdxjuiyda874.jpg "/>

Turn off the forward proxy, enable the reverse proxy, add the statement, fcgi: The following IP address is the PHP application server IP address,/var/phpscript is the PHP server for the PHP page file directory location, the user in the front-end of the Apache Server request PHP page, The httpd process will reverse-proxy the user request to a page file in the same directory as the PHP server and return it to the HTML page format of the front-end Apache server after processing by the PHP interpreter.

Proxyrequests OFF

Proxypassmatch ^/(. *\.php) $ fcgi://192.168.1.134:9000/var/phpscript/$1

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/46/2F/wKiom1PuGruTcQJIAABx3VkjLzA665.jpg "title=" 2014-08-15 22_34_30-root@httpd__mnt-xshell 4.jpg "alt=" Wkiom1pugrutcqjiaabx3vkjlza665.jpg "/>

Set the PID file path, which is set up to use the Apache service script.

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/46/2F/wKiom1PuHZ3RNyCDAAAkfZHjDds028.jpg "title=" 2014-08-15 22_46_49-root@httpd__mnt-xshell 4.jpg "alt=" Wkiom1puhz3rnycdaaakfzhjdds028.jpg "/>

4, provide SYSV service script, create a file named Httpd24 under the/ETC/RC.D/INIT.D directory, edit and add the following content

#!/bin/bash

#

# httpd Startup script for the Apache HTTP Server

#

# Chkconfig:-85 15

# Description:apache is a world Wide Web server. It's used to serve \

# HTML files and CGI.

# PROCESSNAME:HTTPD

# config:/etc/httpd/conf/httpd.conf

# config:/etc/sysconfig/httpd

# Pidfile:/var/run/httpd.pid


# Source function library.

. /etc/rc.d/init.d/functions


if [-F/ETC/SYSCONFIG/HTTPD]; Then

. /etc/sysconfig/httpd

Fi


# Start httpd in the C locale by default.

httpd_lang=${httpd_lang-"C"}


# This would prevent Initlog from swallowing up a pass-phrase prompt if

# Mod_ssl needs a pass-phrase from the user.

Initlog_args= ""


# Set Httpd=/usr/sbin/httpd.worker in/etc/sysconfig/httpd to use a server

# with the thread-based "worker" MPM; Be warned this some modules may not

# work correctly with a thread-based MPM; Notably PHP would refuse to start.


# Path to the Apachectl script, server binary, and short-form for messages.

Apachectl=/usr/local/apache/bin/apachectl

HTTPD=${HTTPD-/USR/LOCAL/APACHE/BIN/HTTPD}

Prog=httpd

Pidfile=${pidfile-/var/run/httpd.pid}

LOCKFILE=${LOCKFILE-/VAR/LOCK/SUBSYS/HTTPD}

Retval=0


Start () {

Echo-n $ "Starting $prog:"

lang= $HTTPD _lang Daemon--pidfile=${pidfile} $httpd $OPTIONS

Retval=$?

Echo

[$RETVAL = 0] && Touch ${lockfile}

Return $RETVAL

}


Stop () {

Echo-n $ "Stopping $prog:"

Killproc-p ${pidfile}-D $httpd

Retval=$?

Echo

[$RETVAL = 0] && rm-f ${lockfile} ${pidfile}

}

Reload () {

Echo-n $ "Reloading $prog:"

if! lang= $HTTPD _lang $httpd $OPTIONS-T >&/dev/null; Then

Retval=$?

echo $ "not reloading due to configuration syntax error"

Failure $ "not reloading $HTTPD due to configuration syntax error"

Else

Killproc-p ${pidfile} $httpd-hup

Retval=$?

Fi

Echo

}


# See how we were called.

Case "$" in

Start

Start

;;

Stop

Stop

;;

Status

Status-p ${pidfile} $httpd

Retval=$?

;;

Restart

Stop

Start

;;

Condrestart)

If [-f ${pidfile}]; Then

Stop

Start

Fi

;;

Reload

Reload

;;

Graceful|help|configtest|fullstatus)

$apachectl [email protected]

Retval=$?

;;

*)

echo $ "Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}"

Exit 1

Esac


Exit $RETVAL

Modify the Execute permissions for this script:

# chmod +X/ETC/RC.D/INIT.D/HTTPD24

To add a list of services:

# chkconfig--add httpd24

# Start Service:

# service HTTPD24 Start

Apache server ready to complete.


Second, compile and install php-5.4.26

1, to resolve the dependency relationship:

# yum Groupinstall-y "Desktop Platform Development"

# yum-y Install Bzip2-devel Libmcrypt-devel

2. Compile and install php-5.4.26

# Tar XF php-5.4.26.tar.bz2

# CD php-5.4.26

#./configure--prefix=/usr/local/php5--with-mysql=mysqlnd--with-openssl--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

The database server is another separate host, so when you compile PHP, specify the installation location for MySQL, you need to set it to Mysqlnd, and explicitly indicate the use of the FPM module

# Make && make install

To provide a configuration file for PHP:

# CP Php.ini-production/etc/php.ini

3, Configuration php-fpm

Provide a SYSV service script for PHP-FPM and add it to the list of services

# CP SAPI/FPM/INIT.D.PHP-FPM/ETC/RC.D/INIT.D/PHP-FPM

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

# chkconfig--add php-fpm

# Chkconfig PHP-FPM on

To provide a configuration file for php-fpm:

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

To modify the PHP-FPM configuration file:

# vim/usr/local/php5/etc/php-fpm.conf

Enable the PID file, the option is enabled under the Global configuration section, and modify the PHP-FPM listening address, the original listener address is 127.0.0.1, you need to change the address that can communicate with the external, set:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/46/30/wKiom1PuImLh_oBZAADpt3J1d3E799.jpg "title=" 2014-08-15 23_07_11-root@php__usr_local_php5_etc-xshell 4.jpg "alt=" wkiom1puimlh_obzaadpt3j1d3e799.jpg "/>650) this.width=650, "src=" http://s3.51cto.com/wyfs02/M02/46/32/wKioL1PuJAfSXFOFAAGTa4plD8A207.jpg "title=" 2014-08-15 23_09_06-root@php__usr_local_php5_etc-xshell 4.jpg "alt=" Wkiol1pujafsxfofaagta4pld8a207.jpg "/>

Start the service:

# service PHP-FPM Start

To view the ports that the service listens on:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/46/32/wKioL1PuJIvQYeiJAACPMukSCa8343.jpg "title=" 2014-08-15 23_11_44-root@php__usr_local_php5_etc-xshell 4.jpg "alt=" Wkiol1pujivqyeijaacpmuksca8343.jpg "/>

You can see that the PHP-FPM works on port 9000, and the listening address is 192.168.1.134.

Create a PHP page store directory to store php page files.

# Mkdir/var/phpscript

# vim/var/phpscript/index.php; Edit the PHP page file, as follows:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/46/32/wKioL1PuLjTyBe9mAADRws0kAc0042.jpg "title=" 2014-08-15 23_52_55-root@php__var_phpscript-xshell 4.jpg "alt=" Wkiol1puljtybe9maadrws0kac0042.jpg "/>

The PHP application server is ready to complete.


Third, installation mariadb-5.5.39

1. Prepare the file system for data storage, create a logical volume for the database to hold the data.

Create a disk partition with the partition format LVM:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/46/30/wKiom1PuJaHjdgAjAAESRSEN8xk174.jpg "title=" 2014-08-15 23_21_03-root@database__shared_nfs-xshell 4.jpg "alt=" Wkiom1pujahjdgajaaesrsen8xk174.jpg "/>

# KPARTX-AF/DEV/SDA; Notifies the kernel to reread the disk partition table

# partx-a/DEV/SDA; Notifies the kernel to reread the disk partition table

# cat/proc/partitions; view kernel recognition partition

# Pvcreate/dev/sda3

# vgcreate Myvg/dev/sda3

# lvcreate-l 10g-n mylv MYVG

# LVS; view LV creation results

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/46/30/wKiom1PuJnKiazTDAAEDgb6-EmI820.jpg "title=" 2014-08-15 23_24_30-root@database__shared_nfs-xshell 4.jpg "alt=" Wkiom1pujnkiaztdaaedgb6-emi820.jpg "/>

# mke2fs-t Ext4/dev/myvg/mylv

# mkdir/mydata/data; Create a directory to store database data

# vim/etc/fstab; Edit the Fstab file to mount the/DEV/MYVG/MYLV to/mydata/data

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/46/32/wKioL1PuKFqCsdr0AAHB1sb5OEU907.jpg "title=" 2014-08-15 23_27_56-root@database__shared_nfs-xshell 4.jpg "alt=" Wkiol1pukfqcsdr0aahb1sb5oeu907.jpg "/>

# mount-a

2. New to run the process in a secure manner

# groupadd-r MySQL

# useradd-g mysql-s/sbin/nologin-r MySQL

# Chown-r Mysql:mysql/mydata/data

3, installation of the initialization MariaDB-5.5.39

# Tar XF mariadb-5.5.39-linux-x86_64.tar.gz

# cd/usr/local

# LN-SV mariadb-5.5.39-linux-x86_64 MySQL

# CD MySQL

# Chown-r Mysql:mysql.

# scripts/mysql_install_db--user=mysql--datadir=/mydata/data

# Chown-r Root.

4. Provide the main configuration file for mariadb

# Cd/usr/local/mysql

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

# vim/etc/my.cnf; Modify the database master configuration file to add the path to the data storage:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/46/32/wKioL1PuKdPg2bvOAAGKlYYDr84534.jpg "title=" 2014-08-15 23_34_18-root@database_~-Xshell 4.jpg "alt=" Wkiol1pukdpg2bvoaagklyydr84534.jpg "/>

5. Provide service script for MARIADB

# Cd/usr/local/mysql

# CP Support-files/mysql.server/etc/rc.d/init.d/mysqld

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

# chkconfig--add mysqld

# Chkconfig Mysqld on

6, MARIADB installation to complete the subsequent configuration work:

Output MARIADB man manual, add content

# Vim/etc/man.config

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/46/32/wKioL1PuKo2gNTfZAACU-UTQLwQ854.jpg "title=" 2014-08-15 23_37_26-root@database_~-Xshell 4.jpg "alt=" Wkiol1puko2gntfzaacu-utqlwq854.jpg "/>

Output MARIADB header file

# Ln-sv/usr/local/mysql/include/usr/include/mysql

Output the MARIADB library file:

# echo '/usr/local/mysql/lib ' >/etc/ld.so.conf.d/mysql.conf

# ldconfig; system Reload library file

Modify the PATH environment variable so that the system can use MARIADB related commands directly

# vim/etc/profile.d/mysql.sh

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/46/32/wKioL1PuK9aQ9_ykAACHXMGDtM8273.jpg "title=" 2014-08-15 23_42_55-root@database_~-Xshell 4.jpg "alt=" Wkiol1puk9aq9_ykaachxmgdtm8273.jpg "/>

Connect to MySQL and create a remote connection user to test the database connection:

# MySQL

# CREATE USER [email protected] ' 192.168.1.% ' identified by ' tpass ';

Now that three hosts are ready to add static page content to the Apache server, add php page files to the PHP server for testing:

Create a page file named test.html under the site root of the Apache server, and edit the contents as:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/46/30/wKiom1PuK-SQ_um0AABaWvHmaSg589.jpg "title=" 2014-08-15 23_46_29-root@httpd__usr_local_apache_htdocs-xshell 4.jpg "alt=" wkiom1puk-sq_um0aabawvhmasg589.jpg "/ >

The test results in the browser are as follows:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/46/32/wKioL1PuLUPQlMQCAAE-Lf9wEBY641.jpg "title=" 2014-08-15 23_47_43-http___192.168.1.132_test.html.jpg "alt=" Wkiol1pulupqlmqcaae-lf9weby641.jpg "/>

Test the PHP page access and database connection conditions:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/46/32/wKioL1PuL4fhQhhpAAFSBsO6FsY975.jpg "title=" 2014-08-15 23_58_34-http___192.168.1.132_index.php.jpg "alt=" Wkiol1pul4fhqhhpaafsbso6fsy975.jpg "/>


Related Article

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.