php在apache下一般有三种工作方式:CGI,Apache模块,FastCGI

在CGI模式下,如果用户请求一个php文件,web服务器就会调用php解析器去解析这个文件,然后把结果返回给客户端。

在apache模块模式下,将php解析器作为了apache的一个模块,这样php解析器就与web服务器一起运行。

在fastcgi模式下,web服务器不会像cgi那样每次都启动一个新的进程,而是将内容传递到一个已有的进程中(这个进程在web服务器启动时就开启了,而且不会退出),这个进程就会一次次的处理来自客户端的请求。

这里我们将演示以模块化的方式工作的LAMP。安装的流程是

httpd--->mariadb--->php--->phpMyadmin--->Xcache

一.编译安装httpd,我们这里的编译安装都是在CentOS6环境下进行的。

编译前的环境准备:

apr-1.5.0.tar.bz2--->apr-util-1.5.3.tar.bz2--->httpd-2.4.10.tar.bz2

httpd-2.4.10编译过程也要依赖于pcre-devel软件包,需要事先安装。

包组:Development tools ,Server Platform Development

接下来我们就可以进行编译了:

1,编译apr-1.5.0.tar.bz2

yumgroupinstall"DevlopmentTools""ServerPlatformDevelopment"-yyuminstallpcre-devel[root@localhosttmp]#tarxfapr-1.5.0.tar.bz2[root@localhosttmp]#cdapr-1.5.0[root@localhostapr-1.5.0]#./configure--prefix=/usr/local/apr[root@localhostapr-1.5.0]#make&&makeinstall

2,编译apr-util-1.5.3.tar.bz2



[root@localhosttmp]#tar-xfapr-util-1.5.3.tar.bz2[root@localhosttmp]#cdapr-util-1.5.3[root@localhostapr-util-1.5.3]#./cconfigurecrypto/[root@localhostapr-util-1.5.3]#./configure--prefix=/usr/loacl/apr-util--with-apr=/usr/local/apr[root@localhostapr-util-1.5.3]#make&&makeinstall

3,编译httpd-2.4.10.tar.bz2

[root@localhosttmp]#tar-xfhttpd-2.4.10.tar.bz2[root@localhosttmp]#cdhttpd-2.4.10[root@localhosthttpd-2.4.10]#./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[root@localhosthttpd-2.4.10]#make&&makeinstall




这样的话我们的httpd-2.4就编译完成了

[root@localhost~]#vim/etc/profile.d/httpd24.shexportPATH=/usr/local/apache/bin:$PATH[root@localhost~]#vim/etc/profile.d/httpd24.sh[root@localhost~]#./etc/profile.d/httpd24.sh[root@localhost~]#echo$PATH/usr/local/apache/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin[root@localhost~]#clear[root@localhost~]#cd/etc/rc.d/init.d/[root@localhostinit.d]#cphttpdhttpd24[root@localhostinit.d]#vimhttpd24


为httpd24提供的脚本中,我们只需要修改一下


接着我们把httpd24加到服务中去,然后启动就可以了

[root@localhosthttpd]#chkconfig--addhttpd24[root@localhosthttpd]#chkconfighttpd24on[root@localhosthttpd]#chkconfig--listhttpd24httpd240:off1:off2:on3:on4:on5:on6:off


修改httpd的主配置文件,设置其Pid文件的路径

编辑/etc/httpd/httpd.conf,添加如下行即可:

PidFile "/var/run/httpd/httpd.pid"

二.编译安装mariadb,我们这里使用的是mariadb的通用二进制包来编译。

1、准备数据存放的文件系统

新建一个逻辑卷,并将其挂载至特定目录即可。这里不再给出过程。

这里假设其逻辑卷的挂载目录为/mydata,而后需要创建/mydata/data目录做为mysql数据的存放目录。

[root@localhosttmp]#tar-xfmariadb-5.5.43-linux-x86_64.tar.gz-C/usr/local[root@localhosttmp]#cd/usr/local[root@localhostlocal]#ln-svmariadb-5.5.43-linux-x86_64/mysql`mysql'->`mariadb-5.5.43-linux-x86_64/'


2、新建用户以安全方式运行进程:


#groupadd-rmysql###创建系统组#useradd-gmysql-r-s/sbin/nologin-M-d/mydata/datamysql#chown-Rmysql:mysql/mydata/data[root@localhostmysql]#scripts/mysql_install_db--user=mysql--datadir=/mydata/dataI#####指明数据库位置在/mydata/data


3.接着我们要为数据库提供主配置文件

[root@localhost~]#cd/usr/local/mysql[root@localhostmysql]#cpsupport-files/my-large.cnf/etc/my.cnfcp:overwrite`/etc/my.cnf'?y


