安装环境:
系统:CentOS release 6.2 (Final)
Mysql: mysql-5.1.62.tar.gz
http:httpd-2.2.25.tar.gz
php: php-5.4.19.tar.gz
前期准备:先将需要的软件包拖到虚拟服务器root上,如下图
[root@localhost ~]# unzip LAMP.zip
[root@localhost ~]# yum -y install openssl-devel ncurses-devel libtermcap-devel libxml2-devel gcc gcc-c++
[root@localhost ~]# yum -y remove httpd mysql-server mysql php-mysql
1. 安装 httpd源码包
[root@localhost ~]# tar -zxvf httpd-2.2.25.tar.gz
[root@localhost ~]# cd httpd-2.2.25
[root@localhost httpd-2.2.25]#./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
[root@localhost httpd-2.2.25]# make && make intsall
建立 httpd 控制脚本,添加启动参数
[root@localhost httpd-2.2.25]# cp -f /usr/local/httpd/bin/apachectl /etc/init.d/httpd
[root@localhost httpd-2.2.25]# vim /etc/init.d/httpd
#!/bin/bash
# chkconfig: 35 85 15
# description: Apache is a World Wide Web Server
......
[root@localhost httpd-2.2.25]# chmod +x /etc/init.d/httpd
[root@localhost httpd-2.2.25]# chkconfig --add httpd
2. 安装 mysql源码包
准备mysql运行账户(不创建家目录 uid为49 不能登录),安装
[root@localhost httpd-2.2.25]# useradd -M -u 49 -s /sbin/nologin mysql
[root@localhost httpd-2.2.25]# cd /root
[root@localhost]# tar -zxvf mysql-5.1.62.tar.gz
[root@localhost]# cd /mysql-5.1.62/
[root@localhost mysql-5.1.62]# ./configure --prefix=/usr/local/mysql \
--with-charset=utf8 --with-collation=utf8_general_ci --with-extra-charset=gbk,gb2312
[root@localhost mysql-5.1.62]# make && make install
调整目录权限,建立mysql配置文件
[root@localhost mysql-5.1.62]#chown -R root:mysql /usr/local/mysql/
[root@localhost mysql-5.1.62]#chown -R mysql /usr/local/mysql/var/#若无此目录需自行创建mkdir
[root@localhost mysql-5.1.62]#cp -f /usr/local/mysql/share/mysql/my-medium.cnf /etc/my.cnf
[root@localhost mysql-5.1.62]# vim /etc/my.cnf
[mysqld]
port = 3306
socket = /tmp/mysql.sock
skip-locking
key_buffer_size = 16M
......
添加库链接,建立 mysqld控制脚本,添加启动参数
[root@localhost mysql-5.1.62]# ln -sf /usr/local/mysql/bin/* /usr/local/bin/
[root@localhost mysql-5.1.62]# cat /etc/ld.so.conf.d/mysql-64.conf
/usr/local/mysql/lib/mysql
[root@localhost mysql-5.1.62]# ldconfig
[root@localhost mysql-5.1.62]#cp -f /usr/local/mysql/share/mysql/mysql.server /etc/init.d/mysqld
[root@localhost mysql-5.1.62]#chmod +x /etc/init.d/mysqld
[root@localhost mysql-5.1.62]#chkconfig --add mysqld
[root@localhost mysql-5.1.62]# /usr/local/mysql/bin/mysql_install_db --user=mysql
3. 编译安装 php
[root@localhost mysql-5.1.62]# cd /root/
[root@localhost ~]# tar -zxvf php-5.4.19.tar.gz
[root@localhost ~]#cd php-5.4.19
[root@localhost 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
[root@localhost php-5.4.19]# make && make install
启用httpd的PHP网页支持
[root@localhost php-5.4.19]# vim /usr/local/httpd/conf/httpd.conf
......
54 LoadModule php5_module modules/libphp5.so
......
99 ServerName localhost:80
......
167 <IfModule dir_module>
168 DirectoryIndex index.html index.php
169 </IfModule>
......
309 AddType application/x-compress .Z
310 AddType application/x-gzip .gz .tgz
311 AddType application/x-httpd-php .php
......
启动mysql 和httpd
[root@localhost php-5.4.19]# service mysqld restart
[root@localhost php-5.4.19]# service httpd restart
修改mysql密码,创建mysql数据库
[root@localhost php-5.4.19]# mysql -u root
mysql> SET PASSWORD FOR 'root'@'localhost'=PASSWORD('123456');
mysql> CREATE DATABASE bbsdb;
mysql> GRANT all ON bbsdb.* TO runbbs@localhost IDENTIFIED BY 'admin123';
mysql> quit;
4. 创建测试网页,测试访问结果
1. 确保能正确解析 PHP 网页
[root@localhost php-5.4.19]# vim /usr/local/httpd/htdocs/test1.php
<?php
phpinfo();
?>
—— 从浏览器访问 http://服务器地址/test1.php
2. 确保PHP网页可访问 MySQL 数据库
[root@localhost php-5.4.19]# vim /usr/local/httpd/htdocs/test2.php
<?php
$link=mysql_connect('localhost','root','123456');
if($link) echo "Success !!"; //成功则显示Success !!
else echo "Failure !!"; //失败则显示Failure !!
mysql_close(); //关闭数据库连接
?>
—— 从浏览器访问 http://服务器地址/test2.php