适用环境:RHEL5.9/5.10 x86_64
—— 准备工作:
[[email protected]~]# yum -y install openssl-devel
[[email protected]~]# yum -y install ncurses-devel libtermcap-devel
[[email protected]~]# yum -y install libxml2-devel
[[email protected]~]# yum -y remove httpd mysql-server mysql php-mysql
############################### START ######################
1. 编译安装 httpd
1)安装
[[email protected]~]# tar zxf /软件包路径/httpd-2.2.26.tar.gz -C /usr/src/
[[email protected]~]# cd /usr/src/httpd-2.2.26/
[[email protected]]# ./configure --prefix=/usr/local/httpd \
--enable-so --enable-rewrite --enable-cgi \
--enable-charset-lite --enable-ssl \
--enable-suexec \
--with-suexec-caller=daemon \
--with-suexec-docroot=/usr/local/httpd/htdocs
[[email protected]]# make
[[email protected]]# make install
2)建立 httpd 控制脚本(注意添加chkconfig识别参数)
[[email protected]~]# cp -f /usr/local/httpd/bin/apachectl /etc/init.d/httpd
[[email protected]~]# vim /etc/init.d/httpd
#!/bin/bash
#chkconfig: 35 85 15
#description: Apache is a World Wide Web Server
.. ..
[[email protected]~]# chmod +x /etc/init.d/httpd
[[email protected]~]# chkconfig --add httpd
2. 编译安装 mysql (可以与 httpd 安装同时进行)
1)准备mysql运行账户
[[email protected]~]# useradd -M -u 49 -s /sbin/nologin mysql
2)安装
[[email protected]~]# tar zxf /软件包路径/mysql-5.1.62.tar.gz -C /usr/src/
[[email protected]~]# cd /usr/src/mysql-5.1.62/
[[email protected]]# ./configure --prefix=/usr/local/mysql \
--with-charset=utf8 \
--with-collation=utf8_general_ci --with-extra-charsets=gbk,gb2312
[[email protected]]# make
[[email protected]]# make install
[[email protected]]# cd /usr/local/mysql/
[[email protected]]# bin/mysql_install_db --user=mysql
3)调整mysql目录权限
[[email protected]~]# chown -R root:mysql /usr/local/mysql/
[[email protected]~]# chown -R mysql /usr/local/mysql/var/
4)建立my.cnf配置文件
[[email protected]~]# cp -f /usr/local/mysql/share/mysql/my-medium.cnf /etc/my.cnf
[[email protected]~]# vim /etc/my.cnf
#skip-locking
skip-external-locking
.. ..
5)mysql执行优化、添加库路径
[[email protected]~]# ln -sf /usr/local/mysql/bin/* /usr/local/bin/
[[email protected]~]# vim /etc/ld.so.conf.d/mysql-64.conf
/usr/local/mysql/lib/mysql
[[email protected]~]#ldconfig
6)建立 mysqld 服务控制脚本
[[email protected]~]# cp -f /usr/local/mysql/share/mysql/mysql.server /etc/init.d/mysqld
[[email protected]~]# chmod +x /etc/init.d/mysqld
[[email protected]~]# chkconfig --add mysqld
3. 编译安装 php
1)安装
[[email protected]~]# tar zxf /软件包路径/php-5.4.24.tar.gz -C /usr/src/
[[email protected]~]# cd /usr/src/php-5.4.24/
[[email protected]]# ./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
[[email protected]]# make
[[email protected]]# make install
2)启用httpd的PHP网页支持
[[email protected]~]# vim /usr/local/httpd/conf/httpd.conf
.. ..
LoadModule php5_module modules/libphp5.so
<IfModuledir_module>
DirectoryIndex index.html index.php
</IfModule>
AddType application/x-httpd-php .php
.. ..
4. 启动LAMP平台、测试
[[email protected]~]# service mysqld restart
[[email protected]~]# service httpd restart
[[email protected]~]# vim /usr/local/httpd/htdocs/test2.php
<?php
$link=mysql_connect(‘localhost‘,‘root‘,‘1234567‘);
if($link) echo "Success !!";
else echo "Failure !!";
mysql_close();
?>
从浏览器访问http://服务器地址/test2.php,应显示“Success!!”
############################### END ######################################