并修改此文件中thread_concurrency的值为你的CPU个数乘以2,比如这里使用如下行:

thread_concurrency = 2

另外还需要添加如下行指定mysql数据文件的存放位置:

datadir = /mydata/data

4.位数据库提供服务脚本

[root@localhost~]#cd/usr/local/mysql[root@localhostmysql]#cpsupport-files/mysql.server/etc/rc.d/init.d/mysqld[root@localhostmysql]#chmod+x/etc/rc.d/init.d/mmdmonitormessagebusmysqld[root@localhostmysql]#chmod+x/etc/rc.d/init.d/mysqld[root@localhostmysql]#chkconfig--addmysqld[root@localhostmysql]#chkconfigmysqldon[root@localhostmysql]#chkconfig--listmysqldmysqld0:off1:off2:on3:on4:on5:on6:off[root@localhostmysql]#


接下来,启动服务,看是否能启动成功

[root@localhost~]#servicemysqldstartStartingMySQL...............SUCCESS!


我们要给数据库安全初始化

[root@localhost~]#cd/usr/local/mysql/bin[root@localhostbin]#.mysql_secure_installation###安全初始化


至此,我们的数据编译完毕。

三,编译PHP

1、解决依赖关系:


请配置好yum源(系统安装源及epel源)后执行如下命令:

# yum -y groupinstall "Desktop Platform Development" ###这个需要配置本地yum源

# yum -y install bzip2-devel libmcrypt-devel libxml2-devel##这个需要配置epl源

2.接着我们安装下面的步骤进行就OK

# tar xf php-5.4.26.tar.bz2

# cd php-5.4.26

# ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --with-apxs2=/usr/local/apache/bin/apxs --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --enable-maintainer-zts

注意:这里为了支持apache的worker或event这两个MPM,编译时使用了--enable-maintainer-zts选项。

# make && make install

为php提供配置文件:

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


3、 编辑apache配置文件httpd.conf,以apache支持php

# vim /etc/httpd24/httpd.conf

(1)添加如下二行

AddType application/x-httpd-php .php

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


(2)定位至DirectoryIndex index.html

修改为:

DirectoryIndex index.php index.html


而后重新启动httpd,或让其重新载入配置文件即可测试php是否已经可以正常使用。

有上面可以看到我们的三者的结合是成功的,所以LAMP编译完成。接下来我们来部署phpadmin图形化工具



[root@localhosttmp]#unzipphpMyAdmin-4.4.14.1-all-languages.zip[root@localhosttmp]#cp-aphpMyAdmin-4.4.14.1-all-languages/usr/local/apache/htdocs/[root@localhosttmp]#cd/usr/local/apache/htdocs/[root@localhosthtdocs]#lsindex.phpphpMyAdmin-4.4.14.1-all-languages[root@localhosthtdocs]#mvphpMyAdmin-4.4.14.1-all-languages/pma[root@localhostpma]#cpconfig.sample.inc.phpconfig.inc.php[root@localhostpma]#vimconfig.inc.php$cfg['blowfish_secret']='seijoiefhsidfhidjfidsf';这里的随机子串可以自己填写也可以随机生成[root@localhostpma]#cd/usr/local/mysql/bin/[root@localhostbin]#.mysql_secure_installation###安全初始化,给root用户设置密码。

四,安装xcache,为php加速:



[root@localhosttmp]#tar-xfxcache-3.1.2.tar.gz[root@localhosttmp]#cdxcache-3.1.2[root@localhostxcache-3.1.2]#/usr/local/php/bin/phpphpphp-cgiphp-configphpize[root@localhostxcache-3.1.2]#/usr/local/php/bin/phpizeConfiguringfor:PHPApiVersion:20100412ZendModuleApiNo:20100525ZendExtensionApiNo:220100525[root@localhostxcache-3.1.2]#./configure--enable-xcache--with-php-config=/usr/local/php/bin/php-config[root@localhostxcache-3.1.2]#make&&makeinstallInstallingsharedextensions:/usr/local/php/lib/php/extensions/no-debug-zts-20100525/[root@localhostxcache-3.1.2]#mkdir/etc/php.d[root@localhostxcache-3.1.2]#cpxcache.ini/etc/php.d[root@localhostxcache-3.1.2]#vim/etc/php.d/xcache.iniextension=/usr/local/php/lib/php/extensions/no-debug-zts-20100525/xcache.so

上图可知xcache已经加入到PHP中去了,现在可以做压力测试看看效果。

[root@lirui ~]# ab -c 200 -n 10000 http://192.168.1.101/pma

忘记在便宜xcache做压力测试了,不过,前面没做,这种效果也可以从上图可以看出。

到此就完了,写的有些凌乱,日后有时间在修改吧