構建企業級LAMMP環境

1、LAMMP簡介php

2、LAMMP項目環境簡介
html

3、Apache的安裝與配置mysql

4、php的安裝與配置linux

5、整合Apache與PHP服務sql

6、安裝Mysql服務器數據庫

7、安裝Memcache與libeventapache


1、LAMMP簡介編程

   LAMP(Linux- Apache-MySQL-PHP)網站架構是目前國際流行的Web框架,該框架包括:Linux操做系統,Apache網絡服務器,MySQL數據 庫,Perl、PHP或者Python編程語言,全部組成產品均是開源軟件,是國際上成熟的架構框架,不少流行的商業應用都是採起這個架構,和 Java/J2EE架構相比,LAMP具備Web資源豐富、輕量、快速開發等特色,微軟的.NET架構相比,LAMP具備通用、跨平臺、高性能、低價格的 優點,所以LAMP不管是性能、質量仍是價格都是企業搭建網站的首選平臺。在此基礎上咱們增長了Memcache緩衝服務器,解決了應用程序與數據庫之間的瓶頸問題,有效提升了訪問速度,這就是LAMMP架構。vim


2、LAMMP項目環境簡介centos

系統環境:centos6.4-x86_64

所需軟件以及下載地址:memcache-2.2.7 (http://www.pecl.php.net/package/memcache) memcached-1.4.17.tar.gz (http://www.memcached.org/ )  apr-1.4.六、apr-util-1.5.一、httpd-2.4.4(http://pan.baidu.com/s/1pJFGBlL ) php-5.5.八、mysql-5.6.15-linux-glibc2.5-x86_6四、libevent-2.0.16-stable(http://pan.baidu.com/s/1bnrcENd)

拓撲圖:

wKiom1L3KQiQRwa9AADdYf4VScg010.jpg

ip地址規劃:

httpd+php服務器:192.168.29.20 192.168.29.30

memcached服務器: 192.168.29.40

mysql服務器:192.168.29.50

3、Apache的安裝與配置

  • 準備系統環境:


[root@nddnd ~]# yum --disablerepo=\* --enablerepo=c6-media groupinstall "Development tools"

[root@nddnd ~]# yum --disablerepo=\* --enablerepo=c6-media install pcre-devel

  • 安裝apr


[root@nddnd ~]# tar -zxvf apr-1.4.6.tar.gz -C /usr/local/src/

[root@nddnd apr-1.4.6]# ./configure --prefix=/usr/local/apr

[root@nddnd apr-1.4.6]# make && make install


  • 安裝apr-util

  [root@nddnd ~]# tar -zxvf apr-util-1.5.1.tar.gz -C /usr/local/src

[root@nddnd apr-util-1.5.1]# ./configure --prefix=/usr/local/apr-util --with

  -apr=/usr/local/apr/bin/apr-1-config

  [root@nddnd apr-util-1.5.1]# make && make install

  • 安裝Apache

    [root@nddnd ~]# tar -jxvf httpd-2.4.4.tar.bz2  -C /usr/local/src

   [root@nddnd httpd-2.4.4]#./configure  --prefix=/usr/local/apache\

   --sysconfdir=/etc/httpd

   --enable-so \

   --enable-rewrite \

   --with-apr=/usr/local/apr/bin/apr-1-config \

   --with-apr-util=/usr/local/apr-util/bin/apu-1-config \

   --with-pcre  \

   --with-z   \

   --enable-mpms-shared=all \

   --with-mpm=event

  [root@nddnd httpd-2.4.4]# make && make install

  • 編寫httpd控制腳本/etc/init.d/httpd,內容以下

#!/bin/bash

#chkconfig: 2345 88 40

#description: the server is httpd server

prog=/usr/local/apache/bin/httpd

lockfile=/var/lock/subsys/httpd

start(){

       if [ -e $lockfile ];then

       echo "httpd server isstarted"

       else echo -n "httpd server isstarting... "

       sleep 1

       $prog -k start &>/dev/null  && echo  "[ ok ]" && touch $lockfile||echo "[ failer ]"

       fi

}

stop(){

       if [ ! -e $lockfile ];then

       echo "httpd server is stoped"

       else echo -n "httpd server isstoping... "

       sleep 1

       $prog -k stop && echo "[ok ]" && rm -rf $lockfile ||echo "[ failer ]"


       fi

}

status(){

       if [ -e $lockfile ];then

       echo "httpd server isstarted"

       else echo "httpd server no found"

       fi

}

case $1 in

start)

  start

  ;;

