平台是linux as4 + httpd-2.2.8 + mysql-5.0.22 + php-5.2.6
首先准备安装包httpd-2.2.8.tar.gz,mysql-5.0.22.tar.gz,php-5.2.6.tar.gz。这些包可以到官方网站上自行下载,都是免费的。把它们放到/usr/localsrc目录下解压。/usr/local/src是放置源码的目录,一般情况下人们都习惯把源码文件放到这里。
1.Mysql的安装
进雖ysql解压的源码文件目录
./configure --prefix=/usr/local/mysql
make && make install
配置mysql
groupadd mysql
useradd -g mysql mysql
cd /usr/local/mysql/
chown -R mysql .
chgrp -R mysql .
cd /usr/local/src/mysql-5.0.22/support-files
cp my-medium.cnf /etc/my.cnf
cd /usr/local/mysql/bin
./mysql_install_db --user=mysql
cd /usr/local/mysql
chown -R mysql:mysql var
chmod 755 var
cd /usr/local/mysql/bin
./mysqld_safe --user=mysql &
netstat -ant | grep 3306
mysqladmin -u root password 'admin'
cd /usr/local/src/mysql-5.0.22/support-files/
cp mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
service mysqld restart
测试mysql:
cd /usr/local/mysql/bin
mysql -u root -p
show databases;
2.Apache的安装
首先检查是否安装了linux自带的apache,若果有将其卸载。
命令:rpm -qa|grep httpd
进入Apache解压的源码目录
./configure --prefix=/usr/local/httpd --with-mysql=/usr/local/mysql/ --enable-module=so --enable-mods-shared=max
make && make install
cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd
把# chkconfig: - 85 15
这些内容拷贝到/etc/init.d/httpd文件#!/bin/bash下面行。
想让服务支持chkconfig工具必须在脚本里有chkconfig和description相关内容的描述。
想了解chkconfig更多信息可参看man文档说明。
chkconfig --add httpd
chkconfig httpd on
service httpd start
netstart -ant | grep :80
配置Apache
vi /usr/local/httpd/conf/httpd.conf
取消ServerName前的#,添加ip或是域名及端口。
例:ServerName 192.168.0.11:80
测试APache:
用浏览器输入自己的ip及端口进行测试。
例:浏览器中输入:http://192.168.0.11:80
3.Php安装
进入php解压的源码文件目录
./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-apxs2=/usr/local/httpd/bin/apxs --with-apxs2=/usr/local/httpd/bin/apxs
make && make install
cp php.ini-dist /usr/local/lib/php.ini
vi /etc/httpd/httpd.conf
找到“#AddType application/x-gzip .gz .tgz”
并在后面加入
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
这两行的目的是让apache识别php。
再找到“DirectoryIndex index.html”
加上index.php 让它把index.php做为默认页
测试环境:
cd /usr/local/httpd/htdocs/
# vi /usr/local/httpd/htdocs/index.php
输入:
<?
?>
# service httpd restart 重启apache服务器
例:浏览器中输入:http://192.168.0.11/index.php测试一下。如果成功会有相关的php的说明,没成功会提示你保存文件内容。