centos 5.9 --2.6.18-348.el5 x86_64 x86_64 x86_64 GNU/Linux 下编译安装lamp(apache/ 2.4.4;mysql5.6.10-x86;php-5.4.12)
今天公司交给我一台新的服务器(华为 tecal RH 1280) 及时这个服务器,华为已官网不在服务了,但是还是一台不错的机器(比我现在那几台好多了)
一、前期准备工作
这里我把所有的软件都放到 /opt 目录 所需软件有:
1. apr-1.4.6.tar.gz
2. apr-util-1.5.1.tar.gz
3. httpd-2.4.4.tar.gz
4.
mysql-5.6.10-linux-glibc2.5-x86_64.tar.gz
5. php-5.4.12.tar.gz
6. freetype-2.4.11.tar.gz
7. libpng-1.6.0.tar.gz
8. jpegsrc.v9.tar.gz
9. gd-2.0.33.tar.gz
软件包下载地址:
软件包下载地址
:
1. http://labs.mop.com/apache-mirror/apr/apr-1.4.6.tar.gz
2. http://labs.mop.com/apache-mirror/apr/apr-util-1.5.1.tar.gz
3. http://labs.mop.com/apache-mirror/httpd/httpd-2.4.4.tar.gz
4. http://cn2.php.net/distributions/php-5.4.12.tar.gz
5. http://sourceforge.net/projects/mysql.mirror/files/MySQL%205.6.10/mysql-5.6.10-linux-glibc2.5-x86_64.tar.gz/download
6. http://down1.chinaunix.net/distfiles/gd-2.0.33.tar.gz
7. http://jaist.dl.sourceforge.net/project/freetype/freetype2/2.4.11/freetype-2.4.11.tar.gz
8. http://sourceforge.net/projects/libpng/files/libpng16/older-releases/1.6.0/libpng-1.6.0.tar.gz/download
9. http://www.ijg.org/files/jpegsrc.v9.tar.gz
移除系统自带的rpm包的http mysql php
# yum remove httpd mysql mysql-server php php-cli php-common php-devel php-gd -y
安装下开发环境工具包
#yum groupinstall 'Development Libraries' 'Development Tools' 'X Software Development' -y
二、编译安装环境
1. # tar xf apr-1.4.6.tar.gz
#cd apr-1.4.6
#./configure --prefix=/usr/local/apr \\指定安装目录
# make && make install
2. #tar xf apr-util-1.5.1tar.gz
#cd apr-util
#./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
# make&& make install
3. #yum install pcre-devel -y
4.编译安装apache
1. # tar xf httpd-2.4.4.tar.gz
2. # cd httpd-2.4.4
3. # ./configure
--prefix=/usr/local/apache \ \\指定安装目录
4. --sysconfdir=/etc/httpd \
\\配置文件目录
5. --enable-so --enable-ssl \
\\基于ssl的加密传输
6. --enable-cgi \
7. --enable-rewrite \
\\允许URL地址重写
8. --with-zlib \
\\支持压缩
9. --with-pcre \
\\支持perl的正则表达式
10.--with-apr=/usr/local/apr \
11.--with-apr-util=/usr/local/apr-util \
\\关联apr-util的目录
12.--enable-mpms-shared=all \
\\实现mpm的动态切换
13.--with-mpm=event
\\默认加载的mpm
14.# make && make install
apache
的便宜选项比较多,可以使用configure --help命令查看所支持的编译选项及简要说明: 这里需要说明一点:这样直接编译后可能出现问题----403 错误,主页访问不了(index.php)
autoindex:error] [pid 5933:tid 46940440824128] [client 222.85.68.134:3186] AH01276: Cannot serve directory /home/djweb/home/web/: No
matching DirectoryIndex (none) found, and server-generated directory index forbidden by Options directive =-----------------解决办法:1:apache 配置文件下面是否开启 LoadModule dir_module modules/mod_dir.so #php -v 然后重启下服务,如果还不可以,则需要重新编译apache (卸载系统自带的apr apr-until)。
1. #!/bin/bash
2. #
3. # httpd Startup script for the Apache HTTP Server
4. #
5. # chkconfig: - 85 15
6. # description: Apache is a World Wide Web server. It is used to serve \
7. # HTML files and CGI.
8. # processname: httpd
9. # config: /etc/httpd/conf/httpd.conf
10.# config: /etc/sysconfig/httpd
11.# pidfile: /var/run/httpd.pid
12.
13.# Source function library.
14.. /etc/rc.d/init.d/functions
15.
16.if [ -f /etc/sysconfig/httpd ]; then
17. . /etc/sysconfig/httpd
18.fi
19.
20.# Start httpd in the C locale by default.
21.HTTPD_LANG=${HTTPD_LANG-"C"}
22.
23.# This will prevent initlog from swallowing up a pass-phrase prompt if
24.# mod_ssl needs a pass-phrase from the user.
25.INITLOG_ARGS=""
26.
27.# Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server
28.# with the thread-based "worker" MPM; BE WARNED that some modules may not
29.# work correctly with a thread-based MPM; notably PHP will refuse to start.
30.
31.# Path to the apachectl script, server binary, and short-form for messages.
32.apachectl=/usr/local/apache/bin/apachectl
33.httpd=${HTTPD-/usr/local/apache/bin/httpd}
34.prog=httpd
35.pidfile=${PIDFILE-/var/run/httpd.pid}
36.lockfile=${LOCKFILE-/var/lock/subsys/httpd}
37.RETVAL=0
38.
39.start() {
40. echo -n $"Starting $prog: "
41. LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
42. RETVAL=$?
43. echo
44. [ $RETVAL = 0 ] && touch ${lockfile}
45. return $RETVAL
46.}
47.
48.stop() {
49.echo -n $"Stopping $prog: "
50.
killproc $httpd
51.
RETVAL=$?
52.
echo
53.
[ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
54.}
55.reload() {
56. echo -n $"Reloading $prog: "
57. if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then
58. RETVAL=$?
59. echo $"not reloading due to configuration syntax error"
60. failure $"not reloading $httpd due to configuration syntax error"
61. else
62. killproc -p ${pidfile} $httpd -HUP
63. RETVAL=$?
64. fi
65. echo
66.}
67.
68.# See how we were called.
69.case "$1" in
70. start)
71.start
72.;;
73. stop)
74.stop
75.;;
76. status)
77. status -p ${pidfile} $httpd
78.RETVAL=$?
79.;;
80. restart)
81.stop
82.start
83.;;
84. condrestart)
85.if [ -f ${pidfile} ] ; then
86.stop
87.start
88.fi
89.;;
90. reload)
91. reload
92.;;
93. graceful|help|configtest|fullstatus)
94.$apachectl $@
95.RETVAL=$?
96.;;
97. *)
98.echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}"
99.exit 1
100. esac
101.
exit $RETVAL 给予脚本执行权限;
# chmod +x /etc/rc.d/init.d/httpd
加入服务列表:
# chkconfig --add httpd
为了方便更新
PATH,省的每次都绝对路径启动服务,并添加帮助文档
1. #echo "export PATH=$PATH:/usr/local/apache/bin" > /etc/profile.d/httpd.sh //添加PATH路径
2. # source /etc/profile.d/httpd.sh
//重读配置文件
#vi /etc/man.config //添加man文档
三、安装下mysql
新建用户安全运行程序
1. # groupadd -r mysql
2. # useradd -g mysql -r -s /sbin/nologin -M -d /usr/local/data mysql
3. # chown -R mysql:mysql /mydata/data
1. # tar xf
mysql-5.6.10-linux-glibc2.5-x86_64.tar.gz -C /usr/local
2. # cd /usr/local/
3. # ln -sv
mysql-5.6.10-linux-glibc2.5-x86_ mysql
4. # cd mysql
5. # chown -R mysql:mysql .
6. # scripts/mysql_install_db --user=mysql --datadir=/usr/local/data
7. # chown -R root .
4、为
mysql提供主配置文件:
1. # cd /usr/local/mysql
2. # cp support-files/my-default.cnf /etc/my.cnf
需要添加如下行指定
mysql数据文件的存放位置:
datadir = /mydata/data
5、为
mysql提供sysv服务脚本
1. # cd /usr/local/mysql
2. # cp support-files/mysql.server /etc/rc.d/init.d/mysqld
3. # chmod +x /etc/rc.d/init.d/mysqld
添加至服务列表:
1. # chkconfig --add mysqld
2. # chkconfig mysqld on
而后就可以启动服务测试使用了。
为了使用
mysql的安装符合系统使用规范,并将其开发组件导出给系统使用,这里还需要进行如下步骤:
6、输出
mysql的man手册至man命令的查找路径:
编辑
/etc/man.config,添加如下行即可:
MANPATH /usr/local/mysql/man
7、输出
mysql的头文件至系统头文件路径/usr/include:
这可以通过简单的创建链接实现:
1. # ln -sv /usr/local/mysql/include /usr/include/mysql
8、输出
mysql的库文件给系统库查找路径:
1. # echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
而后让系统重新载入系统库:
# ldconfig
9、修改
PATH环境变量,让系统可以直接使用mysql的相关命令。
1. #echo "export PATH=$PATH:/usr/local/mysql/bin " >/etc/profile.d/mysql.sh
2. #source /etc/profile.d/mysql.sh
四、编译php-5.4.12
1、解决依赖关系:
如果想让编译的
php支持mcrypt扩展,此处还需要下载如下两个rpm包并安装之,这里我直接使用已配置好的yum源进行安装。
libmcrypt-2.5.7-5.el5.i386.rpm
libmcrypt-devel-2.5.7-5.el5.i386.rpm
1. #yum -y install libmcrypt libmcrypt-devel
2、安装
libpng
1. # tar zxvf libpng-1.4.2.tar.tar
2. # cd libpng-1.4.2
3. # ./configure
4. # make && make install
3、安装
freetype
1. # tar zxvf freetype-2.4.11.tar.gz
2. # cd freetype-2.4.11
3. # ./configure
4. # make && make install
4、安装
Jpeg
1. # tar zxvf jpegsrc.v9.tar.gz
2. # cd jpeg-9/
3. # ./configure --enable-shared
4. # make
5. # make test
6. # make install
注意,这里
configure一定要带--enable-shared参数,不然,不会生成共享库.
5、安装
gd库支持
由于许多
php网站程序都需要gd库的支持,在编译php之前要先安装该组件以方便以后的使用。
1. # tar zxvf gd-2.0.33.tar.gz
2. # cd gd-2.0.33
3. # ./configure --with-png --with-freetype --with-jpeg
4. # make && make install
6、编译安装
php-5.4.12
1. # tar xf php-5.4.12.tar.gz
2. # cd php-5.4.12
3. # ./configure --prefix=/usr/local/php \
//安装目录
4. --with-mysql=/usr/local/data\
//指定
mysql目录
5. --with-openssl \
//支持
ssl
6. --with-mysqli=/usr/local/mysql/bin/mysql_config \ //支持
mysqli函数
7. --enable-mbstring \
//支持多字符语言
8. --with-gd
9. --with-freetype-dir=/usr/local/include/freetype2/freetype \
10.--with-jpeg-dir=/usr/local/include \
//支持
jpeg
11.--with-png-dir=/usr/local/include/libpng16 \
//支持
png
12.--with-gettext \
13.--enable-bcmath \
14. --with-zlib \
//支持压缩库
15. --with-libxml-dir=/usr \
//支持
xml库
16. --enable-xml \
//支持
xml
17. --enable-sockets \
//支持套接字
18. --with-apxs2=/usr/local/apache/bin/apxs \
//与
Apache的连接
19. --with-mcrypt \
//支持加密
20. --with-config-file-path=/etc \
//配置文件目录
21. --with-config-file-scan-dir=/etc/php.d \
//额外会扫描的配置文件目录
22. --with-bz2 \
//支持
bz2
23.--enable-maintainer-zts
//支持
apache的worker或event这两个MPM
说明:这里为了支持
apache的worker或event这两个MPM,编译时使用了--enable-maintainer-zts选项。
1. make
2. # make test
3. # make intall
为
php提供配置文件:
1. # cp php.ini-production /etc/php.ini
7、 编辑
apache配置文件httpd.conf,以apache支持php
1. # 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
添加
index.php为默认主页
15.修改httpd的主配置文件,设置其Pid文件的路径
编辑
/etc/httpd/httpd.conf,添加如下行即可:
PidFile "/var/run/httpd.pid" 16.提供sysv 服务脚本/etc/rc.d/init.d/httpd
本文出自 “My life enjoy life” 博客,转载请与作者联系!