LAMP简介: LAMP指的Linux(操作系统)、ApacheHTTP 服务器,MySQL(有时也指MariaDB,数据库软件) 和PHP(有时也是指Perl或Python) 的第一个字母,一般用来建立web 服务器。 Linux+Apache+Mysql/MariaDB+Perl/PHP/Python一组常用来搭建动态网站或者服务器的开源软件,本身都是各自独立的程序,但是因为常被放在一起使用,拥有了越来越高的兼容度,共同组成了一个强大的Web应用程序平台。随着开源潮流的蓬勃发展,开放源代码的LAMP已经与J2EE和.Net商业软件形成三足鼎立之势,并且该软件开发的项目在软件方面的投资成本较低,因此受到整个IT界的关注。从网站的流量上来说,70%以上的访问流量是LAMP来提供的,LAMP是最强大的网站解决方案.
为什么要使用源码安装:
理由 1.更新的版本 httpd mysql php 2.提高性能 3.自定义参数 apache 和 php的结合方式: 1.模块 libphp5.so 2.cgi 通用网关接口 3.fastcgi 快速cgi
下面我们使用模块的方式实现apache和php的结合: Linux环境 : centos 6.4 版本号2.6.32-431.el6.i686 32位操作系统 源码 httpd-2.4.9.tar.bz2 php-5.5.8.tar.bz2 mysql-5.6.15.tar.gz apr-1.4.6.tar.gz apr-util-1.5.1.tar.gz
预编译环境 : Development tools Server Platform Development Additional Development cmake MySQL的安装:
mysql从5.5版本开始,不再使用./configure编译,而是使用cmake编译器,具体的cmake编译参数可以参考mysql官网文档(※ 非常重要) http://dev.mysql.com/doc/refman/5.6/en/source-configuration-options.html 我的mysql目录配置如下: 安装路径:/usr/local/mysql 数据库路径:/usr/local/mysql/data 源码包存放位置:/usr/local/src [iyunv@vbird ~]# yum --disablerepo=* --enablerepo=c6-media groupinstall "Development tools" "Server Platform Development" –y [iyunv@vbird ~]# yum --disablerepo=* --enablerepo=c6-media remove mysql-libs -y (※ 卸载掉预安装的mysql的lib库文件) [iyunv@vbird ~]# yum --disablerepo=* --enablerepo=c6-media install cmake -y [iyunv@vbird ~]# tar -zxvf mysql-5.6.15.tar.gz -C /usr/local/src/ [iyunv@vbird ~]# cd /usr/local/src/mysql-5.6.15/ [root@vbirdmysql-5.6.15]#[url=]cmake [/url] -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DMYSQL_TCP_PORT=3306 -DMYSQL_UNIX_ADDR=/tmp/mysqld.sock -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci [iyunv@vbird mysql-5.6.15]# make && make install
来到MySQL的安装路径/usr/local/mysql下根据INSTALL-BINARY文件来完成MySQL的安装
[iyunv@vbird ~]# cd /usr/local/mysql/ [iyunv@vbird mysql]# vim INSTALL-BINARY
[iyunv@vbird mysql]# groupadd mysql [iyunv@vbird mysql]# useradd -r -g mysql mysql [iyunv@vbird local]# cd mysql/ [iyunv@vbird mysql]# chown -R mysql:mysql . [iyunv@vbird mysql]# ./scripts/mysql_install_db --user=mysql [iyunv@vbird mysql]# chown -R root . [iyunv@vbird mysql]# chown -R mysql data MySQL的后续处理 拷贝MySQL的配置文件到/etc目录下 [iyunv@vbird mysql]# cp my.cnf /etc 拷贝MySQL的控制脚本文件到/etc/init.d/目录下 [iyunv@vbird mysql]# cd support-files/ [iyunv@vbird support-files]# cp -p mysql.server /etc/init.d/mysqld 编辑环境预配置文件添加MySQL的搜索路径 [iyunv@vbird ~]# vim /etc/profile PATH=$PATH:/usr/local/mysql/bin [iyunv@vbird ~]# . /etc/profile 给MySQL设置管理口令 [iyunv@vbird ~]# mysqladmin -u root -p password '123' 设置开机自动启动 [iyunv@vbird ~]# chkconfig --add mysqld [iyunv@vbird ~]# chkconfig mysqld on 库文件的处理 [iyunv@vbird ~]# vim /etc/ld.so.conf.d/mysql.conf [iyunv@vbird ~]# ldconfig #刷新缓存 [iyunv@vbird ~]# ldconfig -pv |grep mysql #查看是否加载 头文件的处理 [iyunv@vbird ~]# cd /usr/include/ [iyunv@vbird include]# ln -s /usr/local/mysql/include/ mysql
MySQL手册的处理 [iyunv@vbird ~]# vim /etc/man.config MANPATH /usr/local/mysql/man
apache的安装:
为了方便apache的运行,需要搭建apache的可移植性运行环境,就需要额外使用两个包apr apr-util 解压缩包到/usr/local/src [iyunv@vbird ~]# tar -zxvf apr-1.4.6.tar.gz -C /usr/local/src/ [iyunv@vbird ~]# tar -zxvf apr-util-1.5.1.tar.gz -C /usr/local/src/ [iyunv@vbird ~]# tar -jxvf httpd-2.4.9.tar.bz2 -C /usr/local/src/ 安装apr [iyunv@vbird ~]# cd /usr/local/src/apr-1.4.6/ [iyunv@vbird apr-1.4.6]# ./configure --prefix=/usr/local/apr [iyunv@vbird apr-1.4.6]# make && make install 安装apr-utils [iyunv@vbird ~]# cd /usr/local/src/apr-util-1.5.1/ [iyunv@vbird apr-util-1.5.1]# ./configure --prefix=/usr/local/apr-utils --with-apr=/usr/local/apr/bin/apr-1-config [iyunv@vbird apr-util-1.5.1]# make && make install 安装httpd [iyunv@vbird ~]# cd /usr/local/src/httpd-2.4.9/ [iyunv@vbird httpd-2.4.9]# yum --disablerepo=* --enablerepo=c6-media install pcre-devel -y [iyunv@vbird httpd-2.4.9]# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-ssl --enable-rewrite --with-apr=/usr/local/apr/bin/apr-1-config --with-apr-util=/usr/local/apr-utils/bin/apu-1-config --with-pcre --with-z --enable-mpms-shared=all [iyunv@vbird httpd-2.4.9]# make && make install httpd的后续处理 编辑环境预配置文件添加httpd的搜索路径 [iyunv@vbird ~]# vim /etc/profile PATH=$PATH:/usr/local/apache/bin [iyunv@vbird ~]# . /etc/profile 头文件的处理 [iyunv@vbird ~]# cd /usr/include/ [iyunv@vbird include]# ln -s /usr/local/apache/include/ apache httpd手册的处理 [iyunv@vbird ~]# vim /etc/man.config MANPATH /usr/local/apache/man 编辑httpd的控制脚本 [iyunv@vbird init.d]# vim /etc/init.d/httpd #!/bin/bash prog=/usr/local/apache/bin/httpd lockfile=/var/lock/subsys/httpd # description: the httpd server # chkconfig: 2345 88 44 start() { if [ -e $lockfile ];then echo "the httpd server is started" else echo -n "the httpd server is starting" sleep 1 $prog -k start && echo –e " ok" && touch $lockfile || echo "failed" fi } stop() { if [ ! -e $lockfile ];then echo "the httpd server is stopped" else echo -n "the httpd server is stopping" sleep 1 $prog -k stop && echo –e " ok" && rm -rf $lockfile || echo "failed" fi } case "$1" in start) start ;; stop) stop ;; restart) stop start ;; *) echo "USAGE:start|stop|restart" ;; esac
[iyunv@vbird init.d]# chconfig --add httpd
PHP的安装: 先安装php所需的devel包 [iyunv@vbird php-5.5.8]# yum --disablerepo=* --enablerepo=c6-media install libxml2-devel libjpeg-turbo-devel libpng-devel freetype-devel -y 解压缩包到/usr/local/src [iyunv@vbird ~]# tar -jxvf php-5.5.8.tar.bz2 -C /usr/local/src/ [iyunv@vbird ~]# cd /usr/local/src/php-5.5.8/ [iyunv@vbird php-5.5.8]# ./configure --prefix=/usr/local/php --with-config-file-path=/etc/php --with-config-file-scan-dir=/etc/php5.d --with-apxs2=/usr/local/apache/bin/apxs --with-mysql=/usr/local/mysql --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring=all --with-gd --with-jpeg-dir
[iyunv@vbird php-5.5.8]# make && make install php的后续处理 创建php的配置文件目录php和额外扩展配置文件目录php5.d [iyunv@vbird ~]# mkdir -pv /etc/php /etc/php5.d [iyunv@vbird ~]# cd /usr/local/src/php-5.5.8/ [iyunv@vbird php-5.5.8]# cp php.ini-production /etc/php/php.ini
[url=]由于php和apache是用模块结合起来的[/url],vim httpd.conf 查看是否加载了php的模块 在httpd.conf 加入 AddType application/x-httpd-php .php指明.php文件的处理类型
添加.php类型的默认首页
在apache的默认站点目录下编辑一个默认.php类型的首页,做一下php和httpd的连接测试 [iyunv@vbird ~]# cd /usr/local/apache/htdocs/ [iyunv@vbird htdocs]# vim index.php
可以看到php的各种参数,连接成功
更改index.php的内容测试php和MySQL的连接情况
可以看到连接成功
[url=]搭建phpwind应用测试LAMP环境 这里我使用物理目录[/url] [iyunv@vbird ~]# unzip phpwind_v9.0_gbk.zip [iyunv@vbird ~]# cd phpwind_v9.0_gbk [root@vbirdphpwind_v9.0_gbk]#mv upload /usr/local/apache/htdocs/phpwind 使用浏览器访问http://192.168.2.100/phpwind可以看到出现了phpwind的安装向导
点击下一步可以看到环境检测没问题
来到phpwind目录下更改文件权限 [iyunv@vbird htdocs]# cd phpwind/ [iyunv@vbird phpwind]# chmod -R o+w attachment/ conf/ data/ html/ src/ themes/ windid/
创建数据
安装完成后成功进入站点
压力测试 Apache HTTP Web 服务器提供了一个叫做 ab 的工具,即 Apache HTTP 服务器性能检测(benchmark)工具的缩写。ab 用于为 PHP 页面自动化处理大量的请求 对静态页面index.html进行压力测试 可以看到只有每秒800左右 [iyunv@vbird ~]# ab -n 10000 -c 1000 http://192.168.2.100/index.html
对动态页面index.php进行压力测试 可以看到只有每秒300左右 [iyunv@vbird ~]# ab -n 1000 -c 500 http://192.168.2.100/index.php
这远远不能达到我们的要求,怎么加快它的响应速度呢?我们可以使用xcache对php进行缓存 安装xcache: [iyunv@vbird ~]# tar -zxvf xcache-3.1.0.tar.gz -C /usr/local/src/ [iyunv@vbird ~]# cd /usr/local/src/xcache-3.1.0/ [iyunv@vbird xcache-3.1.0]# vim INSTALL
使用phpize把xcache作为php的扩展 [iyunv@vbird xcache-3.1.0]# /usr/local/php/bin/phpize [iyunv@vbird xcache-3.1.0]# ./configure > --enable-xcache > --with-php-config=/usr/local/php/bin/php-config [iyunv@vbird xcache-3.1.0]# make && make install 来到下面目录下把xcache的扩展模块xcache.so模块拷到php的扩展配置文件/etc/php5.d/下 cd /usr/local/php/lib/php/extensions/no-debug-zts-20121212/ [iyunv@vbird no-debug-zts-20121212]# cp xcache.so /etc/php5.d/ 拷贝xcache的配置模板xcache.ini到php的扩展配置文件/etc/php5.d [iyunv@vbird xcache-3.1.0]# cp xcache.ini /etc/php5.d/
Xcache安装完成后重新启动httpd服务 我们接着来作压力测试看看xcache的效果 对静态页面index.html进行压力测试 可以看到只有每秒1300左右 [iyunv@vbird ~]# ab -n 10000 -c 1000 http://192.168.2.100/index.html
对动态页面index.php进行压力测试 可以看到只有每秒800左右 [iyunv@vbird ~]# ab -n 1000 -c 500 http://192.168.2.100/index.php
可以看到xcache缓存对php站点的响应速度有了很大的提升!
|