stop)

  stop

  ;;

restart)

  stop

  start

  ;;

status)

  status

  ;;

*)

echo"USAGE:start|stop|restart|status"

 ;;

esac

  • 爲此腳本賦予執行權限


[root@nddnd ~]# chmod a+x /etc/init.d/httpd


  • 將httpd加入服務列表


[root@nddnd ~]# chkconfig --add httpd


  • 啓動httpd服務


[root@nddnd ~]# service httpd start

httpd server is starting... [ ok ]


  • 客戶端訪問測試

wKioL1L3OGWBDyleAADEbUY9tds787.jpg


4、php的安裝與配置

  • 系統環境安裝


[root@nddnd ~]# yum --disablerepo=\* --enablerepo=c6-media install libxml2-devel openssl-devel


  • 安裝php服務


[root@nddnd ~]# tar -jxvf php-5.5.8.tar.bz2 -C /usr/local/src

[root@nddnd php-5.5.8]#  ./configure     --prefix=/usr/local/php   --enable-fpm     --enable-sockets    --with-mysql=mysqlnd --with-mysqli=mysqlnd  --with-pdo-mysql=mysqlnd --enable-mbstring  --enable-xml  --with-png-dir   --with-jpeg-dir --with-zlib --with-freetype-dir --with-config-file-path=/etc/php --with-config-file-scan-dir=/etc/php5.d

[root@nddnd php-5.5.8]# make && make install

  • 爲php提供配置文件


[root@nddnd php-5.5.8]# cp php.ini-production /etc/php/php.ini


  • 爲php-fpm產生控制腳本,而且給於可執行權限


[root@nddnd php-5.5.8]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

[root@nddnd php-5.5.8]# chmod a+x /etc/init.d/php-fpm


  • 爲php-fpm提供配置文件:

1

[root@nddnd ~]# cd /usr/local/php/etc

[root@nddnd etc]# cp php-fpm.conf.default php-fpm.conf


  • 啓動php-fpm服務

1

[root@nddnd etc]# service php-fpm start

Starting php-fpm  done


  • 查看服務是否已經啓動

wKiom1L3UJnRV2lyAACLgrzF7OU627.jpg

5、整合Apache與PHP服務

  • 配置Apache服務器

wKiom1L3UmLzTJTkAABaPh-fVko275.jpg

wKioL1L3VgzBGUo9AACmVn63hxQ773.jpg

在配置文件中任意位置添加下面兩句話

AddType application/x-httpd-php .php

AddType application/x-httpd-php-source .phps

添加默認php主頁

DirectoryIndex index.php index.html

ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/$1


  • 從新啓動httpd服務


[root@nddnd htdocs]# service httpd restart


  • 建立php測試腳本

1
2
3
4
5

[root@nddnd etc]# cd /usr/local/apache/htdocs/

[root@nddnd htdocs]# vim index.php

<?php

phpinfo();

?>



  • 客戶端測試php是否工做正常

wKioL1L3VtzD5BeAAAMagrQxvEQ755.jpg

6、安裝Mysql服務器

Mysq有三種安裝方式

  1. rpm包

  2. 通用二進制包

  3. 源碼包

此處咱們採用通用二進制包安裝



  • 安裝並初始化mysql

1
2
3
4
5
6
7
8
9

[root@nddnd ~]# tar -zxvf mysql-5.6.15-linux-glibc2.5-x86_64.tar.gz -C /usr/local/

[root@nddnd local]# ln -s mysql-5.6.15-linux-glibc2.5-x86_64 mysql

[root@nddnd local]# groupadd mysql

[root@nddnd local]# useradd -r -g mysql mysql

[root@nddnd local]# chown -R mysql:mysql .

[root@nddnd local]# cd mysql

[root@nddnd mysql]# ./scripts/mysql_install_db --user=mysql

[root@nddnd mysql]# chown -R root .

[root@nddnd mysql]# chown -R mysql data/


  • 爲mysql提供主配置文件

1
2

[root@nddnd mysql]# cd support-files/

[root@nddnd support-files]# cp my-default.cnf /etc/my.cnf



  • 爲mysql提供sysv服務腳本並添加到服務列表

1
2
3
4

[root@nddnd support-files]# cp mysql.server /etc/init.d/mysqld

[root@nddnd support-files]# chmod a+x /etc/init.d/mysqld

[root@nddnd support-files]# chkconfig --add mysqld

