标签:lamp
安装过程中所需要的软件:
apr-1.5.1.tar.gz
apr-util-1.5.4.tar.bz2
httpd-2.4.10.tar.bz2
mysql-5.5.33-linux2.6-x86_64.tar.gz
php-5.3.29.tar.bz2
一. 编译安装apache
1. 编译安装apr
# tar zxvf apr-1.5.1.tar.gz # cd apr-1.5.1 # ./configure --prefix=/usr/local/apr # make && make install
2. 编译安装apr-util
# tar jxvf apr-util-1.5.4.tar.bz2 # cd apr-util-1.5.4 # ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr # make && make install
3. 安装依赖性软件
# yum -y install gcc pcre-devel openssl-devel
4. 编译安装httpd
# tar jxvf httpd-2.4.10.tar.bz2 # cd httpd-2.4.10 # ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --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
5. 编写httpd启动脚本/etc/init.d/httpd
# chmod +x httpd # chkconfig --add httpd # chkconfig httpd on # service httpd start
# cat /etc/init.d/httpd #!/bin/bash # # httpd Startup script for the Apache HTTP Server # # chkconfig: - 85 15 # description: Apache is a World Wide Web server. It is 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 will 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 that some modules may not # work correctly with a thread-based MPM; notably PHP will 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/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 10 $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 "$1" 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 $@ RETVAL=$? ;; *) echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}" exit 1 esac exit $RETVAL
二. 编译安装mysql
1. 新建mysql用户
# groupadd -r mysql # useradd -g mysql -r -s /sbin/nologin -M /mysqldata/data mysql # chown -R mysql:mysql /mysqldata/data
2. 安装初始化mysql
# tar zxvf mysql-5.5.33-linux2.6-x86_64.tar.gz # mv mysql-5.5.33-linux2.6-x86_64 /usr/local # ln -sv mysql-5.5.33-linux2.6-x86_64 mysql # cd mysql # scripts/mysql_install_db --user=mysql --datadir=/mysqldata/data # chown -R root .
3. 配置mysql配置文件my.cnf
# cd /usr/local/mysql # cp support-files/my-large.cnf /etc/my.cnf # vim /etc/my.cnf 增加一行: datadir = /mysqldata/data
4. 配置mysqld启动脚本
# cd /usr/local/mysql # cp support-files/mysql.server /etc/init.d/mysqld # chmod +x mysqld # chkconfig --add mysqld # chkconfig mysqld on # service mysqld start
5. 配置mysql库文件查找路径
# vim /etc/ld.so.conf.d/mysql.conf 增加 /usr/local/mysql/lib # ldconfig
6. 配置PATH变量
# vim /etc/profile.d/mysql.sh 增加 PATH=/usr/local/mysql/bin:$PATH # . /etc/profile.d/mysql.sh
三. 编译安装php
1. 安装依赖软件
# yum -y groupinstall "Desktop Platform Development" # yum -y install bzip2-devel libmcrypt-devel # yum -y install libtool libtool-devel libtool-ltdl-devel
2. 编译安装php
编译安装php作为apache的module,php安装成功后会在httpd.conf中增加如下行:
LoadModule php5_module modules/libphp5.so
--with-mysql=/usr/local/mysql
--with-mysqli=/usr/local/mysql/bin/mysql_config表示使用本机Mysql作为后台数据库
# tar jxvf php-5.3.29.tar.bz2 # cd php-5.3.29 # ./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 # make && make install
3. 配置apache支持php
# vim httpd.conf 增加 AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps 修改 DirectoryIndex index.html 修改前 DirectoryIndex index.php index.html 修改后
4. 编写测试文件index.php,测试Php是否能正常使用
<?php $link = mysql_connect(‘127.0.0.1‘,‘root‘,‘mageedu‘); if ($link) echo "Success..."; else echo "Failure..."; mysql_close(); ?>
5. 性能测试
ab -c 1000 -n 10000 http://www.tech.com/index.php This is ApacheBench, Version 2.3 <$Revision: 1604373 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking www.tech.com (be patient) Completed 1000 requests Completed 2000 requests Completed 3000 requests Completed 4000 requests Completed 5000 requests Completed 6000 requests Completed 7000 requests Completed 8000 requests Completed 9000 requests Completed 10000 requests Finished 10000 requests Server Software: Apache/2.4.10 Server Hostname: www.tech.com Server Port: 80 Document Path: /index.php Document Length: 11 bytes Concurrency Level: 1000 Time taken for tests: 13.315 seconds Complete requests: 10000 Failed requests: 0 Total transferred: 1980000 bytes HTML transferred: 110000 bytes Requests per second: 751.04 [#/sec] (mean) Time per request: 1331.480 [ms] (mean) Time per request: 1.331 [ms] (mean, across all concurrent requests) Transfer rate: 145.22 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 2 97 224.8 44 1085 Processing: 11 282 995.7 55 13269 Waiting: 10 273 996.8 47 13269 Total: 31 379 1014.0 106 13305 Percentage of the requests served within a certain time (ms) 50% 106 66% 123 75% 130 80% 139 90% 1114 95% 1619 98% 3096 99% 5748 100% 13305 (longest request)
6. 安装php加速器xcache
# tar zxvf xcache-3.0.4.tar.gz # cd xcache-3.0.4 # /usr/local/php/bin/phpize # ./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config # make && make install 安装完成后最后一行显示: Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-zts-20090626/ # mkdir /etc/php.d # cp xcache.ini /etc/php.d # vim /etc/php.d/xcache.ini 修改extension为 extension = /usr/local/php/lib/php/extensions/no-debug-zts-20090626/xcache.so
7. 安装xcache之后的性能测试:
ab -c 1000 -n 10000 http://www.tech.com/index.php This is ApacheBench, Version 2.3 <$Revision: 1604373 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking www.tech.com (be patient) Completed 1000 requests Completed 2000 requests Completed 3000 requests Completed 4000 requests Completed 5000 requests Completed 6000 requests Completed 7000 requests Completed 8000 requests Completed 9000 requests Completed 10000 requests Finished 10000 requests Server Software: Apache/2.4.10 Server Hostname: www.tech.com Server Port: 80 Document Path: /index.php Document Length: 11 bytes Concurrency Level: 1000 Time taken for tests: 6.630 seconds Complete requests: 10000 Failed requests: 0 Total transferred: 1980000 bytes HTML transferred: 110000 bytes Requests per second: 1508.24 [#/sec] (mean) Time per request: 663.026 [ms] (mean) Time per request: 0.663 [ms] (mean, across all concurrent requests) Transfer rate: 291.63 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 122 283.1 35 1068 Processing: 5 188 544.2 50 5652 Waiting: 4 181 544.7 44 5652 Total: 17 310 660.4 89 5657 Percentage of the requests served within a certain time (ms) 50% 89 66% 115 75% 125 80% 153 90% 1093 95% 1337 98% 2374 99% 3587 100% 5657 (longest request)
二. 编译安装php为独立的服务进程php-fpm
1. 安装依赖软件
# yum -y install bzip2-devel libmcrypt-devel libxml2-config-devel # yum -y install libtool libtool-devel libtool-ltdl-devel
2. 编译安装php
# tar jxvf php-5.3.29.tar.bz2 # cd php-5.3.29 # ./configure --prefix=/usr/local/php --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-openssl --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 # make && make install //--with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd用于配置php通过socket连接非本机mysql数据库
3. 配置php
# cd php-5.3.29 # cp php.ini-production /etc/php.ini # cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm # chmod +x /etc/init.d/php-fpm # chkconfig --add php-fpm # chkconfig php-fpm on # cd /usr/local/php/etc # cp php-fpm.conf.default php-fpm.conf # vim php-fpm.conf 修改 pm.max_children = 50 //设置php-fpm进程最大数为50 pm.start_servers = 5 //设置php-fpm初始进程数为5 pm.min_spare_servers = 2 //设置最小空闲进程数为2 pm.max_spare_servers = 8 //设置最大空闲进程数为8 pid = /usr/local/php/var/run/php-fpm.pid
4. 启动php-fpm进程
# service php-fpm start # ss -tuln | grep 9000 //验证php-fpm tcp LISTEN 0 128 127.0.0.1:9000 *:*
5. 启动httpd的相关模块
//在httpd.conf中配置对于fastcgi的支持 LoadModule proxy_module modules/mod_proxy.so LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
6. 配置虚拟主机支持fcgi
<VirtualHost *:80> ServerAdmin root@localhost DocumentRoot "/usr/local/apache/htdocs/www.dev.com" ServerName www.dev.com ServerAlias dev.com ProxyRequests off //关闭正向代理 ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/ //把以.php结尾的文件请求发送到php-fpm进程 <Directory /usr/local/apache/htdocs/www.dev.com> Options none AllowOverride none Require all granted </Directory> ErrorLog "logs/www.dev.com_error" CustomLog "logs/www.dev.com_access" combined </VirtualHost>
7. 配置httpd.conf,让apache能识别.php文件
# vim httpd.conf 增加两行 AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps 修改 DirectoryIndex index.php index.html
本文出自 “虎虎生威” 博客,请务必保留此出处http://tobeone.blog.51cto.com/817917/1563839
标签:lamp
原文地址:http://tobeone.blog.51cto.com/817917/1563839