本文主要是介绍LAMP组建,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
httpd-2.4.3.tar.bz2 ##它依赖的包有 apr arp-utils pcre-develphp-5.4.8.tar.bz2 ##它依赖的包有 libmcrypt libmcrypt-devel mysql-5.5.28-linux2.6-i686.tar.bz2 ##通用已编译包
1: tar -xvf apr-1.4.6.tar.bz2
2: cd apr-1.4.6
3: ./configure --prefix=/usr/local/apr
4: make && make install
1: cd ..2: cd apr-util-1.4.1
3: ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
4: make && make install
5: cd ..
1: yum -y install pcre-devel
4.编译安装httpd-2.4.3
1: tar -xvf httpd-2.4.3.tar.bz2
2: cd httpd-2.4.3
3: ./configure --prefix=/usr/local/apache \ ##安装目录
4: > --sysconfdir=/etc/httpd \ ##配置文件目录
5: > --enable-so \ ##启用动态库,也就是实现模块的动态加载
6: > --enable-cgi \ ##运行执行cgi程序
7: > --enable-ssl \ ##允许基于ssl加密传输
8: > --enable-rewrite \ ##允许URL地址重写
9: > --with-zlib \ ##支持压缩
10: > --with-pcre \ ##支持perl语言的正则表达式
11: > --with-apr=/usr/local/apr \ ##apr的目录
12: > --with-apr-util=/usr/local/arp-util \ ##apr-util的目录
13: > --enable-mpms-shared=all \ ##实现mpm的动态切换
14: > --with-mpm=event ##默认加载的mpm15:16: make && make install ##编译安装,这的大家懂得吧
1: vi /etc/httpd/httpd.conf ##编辑配置文件
2: #DocumentRoot "/usr/local/apache/htdocs" ##213行,欲建立虚拟主机,注释此行3: Pidfile /var/run/httpd.pid ##214行,不定义pid文件位置容易出错,建议设定
4: Include /etc/httpd/extra/httpd-vhosts.conf ##463左右,启用这行,启用配置virtualhost的配置文件
1: /etc/httpd/extra/httpd-vhosts.conf ##如下所示
2: <VirtualHost *:80>
3: DocumentRoot "/www/laoguang.me/" ##文档目录4: ServerName www.laoguang.me ##域名
5: ErrorLog "/www/logs/error_laoguang.log" ##错误日志6: CustomLog "/www/logs/access_laoguang.log" common ##访问日志7: <Directory /www/laoguang.me> ##2.4必须要求对目录权限进行设置
8: AllowOverride none ##不允许url重写
9: Options none ##不启用所有选项
10: Require all granted ##允许所有
11: </Directory>
12: </VirtualHost>
13: <VirtualHost *:80>
14: DocumentRoot "/www/magedu.com" ##同上15: ServerName www.magedu.com
16: ErrorLog "/www/logs/error_magedu.log"17: CustomLog "/www/logs/access_magedu.log" common18: <Directory /www/magedu.com>
19: AllowOverride none
20: Options none
21: Require all granted
22: </Directory>
23: </VirtualHost>
1: mkdir -pv /www/{laoguang.me,magedu.com,logs}
2: echo "Hello ,I'm LaoGuang" > /www/laoguang.me/index.html3: echo "Hello ,I'm Magedu" > /www/magedu.com/index.html4: chown -R deamon:deamon /www
5: ##启动httpd
6: /etc/local/apache/bin/apachectl start ##没有提示代表一切正常
7: ##修改/etc/hosts文件,建立映射,添加
8: 172.16.1.1 www.laoguang.me ##我的IP是172.16.1.1
9: 172.16.1.1 www.magedu.com
10: ##打开浏览器,或者 elinks www.laoguang.me看看能否正常访问
1: LoadModule ssl_module modules/mod_ssl.so ##126行左右取消注释,启用ssl模块
2: LoadModule socache_shmcb_module modules/mod_socache_shmcb.so ##取消注释,ssl模块依赖
3: include /etc/httpd/extra/httpd-ssl.conf ##480行左右取消注释,启用httpd-ssl配置文件
4: ##修改ssl配置文件,被修改的选项有
5: DocumentRoot "/www/laoguang.me" ##确定文档目录6: ServerName www.laoguang.me:443 ##域名为哪个
7: SSLCertificateFile "/etc/httpd/laoguang.crt" ##证书位置8: SSLCertificateKeyFile "/etc/httpd/laoguang.key" ##私钥位置9: ##添加如下,否则2.4的httpd不让访问
10: <Directory /www/laoguang.me>
11: Options none
12: AllowOverride none
13: Require all granted
14: </Directory>
15:
16: ##建立相应的证书与私钥 看下面链接 11: http://laoguang.blog.51cto.com/6013350/1035608
1: echo "export PATH=$PATH:/usr/local/apache/bin" > /etc/profile.d/httpd.sh ##更新PATH2: vi /etc/man.config ##添加man文档
3: MANPATH=/usr/local/apache/man 48行左右
#!/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/functionsif [ -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.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd}
RETVAL=0start() {echo -n $"Starting $prog: "LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONSRETVAL=$?echo[ $RETVAL = 0 ] && touch ${lockfile}return $RETVAL
}stop() {echo -n $"Stopping $prog: "killproc -p ${pidfile} -d 10 $httpdRETVAL=$?echo[ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}
reload() {echo -n $"Reloading $prog: "if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; thenRETVAL=$?echo $"not reloading due to configuration syntax error"failure $"not reloading $httpd due to configuration syntax error"elsekillproc -p ${pidfile} $httpd -HUPRETVAL=$?fiecho
}# See how we were called.
case "$1" instart)start;;stop)stop;;status)status -p ${pidfile} $httpdRETVAL=$?;;restart)stopstart;;condrestart)if [ -f ${pidfile} ] ; thenstopstartfi;;reload)reload;;graceful|help|configtest|fullstatus)$apachectl $@RETVAL=$?;;*)echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}"exit 1
esacexit $RETVAL而后为此脚本赋予执行权限:
# chmod +x /etc/rc.d/init.d/httpd加入服务列表:
# chkconfig --add httpd接下来就可以启动服务进行测试了。
1: groupadd -r mysql
2: useradd -r -g mysql mysql
1: tar xvf mysql-5.5.28-linux2.6-i686.tar.gz -C /usr/local
2: cd /usr/local
3: ln -sv mysql-5.5.28-linux2.6-i686/ mysql
4: chown -R mysql:mysql mysql
1: mkdir /data
2: chown -R mysql:mysql /data
1: cd /usr/local/mysql
2: ./scripts/mysql_install_db --datadir=/data --user=mysql
3: ## 拷贝控制脚本到/etc/init.d下
4: cp ./support-files/mysql.server /etc/init.d/mysqld
5: ##拷贝配置文件
6: cp ./support-files/my-huge.cnf /etc/my.cnf
7: ##修改my.cnf
8: thread_concurrency=4 ##你的cpu数*2
9: datadir=/data ##添加数据目录
1: ln -sv /usr/local/mysql/include/ /usr/include/mysql ##把头文件链接头文件库
2: echo "/usr/local/mysql/lib" > /etc/ld.so.conf.d/mysql.conf ##把库做一个附属配置文件,开机会自动加载3: ldconfig -v 立刻加载库到缓存
4:
5: echo "export PATH=$PATH:/usr/local/mysql/bin " >/etc/profile.d/mysql.sh ##更新PATH6: vi /etc/man.config ##添加帮助文档
7: MANPATH /usr/local/mysql/man ##48行左右加入
1: chkconfig --add mysqld ##添加到service中
2: chkconfig mysqld on ##添加到开机启动
3: service mysqld start ##现在启动服务
1: rpm -ivh libmcrypt-2.5.7-5.el5.i386.rpm libmcrypt-devel-2.5.7-5.el5.i386.rpm
1: tar -xvf php-5.4.8.tar.bz2
2: cd php-5.4.8
3: ./configure --prefix=/usr/local/php \ ##安装目录你懂得
4: > --with-mysql=/usr/local/mysql \ ##跟mysql整合
5: > --with-openssl \ ##支持ssl
6: > --with-mysqli=/usr/local/mysql/bin/mysql_config \##支持mysqli函数,靠它与mysql交流
7: > --enable-mbstring \ ##支持像中文这样的多字符语言
8: > --with-freetype-dir \ ##这个是关于字体的
9: > --with-jpeg-dir \ ##支持jpeg你懂得
10: > --with-png-dir \ ##支持png你也懂得
11: > --with-zlib \ ##支持压缩库
12: > --with-libxml-dir=/usr \ ##支持xml库
13: > --enable-xml \ ##支持xml
14: > --enable-sockets \ ##支持套接字
15: > --with-apxs2=/usr/local/apache/bin/apxs \ ##这是与apache沟通的选项
16: > --with-mcrypt \ ##支持加密
17: > --with-config-file-path=/etc \ ##配置文件目录
18: > --with-config-file-scan-dir=/etc/php.d \ ##还会扫描的配置文件目录
19: > --with-bz2 \ ##支持bz2
20: > --enable-maintainer-zts ##支持apache的worker或event这两个MPM
1: cp php.ini-production /etc/php.ini ##从安装目录下拷贝到/etc/下
1: DirectoryIndex index.php index.html ##248行左右添加php的主页支持
2: AddType application/x-httpd-php .php ##合适位置添加对php类型文件的支持
1: echo -e "<?php\nphpinfo()\n?>" > /www/laoguang.me/index.html2: mv /www/laoguang.me/index.html /www/laoguang.me/index.php
3:
4: ##访问www.laoguang.me测试运行是否能调用phpinfo()这个函数
如果能运行,php就安装整合完毕了
四:编译安装xcache为php加速 1.编译安装xcache1: tar xf xcache-2.0.0.tar.gz2: cd xcache-2.0.0
3: /usr/local/php/bin/phpize
4: ./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config
5: make && make install
1: ##将xcache提供的样例配置导入php.ini
2: mkdir /etc/php.d
3: cp xcache.ini /etc/php.d
4:
5: ##编辑/etc/php.d/xcache.ini,找到zend_extension开头的行,修改为如下行:
6: zend_extension = /usr/local/php/lib/php/extensions/no-debug-zts-20100525/xcache.so
所有整合完毕了。
这篇关于LAMP组建的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!