[root@nddnd support-files]# chkconfig mysqld on


  • 輸出mysql的man手冊至man命令的查找路徑

1
[root@nddnd mysql]# vim /etc/man.config

wKioL1L3Rjjy-F7YAAAs1B-YOPU641.jpg



  • 修改PATH環境變量,讓系統能夠直接使用mysql的相關命令。


[root@nddnd mysql]# vim /etc/profile

wKiom1L3R07gkXjZAAAwgWdLwyE847.jpg


  • 啓動mysqld服務

1

[root@nddnd mysql]# service mysqld start

Starting MySQL........ SUCCESS!


  • 建立mysql管理賬號

[root@nddnd mysql]# mysqladmin -u root -p password '123'

  • 數據庫受權

1
2
3

root@nddnd ~]# mysql -u root -p

mysql> grant all privileges on *.* to root@'%' identified by '123';

Query OK, 0 rows affected (0.18 sec)


  • 客戶端鏈接測試

    在httpd+php服務器上編輯index.php網頁

    wKiom1L4KzXjEO9dAACKOd18dP4606.jpg

   測試連接

wKioL1L4K1SSG33_AABOSG787hM583.jpg

7、安裝Memcache與libevent

  • 安裝libevent

memcached依賴於libevent API,所以要事先安裝。

1
2
3
4

[root@nddnd ~]# tar -zxvf libevent-2.0.16-stable.tar.gz -C /usr/local/src

[root@nddnd ~]# cd /usr/local/src/libevent-2.0.16-stable

[root@nddnd libevent-2.0.16-stable]# ./configure --prefix=/usr/local/libevent

[root@nddnd libevent-2.0.16-stable]# make && make install


1
2
3
4

[root@nddnd libevent-2.0.16-stable]# cd /usr/local/libevent/

[root@nddnd include]# vim /etc/ld.so.conf.d/libevent.conf

/usr/local/libevent/lib

[root@nddnd include]# ldconfig

  • 安裝memcached

1
2
3
4
5

[root@nddnd ~]# tar -zxvf memcached-1.4.17.tar.gz -C /usr/local/src

[root@nddnd ~]# cd /usr/local/src/memcached-1.4.17

[root@nddnd memcached-1.4.17]# ./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent/

[root@nddnd memcached-1.4.17]# make && make install


  • 啓動memcached並查看監聽端口

1
2
3

[root@nddnd memcached-1.4.17]# cd /usr/local/memcached/bin

[root@nddnd bin]# ./memcached -u nobody -m 512m -d

[root@nddnd bin]# netstat -tupln |grep 11211

wKiom1L4NsWDo_0bAADaoTzwuW0962.jpg

  • 安裝Memcache客戶端

1
2
3
4
5
6
7
8
9
10

[root@nddnd ~]# tar -zxvf memcache-2.2.7.tgz -C /usr/local/src

[root@nddnd ~]# cd /usr/local/src/memcache-2.2.7/

[root@nddnd memcache-2.2.7]# /usr/local/php/bin/phpize

Configuring for:

PHP Api Version:         20121113

Zend Module Api No:      20121212

Zend Extension Api No:   220121212

[root@nddnd memcache-2.2.7]# ./configure --enable-memcache --with-php-config=/usr/local/php/bin/php-config

[root@nddnd memcache-2.2.7]# make && make install



  • 修改php配置文件加載memcached模塊

1
2
3

[root@nddnd memcache-2.2.7]# vim /etc/php/php.in

[memcache]

extension = /usr/local/php/lib/php/extensions/no-debug-non-zts-20121212/memcache.so



  • 從新啓動此服務php-fpm

1
2
3

[root@nddnd memcache-2.2.7]# service php-fpm restart

Gracefully shutting down php-fpm . done

Starting php-fpm  done


  • 此時在客戶端測試php與memcache是否鏈接成功

wKiom1L4aNezXSrKAAHMaTkFrzI829.jpg

  • 測試memcached與php是否工做正常

1
2
3
4
5
6
7
8
9
10
11
12

<?php

error_reporting(E_ALL & ~E_NOTICE);

$mc = new memcache;

$mc->addServer("localhost", 11211);

$mc->set("foo", "Hello!");

$mc->set("bar", "Memcached...");

$arr = array(

$mc->get("foo"),

$mc->get("bar")

);

var_dump($arr);

?>

  • 客戶端再次訪問測試

wKiom1L4aZahJAfzAABmvye4QR4375.jpg



至此LAMMP環境搭建完成。。。

相關文章
相關標籤/搜索