配过几次 这次又过了好久了又忘了
一套经典的服务器配置,经过N次的重复劳动 参考了一份非常好的文档 整理收集一下
一、安装环境描述

php-4.3.11.tar.gz
httpd-2.0.54.tar.gz
mysql-4.0.24.tar.gz
gd-2.0.33.tar.gz
phpmyadmin请到http://sourceforge.net/下载



如果你已经随系统安装了自带的http和mysql,php那么首先卸掉
rpm -qa这个命令查询系统上是否安装过某个软件(linux系统中httpd就是apache)
先查找apache的安装包 类似
代码:

[root@linuxsir01 root]# rpm -qa | grep httpd
redhat-config-httpd-1.1.0-5
httpd-devel-2.0.47-10
httpd-manual-2.0.47-10
httpd-2.0.47-10

卸载一个软件包用rpm -e
比如要卸载httpd-2.0.47-10 只要命令
rpm -e httpd 后面的是版本号 不需要的

删除的时候可能会提示 某些软件需要 没关系
将所有与之相关联的软件包删除掉就可以了

1.安装mysql
[root@localhost root]tar zxvf mysql-4.0.24.tar.gz
[root@localhost root]cd mysql --->[Tab] 确认
这里的[Tab]就是用linux命令自动补全。
[root@localhost mysql-4.0.24]#./configure --prefix=/usr/local/mysql --with-extra-charsets=all
说明:
--prefix=/usr/local/mysql是指安装mysql的路径
这里我安装的路径是/usr/local/mysql,你可以指定不同的路径
--with-extra-charsets=all 让mysql支持多语言

然后运行make 和make install 就装完了
我们得把文件my.cnf文件放到/etc/目录下。让mysql服务器启动时能找到它。

安装好mysql后,配制文件应该在/usr/local/mysql/share/mysql目录中,配制文件有几个,有my-huge.cnf my-medium.cnf my-large.cnf my-small.cnf
,不同的流量的网站和不同配制的服务器环境,当然需要有不同的配制文件了。一般的情况下,my-medium.cnf这个配制文件就能满足我们的大多需要;
[root@localhost mysql-4.0.24]# cp /usr/local/mysql/share/mysql/my-medium.cnf /etc/my.cnf

接着创建MySQL授权表, 否则数据库也是启动不了。
mysql_install_db,这个命令的用途就是做这个的。mysql_install_db这个命令应该已经安装到了/usr/local/mysql/bin这个目录中。

[root@localhost mysql]#bin/mysql_install_db

看看mysql目录下是不是多了一个 var 目录,在到var目录里面看看,是不是还有两个目录 mysql test ,mysql目录下应该有一些文件,test目录应该是空的。
现在 var 目录下只有两个目录 没有别的文件,那是因为我们还没有启动mysql
[root@localhost mysql-4.0.24]# /usr/local/mysql/bin/mysqld_safe &
[1]+ Exit 1 /usr/local/mysql/bin/mysqld_safe
[root@localhost mysql-4.0.24]#
看到上面的信息表示我们已经成功启动了mysql
刚才启动mysql命令是初始化启动方式,以后的启动我们不会使用这个命令。
注意点
在启动mysql过程中你可能会遇到和下面类似的这种情况:

[root@localhost mysql]# bin/mysqld_safe &
[1] 14587
[root@localhost mysql]# Starting mysqld daemon with databases from /usr/local/mysql/var
STOPPING server from pid file /usr/local/mysql/var/localhost.localdomain.pid
050407 01:44:15 mysqld ended
[1]+ Done bin/mysqld_safe

这时我们应该看看错误记录文件
localhost.localdomain.err
位置在/usr/local/mysql/var/下面。寻找出错的原因
可能会得到类似的错误
代码:

