一、LAMMP简介
LAMP(Linux-Apache-MySQL-PHP)网站架构是目前国际流行的Web框架,该框架包括:Linux操作系统,Apache网络服务器,MySQL数据库,Perl、PHP或者Python编程语言,所有组成产品均是开源软件,是国际上成熟的架构框架,很多流行的商业应用都是采取这个架构,和Java/J2EE架构相比,LAMP具有Web资源丰富、轻量、快速开发等特点,与微软的.NET架构相比,LAMP具有通用、跨平台、高性能、低价格的优势,因此LAMP无论是性能、质量还是价格都是企业搭建网站的首选平台。在此基础上增加了Memcache缓冲服务器,解决了应用程序与数据库之间的瓶颈问题,有效提高了访问速度,这就是LAMMP架构。
二、环境简介
系统:CentOS6.4 32位系统
Apache+php 192.168.2.100
Mysql 192.168.2.101
Meecached 192.168.2.102
三、apache+php安装与配置
a)apache安装
[root@localhost ~]# ll //上传
-rw-r--r--. 1 root root 982243 Jan 19 04:18 apr-1.4.6.tar.gz
-rw-r--r--. 1 root root 829779 Jan 19 04:18 apr-util-1.5.1.tar.gz
-rw-r--r--. 1 root root 4780289 Jan 19 02:54 httpd-2.4.4.tar.bz2
[root@localhost ~]# rpm -qa |grep httpd //安装前查看系统中是否有和httpd相关的包
httpd-tools-2.2.15-26.el6.centos.i686
httpd-2.2.15-26.el6.centos.i686
[root@localhost ~]# yum remove httpd //卸载,避免冲突
[root@localhost ~]# tar -jxvf httpd-2.4.4.tar.bz2 -C /usr/local/src/
[root@localhost ~]# tar -zxvf apr-util-1.5.1.tar.gz -C /usr/local/src/
[root@localhost ~]# tar -zxvf apr-1.4.6.tar.gz -C /usr/local/src/
[root@localhost ~]# yum install pcre-devel
[root@localhost ~]# cd /usr/local/src/
[root@localhost src]# cd apr-1.4.6/ //安装apr
[root@localhost apr-1.4.6]# ./configure --prefix=/usr/local/apr
[root@localhost apr-1.4.6]#make && make install
[root@localhost apr-1.4.6]# cd ../apr-util-1.5.1/ //安装apr-util
[root@localhost apr-util-1.5.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config
[root@localhost apr-util-1.5.1]# make && make install
[root@localhost apr-util-1.5.1]# cd ../httpd-2.4.4/ //安装httpd
[root@localhost 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@localhost httpd-2.4.4]# make && make install //耐心等待...
[root@localhost httpd-2.4.4]# ll /usr/local/apache/ //安装完毕后,查看。
drwxr-xr-x. 2 root root 4096 Jan 19 16:43 bin
drwxr-xr-x. 2 root root 4096 Jan 19 16:43 build
drwxr-xr-x. 2 root root 4096 Jan 19 16:43 cgi-bin
drwxr-xr-x. 3 root root 4096 Jan 19 16:43 error
drwxr-xr-x. 2 root root 4096 Jan 19 04:24 htdocs
drwxr-xr-x. 3 root root 4096 Jan 19 16:43 icons
drwxr-xr-x. 2 root root 4096 Jan 19 16:43 include
drwxr-xr-x. 2 root root 4096 Jan 19 16:43 logs
drwxr-xr-x. 4 root root 4096 Jan 19 16:43 man
drwxr-xr-x. 14 root root 12288 Feb 18 2013 manual
drwxr-xr-x. 2 root root 4096 Jan 19 16:43 modules
[root@localhost httpd-2.4.4]# ll /etc/httpd/ //httpd配置文件
drwxr-xr-x. 2 root root 4096 Jan 19 04:21 conf.d
drwxr-xr-x. 2 root root 4096 Jan 19 16:43 extra
-rw-r--r--. 1 root root 18123 Jan 19 16:43 httpd.conf
-rw-r--r--. 1 root root 13077 Jan 19 16:43 magic
-rw-r--r--. 1 root root 53011 Jan 19 16:43 mime.types
drwxr-xr-x. 3 root root 4096 Jan 19 16:43 original
[root@localhost httpd-2.4.4]# vi /etc/httpd/httpd.conf //查看httpd根路径
[root@localhost httpd-2.4.4]# cd /usr/local/apache/
[root@localhost apache]# cd bin
[root@localhost bin]# ll
-rwxr-xr-x. 1 root root 1434187 Jan 19 16:43 httpd
[root@localhost bin]# vi /etc/httpd/httpd.conf
[root@localhost bin]# ./httpd -k start //启动apache
[root@localhost bin]# netstat -tupln |grep 80
tcp 0 0 :::80 :::* LISTEN 20027/./httpd
[root@localhost bin]# pwd
/usr/local/apache/bin
[root@localhost bin]# cd /etc/init.d/
[root@localhost init.d]# vi httpd //创建启动脚本
#!/bin/bash [ -e /etc/init.d/functions ] && . /etc/init.d/functions prog=/usr/local/apache/bin/httpd lockfile=/var/lock/subsys/httpd start () { if [ -e $lockfile ];then echo "The httpd server is started" else echo "The httpd server is starting..." sleep 1 $prog && echo -e "[ \033[32mOK\033[0m ]" && touch $lockfile fi } stop () { if [ ! -e $lockfile ];then echo "The httpd server is stoped..." else echo -n "The httpd server is stoping..." sleep 1 killproc httpd && echo "ok" && rm -rf $lockfile || echo "failer" fi } status () { if [ -e $lockfile ];then echo "The httpd server is running..." else echo "The httpd is stop" fi } case "$1" in start) start ;; stop) stop ;; restart) stop start ;; status) status ;; *) echo "USE ONLY:start|stop|restart|status" esac
[root@localhost init.d]# chmod a+x httpd //赋予执行权限
[root@localhost init.d]# netstat -tupln |grep :80
tcp 0 0 :::80 :::* LISTEN 20027/./httpd
[root@localhost init.d]# service httpd restart //重启测试
The httpd server is stoped...
The httpd server is starting...
[ OK ]
[root@localhost init.d]# service httpd status
The httpd server is running...
访问http://192.168.2.100 //访问apache服务器地址,测试正常。
b)安装php
[root@localhost ~]# mkdir -pv /etc/php /etc/php5.d
mkdir: created directory `/etc/php'
mkdir: created directory `/etc/php5.d'
[root@localhost ~]# rpm -qa |grep php //系统中没有和php相关的包。
[root@localhost ~]# ll
-rw-r--r--. 1 root root 13005675 Jan 19 02:54 php-5.5.8.tar.bz2
[root@localhost ~]# tar -jxvf php-5.5.8.tar.bz2 -C /usr/local/src/
[root@localhost ~]# cd /usr/local/src/
[root@localhost src]# ll
drwxr-xr-x. 14 1001 1001 4096 Jan 8 02:33 php-5.5.8
[root@localhost src]# cd php-5.5.8/
[root@localhost php-5.5.8]# ./configure -h //可以帮助看下各个指令的含义
[root@localhost 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@localhost php-5.5.8]# make && make install //编译成功后安装
[root@localhost php-5.5.8]# cp php.ini-development /etc/php/php.ini
[root@localhost php-5.5.8]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@localhost php-5.5.8]# chmod a+x /etc/init.d/php-fpm
[root@localhost php-5.5.8]# cd /usr/local/php/
[root@localhost php]# ll
drwxr-xr-x. 2 root root 4096 Feb 9 03:45 bin
drwxr-xr-x. 2 root root 4096 Feb 9 03:45 etc
drwxr-xr-x. 3 root root 4096 Feb 9 03:45 include
drwxr-xr-x. 3 root root 4096 Feb 9 03:44 lib
drwxr-xr-x. 4 root root 4096 Feb 9 03:44 php
drwxr-xr-x. 2 root root 4096 Feb 9 03:44 sbin
drwxr-xr-x. 4 root root 4096 Feb 9 03:44 var
[root@localhost php]# cd etc/
[root@localhost etc]# ll
-rw-r--r--. 1 root root 1152 Feb 9 03:45 pear.conf
-rw-r--r--. 1 root root 21862 Feb 9 03:44 php-fpm.conf.default
[root@localhost etc]# cp php-fpm.conf.default php-fpm.conf
[root@localhost etc]# service php-fpm start
Starting php-fpm done
[root@localhost etc]# netstat -tupln |grep 9000
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 6719/php-fpm
[root@localhost ~]# vim /etc/httpd/httpd.conf
[root@localhost ~]# service httpd restart //修改配置文件后要重启
[root@localhost ~]# tar -zxvf xcache-3.1.0.tar.gz -C /usr/local/src/
[root@localhost ~]# cd /usr/local/src/xcache-3.1.0/
[root@localhost xcache-3.1.0]# /usr/local/php/bin/phpize
Configuring for:
PHP Api Version: 20121113
Zend Module Api No: 20121212
Zend Extension Api No: 220121212
[root@localhost xcache-3.1.0]# ./configure --enable-xcache --with-php-
config=/usr/local/php/bin/php-config
[root@localhost xcache-3.1.0]# make && make install
Installing shared extensions: /usr/local/php/lib/php/extensions/no-
debug-non-zts-20121212/
[root@localhost xcache-3.1.0]# ll /usr/local/php/lib/php/extensions/no-
debug-non-zts-20121212/
-rwxr-xr-x. 1 root root 687720 Feb 9 03:44 opcache.a
-rwxr-xr-x. 1 root root 472303 Feb 9 03:44 opcache.so
-rwxr-xr-x. 1 root root 586238 Feb 9 05:17 xcache.so
[root@localhost xcache-3.1.0]# cp xcache.ini /etc/php5.d/
[root@localhost xcache-3.1.0]# vim xcache.ini
[root@localhost xcache-3.1.0]# service php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm done
四、安装mysql
[root@localhost ~]# rpm -qa |grep mysql //安装源码前查看系统中是否有和mysql相关的包
mysql-libs-5.1.66-2.el6_3.i686
mysql-5.1.66-2.el6_3.i686
mysql-devel-5.1.66-2.el6_3.i686
[root@localhost ~]# yum remove mysql mysql-devel mysql-libs //将所有关于mysql及依赖包全部卸载,避免冲突。
[root@localhost ~]# ll //上传mysql源码包
-rw-r--r--. 1 root root 32794954 Jan 19 02:54 mysql-5.6.15.tar.gz
[root@localhost ~]# tar -zxvf mysql-5.6.15.tar.gz -C /usr/local/src //解压缩
[root@localhost ~]# cd /usr/local/src/
[root@localhost src]# ll
drwxr-xr-x. 33 7161 wheel 4096 Nov 17 10:03 mysql-5.6.15
[root@localhost src]# cd mysql-5.6.15
[root@localhost mysql-5.6.15]# groupadd mysql
[root@localhost mysql-5.6.15]# useradd -r -g mysql mysql
[root@localhost mysql-5.6.15]# cd mysql-5.6.15/
[root@localhost mysql-5.6.15]# yum install cmake //编译需要使用cmake
[root@localhost mysql-5.6.15]#cmake .
[root@localhost mysql-5.6.15]#make //耐心等待...
[root@localhost mysql-5.6.15]#make install
[root@localhost mysql-5.6.15]# cd /usr/local/mysql/
[root@localhost mysql]# chown -R mysql .
[root@localhost mysql]# chgrp -R mysql .
[root@localhost mysql]# scripts/mysql_install_db --user=mysql //重置数据库
[root@localhost mysql]# chown -R root .
[root@localhost mysql]# chown -R mysql data
[root@localhost mysql]# cp my.cnf /etc/
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld //创建配置文件
[root@localhost mysql]# chmod a+x /etc/init.d/mysqld
[root@localhost mysql]# service mysqld start //启动mysql
Starting MySQL.. SUCCESS!
[root@localhost mysql]# netstat -tupln |grep 3306
tcp 0 0 :::3306 :::* LISTEN 18960/mysqld
[root@localhost mysql]# chkconfig --add mysqld
[root@localhost mysql]# chkconfig mysqld on //添加至开机启动
[root@localhost mysql]# vi /etc/profile //系统调用
[root@localhost mysql]# . /etc/profile
[root@localhost mysql]# mysql //测试登录,正常。
mysql> \q
Bye
[root@localhost mysql]# mysqladmin -u root -p password '123' //创建用户
Enter password: //让输入旧的密码,此处回车即可
[root@localhost mysql]# mysql -u root -p
mysql> \q
Bye
五、安装memcached
[root@localhost ~]# tar -zxvf libevent-2.0.21-stable.tar.gz -C /usr/local/src
[root@localhost ~]# cd /usr/local/src/libevent-2.0.21-stable/
[root@localhost libevent-2.0.21-stable]# ./configure --prefix=/usr/local/libevent
[root@localhost libevent-2.0.21-stable]# make && make install
[root@localhost libevent-2.0.21-stable]# cd /usr/local/libevent/
[root@localhost libevent]# ll
drwxr-xr-x. 2 root root 4096 Feb 9 03:40 bin
drwxr-xr-x. 3 root root 4096 Feb 9 03:40 include
drwxr-xr-x. 3 root root 4096 Feb 9 03:40 lib
[root@localhost libevent]# vim /etc/ld.so.conf.d/libevent.conf
/usr/local/libevent/lib
[root@localhost libevent]# ldconfig
[root@localhost libevent]# ldconfig -pv|grep libevent
libevent_pthreads-2.0.so.5 (libc6) => /usr/local/libevent/lib/libevent_pthreads-2.0.so.5
libevent_extra-2.0.so.5 (libc6) => /usr/local/libevent/lib/libevent_extra-2.0.so.5
libevent_core-2.0.so.5 (libc6) => /usr/local/libevent/lib/libevent_core-2.0.so.5
libevent-2.0.so.5 (libc6) => /usr/local/libevent/lib/libevent-2.0.so.5
[root@localhost libevent]# cd
[root@localhost ~]# tar -zxvf memcached-1.4.17.tar.gz -C /usr/local/src/
[root@localhost ~]# cd /usr/local/src/memcached-1.4.17/
[root@localhost memcached-1.4.17]# ./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent/
[root@localhost memcached-1.4.17]# make && make install
[root@localhost memcached-1.4.17]# cd /usr/local/memcached/
[root@localhost memcached]# ll
drwxr-xr-x. 2 root root 4096 Feb 9 03:56 bin
drwxr-xr-x. 3 root root 4096 Feb 9 03:56 include
drwxr-xr-x. 3 root root 4096 Feb 9 03:56 share
[root@localhost memcached]# cd bin
[root@localhost bin]# ll
-rwxr-xr-x. 1 root root 258245 Feb 9 03:56 memcached
[root@localhost bin]# ./memcached -u nobody -m 64m -d -vv
[root@localhost bin]# netstat -tupln |grep 11211
tcp 0 0 0.0.0.0:11211 0.0.0.0:* LISTEN 9878/./memcached
tcp 0 0 :::11211 :::* LISTEN 9878/./memcached
udp 0 0 0.0.0.0:11211 0.0.0.0:* 9878/./memcached
udp 0 0 :::11211 :::* 9878/./memcached
[root@localhost bin]# telnet 127.0.0.1 11211
Trying 127.0.0.1...
<30 new auto-negotiating client connection
Connected to 127.0.0.1.
Escape character is '^]'.
stats
30: Client using the ascii protocol
连接测试
set foo 0 0 3
<30 set foo 0 0 3
nuo
>30 STORED
STORED
get foo
<30 get foo
>30 sending key foo
>30 END
VALUE foo 0 3
nuo
六、测试
[root@localhost ~]# tar -zxvf memcache-2.2.7.tgz -C /usr/local/src/
[root@localhost ~]# cd /usr/local/src/memcache-2.2.7/
[root@localhost 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@localhost memcache-2.2.7]# ./configure --enable-memcache --with-php-
config=/usr/local/php/bin/php-config
[root@localhost memcache-2.2.7]# make && make install
Installing shared extensions: /usr/local/php/lib/php/extensions/no-
debug-non-zts-20121212/
[root@localhost memcache-2.2.7]# ll /usr/local/php/lib/php/extensions/no-
debug-non-zts-20121212/
-rwxr-xr-x. 1 root root 216288 Feb 9 05:31 memcache.so
-rwxr-xr-x. 1 root root 687720 Feb 9 03:44 opcache.a
-rwxr-xr-x. 1 root root 472303 Feb 9 03:44 opcache.so
-rwxr-xr-x. 1 root root 586238 Feb 9 05:17 xcache.so
[root@localhost memcache-2.2.7]# vim /etc/php5.d/xcache.ini
[root@localhost memcache-2.2.7]# service php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm done
[root@localhost memcache-2.2.7]# vim /usr/local/apache/htdocs/index.php
1 <?php
2 error_reporting(E_ALL & ~E_NOTICE);
3 $mc = new memcache;
4 $mc->addServer("192.168.2.102", 11211);
5 $mc->set("foo", "Hello!");
6 $mc->set("bar", "Memcached...");
7 $arr = array(
8 $mc->get("foo"),
9 $mc->get("bar")
10 );
11 var_dump($arr);
12 ?>