【IT168 服务器学院】前前后后查了2,3天的资料,把我搞的很惨,但是终于还是把它征服了^_^,乘空赶快把它整理整理。由于我的linux系统是最小化安装,所以你必须要安装gcc编译器,才能正常安装tar包。gcc编译器在linux自带的第一张光盘里有,按顺序安装下面的rpm包(你可以用tab键自动补全):
binutils
cpp
glibc-kernheaders
glibc-devel
gcc(这个是在第二张)
这几个装好之后要继续装这几个rpm包,它们在第二张盘里都可以找的到。不然在安装过程中还是会出错的:
libtermcap-devel-2.0.8-35.i386.rpm
gcc-c++-3.2.2-5.i386.rpm #这2个是安装mysql时必须的
bison-1.35-6.i386.rpm
flex-2.5.4a-29.i386.rpm
zlib-devel-1.1.4-8.i386.rpm #这3个是安装php是必须的
好的,这可以说是准备工作了,下面进入真正的实战啦:
关于这3款软件的下载你可以去他们的官方网下载
mysql:http://www.mysql.org/
http://www.apache.org/
http://www.php.net/
一、先安装最简单的mysql
1 mysql的官方网站建议在目前的版本中,最好直接以它们编译好的mysql的binary版本来进行安装,(因为在使用tarball的方式来编译,如果你的gcc版本高于2.96时,那么编译出来的mysql程序很有可能会有数据库突然死掉的情况发生)这样就变得很简单了。
把下载来的tar包都放在/usr/local/src(这样可以方便集中管理)
[root@weiming root]# groupadd mysql
[root@weiming root]# useradd -g mysql mysql #创建mysql组和mysql用户,这很重要哦。
[root@weiming root]# cd /usr/local
[root@weiming local]# tar -zxvf /usr/local/src/mysql-3.23.57-pc-linux-i686.tar.gz
[root@weiming local]# ln -s mysql-3.23.57-pc-linux-i686 mysql
[root@weiming local]# cd mysql
[root@weiming mysql]# scripts/mysql_install_db
#这个步骤会在/usr/local/mysql/data里建立好mysql数据库
[root@weiming mysql]# chown -R root .
[root@weiming mysql]# chown -R mysql data
[root@weiming mysql]# chgrp -R mysql .
#设置一些目录的权限,一定要的
[root@weiming mysql]# bin/safe_mysqld --user=mysql &
starting mysqld daemon with databases from /usr/local/mysql/data
#这个时候mysql会建立一个/tmp/mysql.sock,可以先等会儿不要急着按enter。这个socket file是动态生成的,不可以被移动,复制,没它mysql是启动不了的。
2.[root@weiming mysql]# netstat -tl | grep mysql
tcp 0 0 *:mysql *:* LISTEN
#这样就搞定了,mysql已经在监听了。
3.开机后立即启动:
[root@weiming mysql]# vi /etc/rc.d/rc.local
#将下面这一行加入到最后一行
cd /usr/local/mysql; /usr/local/mysql/bin/safe_mysqld --user=mysql &
#记得加上cd /usr/local/mysql;并在改句后面加个空格,不然会导致无法自动在开机的时候启动(让我郁闷了好久)。
4.高级设置:
由于mysql放置的位置在/usr/local/mysql中,而这个目录不在PATH当中,且man page也不在MANPATH里面,所以要手动加入。
[root@weiming mysql]# vi /etc/profile
找到export PATH...那一行,加入这么句:
PATH="$PATH":/usr/local/mysql/bin
#记得要logout,这个命令在下次开机也可以用了。
[root@weiming mysql]# vi /etc/man.config
#可以在这个文件的任何地方加入这么一行:
MANPATH /usr/local/mysql/man
5.建立mysql的root帐号密码:
[root@weiming mysql]# /usr/local/mysql/bin/mysqladmin -u root password ''yourpassword''
#为了安全
二、安装需要编译的新版apache2.*
1.因为目前有所谓的这个动态函数库,因此,在安装apache时,请特别要向apache声明php模块使用动态函数库的模式。
[root@weiming root]# cd /usr/local/src
[root@weiming src]# tar -zxvf httpd-2.0.55.tar.gz
[root@weiming src]# cd httpd-2.0.55
[root@weiming httpd-2.0.55]# ./configure --prefix=/usr/local/apache2 --enable-so --enable-rewrite
#--prefix=/安装的路径
--enable-so 这是在宣告使用动态函数库,特别重要!
--enable-rewrite 这是预防用的,先设置一下。
2.开始编译与安装:
[root@weiming httpd-2.0.55]#make; make install
#应该不会有什么问题了
3.简单的修改:
[root@weiming httpd-2.0.55]# vi /usr/local/apache2/conf/httpd/conf
#找到这2行:
User nobody
Group #-1
#很奇怪,居然是#-1,查一下你的/etc/passwd与/etc/group是否有nobody存在,没有的话自行加。
User nobody
Group nobody
#存储后推出。
4.确定启动状态:
[root@weiming httpd-2.0.55]# /usr/local/apache2/bin/apachectl start
[root@weiming httpd-2.0.55]# netstat -utl
tcp 0 0 *:http *:* LISTEN
同样把/usr/local/apache2/bin/apachectl start放在/etc/rc.d/rc.local内,开机时启动apache。
5.高级设置:
跟mysql的一样的,在/etc/profile将安装mysql新增的那行该为:
PATH="$PATH":/usr/local/mysql/bin:/usr/local/apache2/bin
还有man参照mysql的设置。
三、安装php
1.
[root@weiming root]#cd /usr/local/src
[root@weiming src]# tar -zxvf php-4.4.1.tar.gz
[root@weiming src]# cd php-4.4.1
[root@weiming php-4.4.1]# ./configure --prefix=/usr/local/php4 --with-apxs2=/usr/local/apache2/bin/apxs --with-
mysql=/usr/local/mysql
#--with-apxs2=/usr/local/apache2/bin/apxs 这是apache2专用的选项,请针对你的主机设置
--with-mysql 这是针对mysql的安装路径,这几个是同一行的.
...skipping
+--------------------------------------------------------------------+
| License: |
| This software is subject to the PHP License, available in this |
| distribution in the file LICENSE. By continuing this installation |
| process, you are bound by the terms of this license agreement. |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point. |
+--------------------------------------------------------------------+
| *** NOTE *** |
| The default for register_globals is now OFF! |
| |
| If your application relies on register_globals being ON, you |
| should explicitly set it to on in your php.ini file. |
| Note that you are strongly encouraged to read |
| http://www.php.net/manual/en/security.globals.php |
| about the implications of having register_globals set to on, and |
| avoid using it if possible. |
+--------------------------------------------------------------------+
Thank you for using PHP.
2.开始编译与安装:
[root@weiming php-4.4.1]# make
...skipping
Build complete.
(It is safe to ignore warnings about tempnam and tmpnam).
[root@weiming php-4.4.1]#make install
[root@weiming php-4.4.1]# cp php.ini-dist /usr/local/lib/php.ini
将主要的 php 设定档 php.ini-dist 拷贝成 /usr/local/lib/php.ini 这个档案,
这是因为 apache 或其它程序执行 php 时需要到 usr/local/lib/ 中去使用这档案。
3.启动apache当中的php选项:
[root@weiming php-4.4.1]# vi /usr/local/apache2/conf/httpd.conf
#找到下面2行
LoadModule php4_module modules/libphp4.so #大约在231行
AddType application/x-httpd-php .php #在847行自行增加
4.重新启动apache:
[root@weiming php-4.4.1]# /usr/local/apache2/bin/apachectl stop
[root@weiming php-4.4.1]# /usr/local/apache2/bin/apachectl start
5.测试php是否正常工作;
[root@weiming php-4.4.1]# cd /usr/local/apache2/htdocs
[root@weiming php-4.4.1]# vi test.php
<?
phpinfo();
?>
#以我的测试主机为例,ip是192.168.3.1,我在虚拟机上也安装了2000,所以得同时启动windows2000,在2000地址栏中输入http://192.168.3.1/test.php
呵呵,看到了那熟悉的php测试页了吧:-)