[root@localhost mysql]# more /usr/local/mysql/var/localhost.localdomain.err
050407 01:47:18 mysqld started
/usr/local/mysql/libexec/mysqld: File './localhost-bin.1' not found (Errcode: 13
)
050407 1:47:18 [ERROR] Could not use localhost-bin for logging (error 13). Turn
ing logging off for the whole duration of the MySQL server process. To turn it o
n again: fix the cause, shutdown the MySQL server and restart it.
050407 1:47:18 InnoDB: Operating system error number 13 in a file operation.
InnoDB: The error means mysqld does not have the access rights to
InnoDB: the directory.
InnoDB: File name ./ibdata1
InnoDB: File operation call: 'create'.
InnoDB: Cannot continue operation.
050407 01:47:18 mysqld ended

如果出现这种错误消息,说明是数据库目录权限的问题造成的。也就是无法在数据库的目录(var目录)中创建 ibdatal 文件。这时我们只要改变一下var目录的权限就可以了
[root@localhost mysql]#chmod -R 1777 var/

再次启动mysql,我们到 var 目录看看是不是多了几个文件
ibdata1
ib_logfile0
ib_logfile1
以后我们的启动可以从mysql的脚本中启动,在 /usr/local/mysql/share/mysql/目录下有一个 启动mysql的文件 mysqld.server
我们可以把他复制到/etc/rc.d/init.d/目录并且改名为mysql

[root@localhost mysql]#cp mysqld.server /etc/rc.d/init.d/mysql

启动
/etc/rc.d/init.d/mysql start
停止
/etc/rc.d/init.d/mysql stop
重启:
/etc/rc.d/init.d/mysql restart

验证一下mysql是不是真的启动了,最好的办法就是用客户端去连接mysql


[root@localhost mysql]# bin/mysql

Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 14 to server version: 5.0.2-alpha

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>

启动成功

看看是不是有2个数据库,应该和var目录下的2个目录名字一样
mysql
test

mysql> show databases
-> ;
+----------+
| Database |
+----------+
| mysql |
| test |
+----------+
2 rows in set (0.00 sec)
在mysql/bin目录下有个mysqladmin工具是用来管理和操作mysql用的,我们用他来给 root 加上密码
[root@localhost mysql]#bin/mysqladmin -uroot password 123456
这样我们就给root设置了 123456 这个密码

再次登录
[root@localhost mysql]# bin/mysql
上次我们使用这个命令连接mysql,看看密码是否生效。
[root@localhost mysql]# bin/mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@localhost mysql]#
进不去了,说明密码设置成功。
们在用密码试试,这时应该说明是什么用户登录,这里我们用的是 root 这个用户。

[root@localhost mysql]# bin/mysql -uroot -p
Enter password: 这里密码是不显示的,不要按错键盘就行
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 18 to server version: 5.0.2-alpha

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>

顺便说几个管理数据库的常用命令,看到论坛里有不少问如何导入数据库的贴子。
查看数据库:
mysql> show databases

新建数据库:
mysql> create database [新的数据库名]

删除数据库:
mysql> drop database [要删除的数据库名]

指定一个数据库为当前数据库
mysql>use [数据库名]

备份数据库:
[root@localhost mysql]# /usr/local/mysql/bin/mysqldump -uroot -p 123456 > /root/shuifu.sql
Enter password: 这里输入数据库的密码
这个命令就是备份上面的 shuifu 这个数据库
备份的文件名就是 shuifu.sql

导入数据库:
[root@localhost mysql]#/usr/local/mysql/bin/mysqldump -uroot -p 123456 < /home/shuifu.sql
Enter password:
这个命令就是把刚才我们备份的shuifu.sql这个数据库文件导入到数据库中。
注意看清楚< >,应该知道了吧,< 导入。 > 导出。

[b]二、安装APACHE[b]
代码:

./configure --prefix=/usr/local/apache --with-mysql=/usr/local/mysql --enable-track-vars --enable-cgi --enable-so --enable-mods-shared=all --with-config-file-path=/usr/local/apache/conf

