最近在学习重要的Web服务,当然也就少不了很重要的httpd和php.而动态网站必定又会使用数据库如mysql之类的,那么,今天就总结一下最近做的LAMP平台编译实验。具体过程如下。
实验名:在CentOS6上使用源码编译LAMP平台
实验环境:CentOS6.5,安装时选择了使用最多的两个开发包组。
使用系统默认基本yum源+epel6源(aliyun: http://mirrors.aliyun.com/repo/epel-6.repo )
使用源码包:httpd-2.4.9 ;二进制安装包mysql-5.5.33 ;php-5.4.26
实验步骤:
一.安装httpd服务
1.安装httpd的依赖软件包。
安装apr-1.5.0
# tar xf apr-1.5.0.tar.bz2
# cd apr-1.5.0
# ./configure --prefix=/usr/local/apr
# make && make install
安装apr-util-1.5.3
# tar xf apr-util-1.5.3.tar.bz2
# cd apr-util-1.5.3
# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
# make && make install
若httpd有可能要支持ssl请要安装openssl及openssl-devel.另,若有安装,请查看是否这两个包有 更新过。
另编译过程中也会使用pcre,请在编译httpd前安装,系统安装盘是有这个包的。
2.接着就是解压httpd的源码包并安装了,使用如下命令:
# tar xf httpd-2.4.9.tar.bz2
# cd httpd-2.4.9
# ./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
说一下./configure里面的参数吧。
第一个参数--prefix是设定安装目录的;
第二个是服务的配置文件存放目录;
第三个是开启动态模块的选项;
第四个是编译并启用ssl模块;
第五个是启用CGI功能;
第六个是rewrite;
第七个是编译数据压缩相关模块;
第八个是使用pcre,这个一个perl的正则匹配类的函数库;
第九个是指明apr的路径;
第十个指明apr-utin的路径;
第十一个是编译最多的模块;
第十二个是构建mpm为动态模块并编译所有支持的模式;
第十三个是指明默认mpm模块为event事件处理方式。
注:最后两个选项很重要,不太明白请搜索关键字“构建MPM模块”
3.好了,一会后,检查发现没有问题,就make && make install安装吧。
。。。。。一会就安装好了。
4.接着,修改主配置文件中的Pid文件路径。
5.编辑/etc/httpd/httpd.conf,添加如下行即可:
PidFile "/var/run/httpd.pid"
6.最后,是提供SysV脚本,以方便我们管理服务。
编辑一个/etc/rc.d/init.d/httpd ,将以下内容放进去并保存就好了。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/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.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
7.添加脚本的执行权限后(# chmod +x /etc/rc.d/init.d/httpd)。最后,是不是应该把这个服务加入系统开机启动中呢,明显是必须的嘛。
# chkconfig --add httpd
8.这就是安好apache了哈,不过测试访问前请记得关掉或放行iptables哦。
我来测试一下。
再接再厉,我们接着装第二个,mysql服务。
安装前先准备好数据存放的目录和服务运行的用户。设置目录是为了方便以后数据库的数据管理哈,设置用户是为了安全。
#mkdir -pv /mydata/data
#groupadd -r mysql
#useradd -g mysql -r -s /sbin/nologin -M -d /mydata/data mysql
#chown -R mysql:mysql /mydata/data
2.解压下载好的二进制安装包并初始化mysql,千万千万要下对版本,我就下错版本白忙了3个小时。
#tar xf mysql-5.5.33-linux2.6-i686.tar.gz -C /usr/local
#cd /usr/local/
#ln -sv mysql-5.5.33-linux2.6-i686 mysql
#cd mysql
#chown -R mysql:mysql .
#scripts/mysql_install_db --user=mysql --datadir=/mydata/data
#chown -R root .
3.为Mysql提供主配置文件
方法是把解压目录下的样例配置文件拷贝并修改。
#cd /usr/local/mysql
#cp support-files/my-large.cnf /etc/my.cnf
修改my.cnf文件中的thread_concurrency的值为你的CPU个数乘以2(此值是mysql运行使用的系统CPU资源设定),并添加datadir = /mydata/data,这就是设置我们第一步新建的数据目录了。
4.然后当然也是提供SysV脚本了
不过这一次我们不用建文件,直接有样例,拷贝就好。
#cd /usr/local/mysql
#cp support-files/mysql.server /etc/rc.d/init.d/mysqld
#chmod +x /etc/rc.d/init.d/mysqld
5.同样的加入系统启动服务
#chkconfig --add mysqld
#chkconfig mysqld on
然后我们就可以启动了。#service mysqld start
6.输出mysql的man手册至man命令的查找路径
编辑/etc/man.config,添加 MANPATH /usr/local/mysql/man
7.输出mysql的头文件至系统头文件路径/usr/include
通过简单的创建链接实现:
#ln -sv /usr/local/mysql/include /usr/include/mysql
8.输出mysql的库文件给系统库查找路径
# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
系统重载系统库 # ldconfig
9.修改系统PATH变量。修改/etc/profile或~/.profile或/etc/bashrc或~/.bashrc
这样就完成了mysql的安装了。
三.php的安装
安装依赖软件包。
若没有安装两个开发包,请先安装。
另外要安装bzip2-devel及libmcrypt-devel,后一个是epel的软件包哈。
#yum -y install bzip2-devel libmcrypt-devel
解压编译安装php-5.4.26
#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
同样的解释一下./configure的参数。
第一个是安装的目录
第二个是使用mysql
第三个是使用openssl
第四个是使用mysqli这种方式连接mysql
第五个是不同语言的编码(如ISO-8859,utf-8等等)能够正常转换的函数库
第六个是用于显示各种各样的字体的
第七、八个分别是激活对jpeg、png的支持
第九个说过了
第十个、十一个是对xml的支持
第十二个是开启sockets
第十三个是对apache扩展模块的支持
第十四个是支持加密
第十五、十六个是配置文件目录和扩展配置文件所在目录
第十七个是支持压缩传输
第十八个是支持apache的多种MPM
检查通过我们就make && make install吧。
3.为php提供配置文件:
#cp php.ini-production /etc/php.ini
4.编辑apache配置文件httpd.conf,以apache支持php
# vim /etc/httpd/httpd.conf
添加如下二行
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
定位至DirectoryIndex index.html
修改为:
DirectoryIndex index.php index.html
好了,这样基本也就配置完成LAMP了,试试结果。
先提供测试页面。
#vim /usr/local/apache/htdocs/index.php
写入
$link = mysql_connect('127.0.0.1','root','');
if ($link)
echo "Success...";
else
echo "Failure...";
mysql_close();
?>
保存退出。
嗯,测试之前别忘了,刚才改过apache的配置文件,要重启一下httpd哈。
#service httpd restart
看一下测试结果。
作为linux最常用的平台,我会多练N次直到我能不看文档就能熟练安装的,请各位同仁也加油吧
运维网声明
1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网 享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com