一,编译安装httpd
1.安装软件包
# tar zxf httpd-2.2.25.tar.gz
# cd httpd-2.2.25
# ./configure --prefix=/usr/local/httpd --enable-so --enable-rewrite --enable-cgi --enable-ssl --enable-charset-lite
配置参数用途:
--prefix=:指定安装目录
--enable-so:支持动态加载模块
--enable-rewrite :支持网站地址重写
--enable-cgi:支持CGI程序脚本
--enable-ssl:支持SSL加密
--enable-charset-lite:支持多语言编码
配置错误提示:
no SSL-C headers found
configure: error: ...No recognized SSL/TLS toolkit detected
安装相应库文件
# yum -y install openssl-devel
# ./configure --prefix=/usr/local/httpd --enable-so --enable-rewrite --enable-cgi --enable-ssl --enable-charset-lite
# make && make install
2.建立服务脚本
# cd /usr/local/httpd/bin/
# cp apachectl /etc/init.d/httpd
# vim /etc/init.d/httpd
#!/bin/sh
# chkconfig: 2345 85 35
# description:Apache is a world wide web server
……
# chkconfig --add httpd
# chkconfig --list httpd
httpd 0:off1:off2:on3:on4:on5:on6:off
3.修改主配置文件及启动服务
# vim /usr/local/httpd/conf/httpd.conf
ServerName www.jinjianjun.com:80
# service httpd start
[root@client bin]# netstat -ln | grep :80
tcp 0 0 :::80 :::* LISTEN
二.编译安装mysql
1. 添加运行用户
# useradd -M -u 49 -s /sbin/nologin mysql
2.安装软件包
# tar zxf mysql-5.1.62.tar.gz
# cd mysql-5.1.62
# ./configure --prefix=/usr/local/mysql --with-charset=utf8 --with-collation=utf8_general_ci --with-extra-charsets=gbk,gb2312
配置参数用途:
--prefix=:指定安装目录
--with-charset=utf8:指定默认字符集
--with-collation=utf8_general_ci:指定默认的校对规则集
--with-extra-charsets=gbk,gb2312:设置支持的其他字符集
配置错误信息:
checking for termcap functions library... configure: error: No curses/termcap library found
安装库文件
# yum -y install ncurses-devel libtermcap-devel
# ./configure --prefix=/usr/local/mysql --with-charset=utf8 --with-collation=utf8_general_ci --with-extra-charsets=gbk,gb2312
# make && make install
编译错误信息:
../depcomp: line 571: exec: g++: not found
make[1]: *** [my_new.o] Error 127
make[1]: Leaving directory `/root/Desktop/mysql-5.1.62/mysys'
make: *** [all-recursive] Error 1
# yum -y install gcc gcc-c++ //需要安装软件
再重新配置编译安装
3.初始化设置
# cd mysql-5.1.62/support-files/
# cp my-medium.cnf /etc/my.cnf //复制样本配置文件
# cd /usr/local/mysql/bin/
# ./mysql_install_db --user=mysql //初始化库表
4.权限调整及执行优化
# chown -R root:mysql /usr/local/mysql/
# chown -R mysql /usr/local/mysql/var/ //使用户mysql有权写库
# ln -s /usr/local/mysql/bin/* /usr/local/bin/ //建程序快捷方式
# ln -s /usr/local/mysql/lib/mysql/* /usr/lib64/ //链接库文件
# ln -s /usr/local/mysql/include/mysql/* /usr/include/ //链接头文件
5.添加为系统服务,并启动服务
# cd mysql-5.1.62/support-files/
# cp mysql.server /etc/init.d/mysqld //复***务脚本
# chmod +x /etc/rc.d/init.d/mysqld
# chkconfig --add mysqld
# service mysqld start
//如果启动失败,先killall -9 mysqld,再service mysqld restart
三.编译安装php
1.安装软件包
# yum -y install libxml2-devel //配置需要这个库文件
# tar zxf php-5.4.19.tar.gz
# cd /usr/src/php-5.4.19/
# ./configure \
--prefix=/usr/local/php --enable-mbstring --enable-sockets \
--with-apxs2=/usr/local/httpd/bin/apxs \
--with-mysql=/usr/local/mysql \
--with-config-file-path=/usr/local/php
关键配置参数
--prefix=:指定安装目录
--enable-mbstring:支持多字节字符
--with-apxs2:指定httpd的模块工具位置
--with-mysql:指定mysql的安装位置
--enable-sockets:启用套接字支持
--with-config-file-path=:指定配置路径
# make
# make install
2)调整配置文件(可选)
# cp php.ini-development /usr/local/php/php.ini
# vim /usr/local/php/php.ini
.. ..
default_charset = "UTF-8" //默认字符集
file_uploads = On //允许上传
upload_max_filesize = 4M //可上传的最大文件
post_max_size = 8M //最大POST提交的容量
3.LAMP协作配置
# vim /usr/local/httpd/conf/httpd.conf
.. ..
LoadModule php5_module modules/libphp5.so
DirectoryIndex index.html index.php //添加PHP首页
AddType application/x-httpd-php .php //识别PHP网页类型
.. ..
# service httpd restart
# service mysqld restart
4.制作测试网页,测试LAMP协作
测试PHP解析(访问http://IP地址/test1.php)
# vim /usr/local/httpd/htdocs/test1.php //
<?php
phpinfo();
?>
测试数据库连接(访问http://IP地址/test2.php)
# vim /usr/local/httpd/htdocs/test2.php
<?php
$link=mysql_connect('localhost','test',''); //连数据库
if($link) echo "恭喜你,数据库连接成功啦 !!"; //成功时的提示
mysql_close(); //关数据库
?>