--prefix=/usr/local/apache 指定把apahce安装到/usr/local/apache目录中;
--enable-cgi 支持CGI;
--with-config-file-path=/usr/local/apache/conf 指定把apache的配制文件放在/usr/local/apache/conf中;比如httpd.conf配制文件就在这个目录中;
--enable-track-vars 为启动cookie的get/post等追踪功能
--enable-so DSO功能
--enable-mods-shared=all 包含所有的模块为DSO

如果需要更多的选项,可能通过下面的命令来查看; (./configure --help)

make
make install

设置成开机自启动
在/etc/rc.d/rc.local文件中加入一行
/usr/local/apache/bin/apachectl start
这样每次重新启动系统以后,apache也会随系统一起启动.

[b]三、安装PHP[b]
先安装GD
1、安装GD
代码:

tar xzvf gd-2.0.33.tar.gz
./configure --prefix=/usr/local/modules/gd --with-jpeg=/usr/local/modules/jpeg6 --with-png --with-zlib --with-freetype=/usr/local/modules/freetype
make
make install

版本php-4.3.11

解压php
tar xzvf php-4.3.11.tar.gz
cd php-4.3.11
./configure --prefix=/usr/local/php --with-gd=/usr/local/modules/gd --enable-magic-quotes --with-mysql=/usr/local/mysql --with-iconv --with-mbstring --with-apxs2=/usr/local/apache/bin/apxs --enable-track-vars --enable-force-cgi-redirect --enable-ftp --with-config-file-path=/usr/local/apache/conf
参数说明:
--prefix=/usr/local/php 指定把php-4.3.11安装到/usr/local/php目录中;
--with-mysql=/usr/local/mysql 指定mysql数据服务器安装的位置;
--with-apxs2=/usr/local/apache/bin/apxs 这个参数是加入apache中为DSO模块的位置,papche2以下的版本参数是apxs而不是apxs2,如果你用的apache版本不是2.0以上的就去掉2,
-enable-track-vars 为启动cookie的get/post等追踪功能
--with-config-file-path=/usr/local/apache/conf 指定php的配制文件存放的目录是/usr/local/apache/conf目录,我们安装完成后,也要把php.ini复制到这个目录中来。
和apache放在一起 以方便以后修改
--enable-force-cgi-redirect 让apache支持cgi
接下来的步骤和安装mysql的时候一样:
# make
# make install
cp php.ini-dist /usr/local/apache/conf/php.ini
安装完毕
更改apache的配制文件:得加几行,目的是让apache能解释php程序。
查找AddType application/x-tar .tgz 行,在下面添加
AddType application/x-httpd-php .php
AddType application/x-httpd-php .php3
AddType application/x-httpd-php .phtml
AddType application/x-httpd-php-source .phps
确保load模块的地方有这句调用PHP模块的
LoadModule php4_module modules/libphp4.so
找到下面一行在后面加上index.php,这表示网站的默认页也能够为index.php

DirectoryIndex index.html index.html.var index.php

进行php.ini文件的配置工作
查找safe_mode=Off,更改为safe_mode=On
1)查找max_execution_time = 30,更改为max_execution_time = 600
(2)查找max_input_time = 60,更改为max_input_time = 600
(3)查找memory_limit = 8M ,更改为memory_limit = 20M
(4)查找display_errors = On,更改为display_errors = Off
(5)查找register_globals = Off,更改为register_globals = On
(6)查找post_max_size = 8M,更改为post_max_size = 20M
(7)查找upload_max_filesize = 2M,更改为upload_max_filesize = 20M
(8)查找session.auto_start = 0,更改为session.auto_start = 1
保存后退出,从而完成了php.ini文件的配置工作。

重启一下apache。
测试一下PHP环境是不是可以运行。把下面这一句另存为PHP网页(如:test.php),
<? phpinfo(); ?>
打开浏览器: http://localhost/test.php
如果能正确显示系统信息,就表示可以了。


如果gd库已开始没有安装,以后又想用,是需要重新编译安装php的
 
posted on 2010-05-21 11:04  MinisFox  阅读(331)  评论(0编辑  收藏  举报