- UID
- 24317
- 帖子
- 33306
- 积分
- 63824
- 阅读权限
- 90
- 注册时间
- 2006-7-15
- 最后登录
- 2011-6-15
- 在线时间
- 10977 小时
|
最近一直在配置linux下的php+Apache+PostgreSQL环境,把5个(VMware- workstation,linux,php,Apache,PostgreSQL)从未接触过的东西整合到一起并能使用,真不是好玩的。不过终于是完成了,现在把全部的过程记录下来。
一,VMware-workstation安装:
1,装的是VMware-workstation-4.5.1-7568.exe
2,注册码:M1ER8-HRW45-N0HFP-4U0JM
二,虚拟机倒入linux系统(linux版本Red Hat Linux9):
1,打开上面提到的Vmware虚拟机,选择File->Open Virtual Machine...
2,选中Red Hat Linux.vmx文件,单击"打开(O)"
3,"运行"按钮,启动linux系统
4,出现窗口时选择"Keep",然后单击"OK"继续
5,出现选择操作系统界面,回车进入。
说明:此时键盘鼠标仍然属于本机操作系统。当在虚拟区域内点击一下鼠标左键后,键盘鼠标就属于虚拟机了,才可以对虚拟机进行操作。如果要切换出来可以按下Ctrl+Alt组合键实现。
6,进入登陆界面,输入用户名“root”和密码后进入命令行模式。
7,输入“startx”进入图形界面
8,配置网络
(1)点击"start applications->System Settings->Network"
(2)点击"Edit",选中单选按钮"Automa……"和复选按钮"Automa……"
(3)然后一路确定。Linux的网络配置就完成了。
(4)接下来确认Vm的设置(网卡为Bridged连接)
(5)现在就可以用虚拟机的Linux访问本机的FTP,实现文件互通了。
三,VMWARE TOOLS安装:
1.以ROOT身份进入LINUX
2.退出到windows,点击 SETTING下的Install VMWARE TOOLS子菜单
3.进入linux运行
①挂载光驱:
# mount -t iso9660 /dev/cdrom /mnt
②拷贝文件,将该软件包拷贝到LINUX的TMP目录(这个自选)下:
# cp /mnt/vmware-linux-tools.tar.gz /tmp
③进入TMP目录:
# cd /tmp
④解压缩该软件包:
# tar zxf vmware-linux-tools.tar.gz
⑤进入解压后的目录(不知道的可以输入# ls察看):
# cd vmware-linux-tools
⑥运行安装命令:
# ./vmware-install.pl
以后除了有[yes]提示的输入“yes”后回车,其它直接回车即可。
还会出现选择分辨率的提示,自己选吧。
四,文件共享:
1,在VM下拉菜单下,选择“Settings...”
2,在出现的界面中,选择“Options”项
3,从左窗体中选择“Shared Folders Enabled”
4,单击“Add...”按钮:
5,单击“下一步”按钮,在出现的界面中命名Linux系统下显示的文件名,指明对应的Windows系统下的文件夹
6,单击“下一步”按钮,设置文件夹的权限,最后点“完成”。
7,路径定位到“/mnt/hgfs”,这时,我们看到刚才定义的共享文件夹
8,进入到该文件夹下,所有内容都可以从Windows系统和虚拟的Liunx系统下修改访问了。
注:当前这种设置,只适合同一台机器,用虚拟环境建立Linux系统的情况下。
五,PostgreSQL安装(用的是postgresql-8.2.0.tar.gz):
1,进入Linux的命令行模式,登陆后进到存放postgresql-8.2.0.tar.gz的文件夹
例如我把安装包放在/home/lsp文件夹下,那么命令为:
[root@localhost root]# cd /home/lsp
2,解压安装包:[root@localhost lsp]# tar -xzvf postgresql-8.2.0.tar.gz
3,进入解压后的文件夹:[root@localhost lsp]# cd postgresql-8.2.0
4,配置源代码树:[root@localhost postgresql-8.2.0]# ./configure
说明:如果在后面增加参数“--prefix=PREFIX”可以实现设置安装路径的功能
比如:# ./configure --prefix=/home/lsp/pgsql
不设置会安装在默认路径“/usr/local/pgsql”下
5,制作:[root@localhost postgresql-8.2.0]# gmake
显示的最后一行应该是:All of PostgreSQL is successfully made. Ready to install.
6,安装:[root@localhost postgresql-8.2.0]# gmake install
说明:其实5,6可以合成为一步[root@localhost postgresql-8.2.0]# gmake && gmake install
7,设置共享库:[root@localhost postgresql-8.2.0]# /sbin/ldconfig /usr/local/pgsql/lib/
8,配置环境变量:[root@localhost postgresql-8.2.0]# vi /etc/profile
然后在文件的最后加入以下几行:
PGLIB=/usr/local/pgsql/lib
PGDATA=$HOME/data
PATH=$PATH:/usr/local/pgsql/bin
MANPATH=$MANPATH:/usr/local/pgsql/man
export PGLIB PGDATA PATH MANPATH
接着,使环境变量生效:
#source /etc/profile
9,添加PostgreSQL用户帐户postgres(这个名字可以自己取):
[root@localhost postgresql-8.2.0]# adduser postgres
10,创建数据库集群:
[root@localhost postgresql-8.2.0]# mkdir /usr/local/pgsql/data
[root@localhost postgresql-8.2.0]# chown postgres /usr/local/pgsql/data
[root@localhost postgresql-8.2.0]# su postgres
[postgres@localhost postgresql-8.2.0]$ initdb -D /usr/local/pgsql/data
说明: (1)创建存放数据库的目录
(2)将存放数据库的目录的权限交给用户postgres
(3)切换到用户postgres
(4)用户postgres创建数据库集群
11,启动数据库:
我们要回到图形化界面运行Terminal(图形化界面里面的命令行)
[root@localhost root]# su postgres
[postgres@localhost root]$ postmaster -i -D /usr/local/pgsql/data
然后看到如下信息:
LOG: database system was interrupted at 2007-01-24 04:19:37 HKT
LOG: checkpoint record is at 0/42C46C
LOG: redo record is at 0/42C46C; undo record is at 0/0; shutdown TRUE
LOG: next transaction ID: 0/593; next OID: 10820
LOG: next MultiXactId: 1; next MultiXactOffset: 0
LOG: database system was not properly shut down; automatic recovery in progress
LOG: record with zero length at 0/42C4B4
LOG: redo is not required
LOG: database system is ready
就说明数据库服务已经开启了。
12,新建个数据库测试一下:
再打开一个Terminal
[root@localhost root]# su postgres
[postgres@localhost root]$ createdb /usr/local/pgsql/data/mydb
提示CREATE DATABASE表示创建成功
13,进入交互工具psql
[postgres@localhost root]$ psql /usr/local/pgsql/data/mydb
会出现如下提示:
Welcome to psql 8.2.0, the PostgreSQL interactive terminal.
Type: \copyright for distribution terms
\h for help with SQL commands
\? for help with psql commands
\g or terminate with semicolon to execute query
\q to quit
/usr/local/pgsql/data/mydb=#
14,这时就可以输入SQL命令了:
建表:/usr/local/pgsql/data/mydb=# CREATE TABLE mytable(id varchar(20),name varchar(20));
插入:/usr/local/pgsql/data/mydb=# INSERT INTO mytable values('2007001', 'postgres');
查询:/usr/local/pgsql/data/mydb=# SELECT * FROM MYTABLE;
六,Apache2安装(使用httpd-2.0.58.tar.gz):
1,进入Linux图形化界面运行Terminal(图形化界面里面的命令行),进到存放httpd-2.0.58.tar.gz的文件夹
例如我把安装包放在/home/lsp文件夹下,那么命令为:
[root@localhost root]# cd /home/lsp
2,解压安装包:
[root@localhost lsp]# tar -xzvf httpd-2.0.58.tar.gz
3,进入解压后的文件夹:
[root@localhost lsp]# cd httpd-2.0.58
4,配置源代码树:
[root@localhost httpd-2.0.58]# ./configure --enable-so
说明:如果在后面增加参数“--prefix=PREFIX”可以实现设置安装路径的功能
比如:# ./configure --prefix=/home/lsp/apache2
不设置会安装在默认路径“/usr/local/apache2”下
5,制作:
[root@localhost httpd-2.0.58]# make
6,安装:
[root@localhost httpd-2.0.58]# make install
说明:其实5,6可以合成为一步[root@localhost httpd-2.0.58]# make && make install
7,启动Apache HTTP服务器:
[root@localhost httpd-2.0.58]# /usr/local/apache2/bin/apachectl start
8,请求第一个网页,用浏览器打开http://localhost/,看到if you can see this...就说明配置正确了。
七,php安装(使用php-4.4.4.tar.gz):
1,进入Linux图形化界面运行Terminal(图形化界面里面的命令行),进到存放php-4.4.4.tar.gz的文件夹
例如我把安装包放在/home/lsp文件夹下,那么命令为:
[root@localhost root]# cd /home/lsp
2,解压安装包:
[root@localhost lsp]# tar -xzvf php-4.4.4.tar.gz
3,进入解压后的文件夹:
[root@localhost lsp]# cd php-4.4.4
4,配置源代码树:
[root@localhost php-4.4.4]# ./configure --prefix=/usr/local/php4 --with-pgsql=/usr/local/pgsql --with-apxs2=/usr/local/apache2/bin/apxs --enable-so
说明: 参数“--prefix=”可以实现设置安装路径的功能,我们把它装在/usr/local/php4下
/usr/local/pgsql是postgreSQL的安装路径;
/home/lsp/apache2是Apache2的安装路径。
5,制作:
[root@localhost php-4.4.4]# make
6,安装:
[root@localhost php-4.4.4]# make install
说明:其实5,6可以合成为一步[root@localhost php-4.4.4]# make && make install
7,安装完后编辑APACHE的配置文件 /usr/local/apache2/conf/httpd.conf
找到 “AddType application/x-gzip .gz .tgz” 在其下添加如下内容:
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
8,把解压缩后文件夹里的php.ini-dsit拷贝到/usr/local/php4/lib/下并改名为php.ini
八,使用测试(如果上面的Apache和postgreSQL服务都启动着,可以省略1,5。这里以完整操作方法为准):
1,启动Apache HTTP服务器:
[root@localhost php-4.4.4]# /usr/local/apache2/bin/apachectl start
2,在服务器文档目录/usr/local/apache2/htdocs/下建立一个简单的测试文件test.php
写入代码:<?php echo "php run"; ?>
3,用浏览器打开http://localhost/test.php
这时可以看到php run字样表示和Apache的配置成功了。
4,连接postgreSQL测试
编辑test.php
<?php
$db = pg_connect("host=localhost port=5432 dbname=/usr/local/pgsql/data/mydb user=postgres ");
if ($db) {
echo "pg_connect is seccess<br>";
} else {
echo "pg_connect is fail<br>";
}
$sql = "select * from mytable";
$result_sql = pg_query($db,$sql);
$arraylist = pg_fetch_all($result_sql);
for($j = 0;$j < count($arraylist);$j ++){
$row = $arraylist[$j];
echo $row["id"]."--".$row["name"]."<br>";
}
?>
5,启动数据库我们使用五--14中创建的表:
我们要回到图形化界面运行Terminal(图形化界面里面的命令行)
[root@localhost root]# su postgres
[postgres@localhost root]$ postmaster -i -D /usr/local/pgsql/data
6,用浏览器打开http://localhost/test.php
这时可以看到:
pg_connect is seccess
2007001--postgres
至此,linux下php+Apache+PostgreSQL环境配置完毕,同时完成相互关联的测试。
呵呵,搞定。
再写个摘要,自己查起来比较方便:
一,VMware-workstation安装:
VMware-workstation-4.5.1-7568.exe
注册码:M1ER8-HRW45-N0HFP-4U0JM
三,VMWARE TOOLS安装:
1.以ROOT身份进入LINUX
2.退出到windows,点击 SETTING下的Install VMWARE TOOLS子菜单
3.进入linux运行
①# mount -t iso9660 /dev/cdrom /mnt
②# cp /mnt/vmware-linux-tools.tar.gz /tmp
③# cd /tmp
④# tar zxf vmware-linux-tools.tar.gz
⑤# cd vmware-linux-tools
⑥# ./vmware-install.pl
以后除了有[yes]提示的输入“yes”后回车,其它直接回车即可。
五,PostgreSQL安装(用的是postgresql-8.2.0.tar.gz):
1,进入Linux的命令行模式,登陆后进到存放postgresql-8.2.0.tar.gz的文件夹
[root@localhost root]# cd /home/lsp
2,[root@localhost lsp]# tar -xzvf postgresql-8.2.0.tar.gz
3,[root@localhost lsp]# cd postgresql-8.2.0
4,[root@localhost postgresql-8.2.0]# ./configure
5,[root@localhost postgresql-8.2.0]# gmake
显示的最后一行应该是:All of PostgreSQL is successfully made. Ready to install.
6,[root@localhost postgresql-8.2.0]# gmake install
7,[root@localhost postgresql-8.2.0]# /sbin/ldconfig /usr/local/pgsql/lib/
8,[root@localhost postgresql-8.2.0]# vi /etc/profile
然后在文件的最后加入以下几行:
PGLIB=/usr/local/pgsql/lib
PGDATA=$HOME/data
PATH=$PATH:/usr/local/pgsql/bin
MANPATH=$MANPATH:/usr/local/pgsql/man
export PGLIB PGDATA PATH MANPATH
#source /etc/profile
回命令行界面!!!
9,[root@localhost postgresql-8.2.0]# adduser postgres
10, [root@localhost postgresql-8.2.0]# mkdir /usr/local/pgsql/data
[root@localhost postgresql-8.2.0]# chown postgres /usr/local/pgsql/data
[root@localhost postgresql-8.2.0]# su postgres
[postgres@localhost postgresql-8.2.0]$ initdb -D /usr/local/pgsql/data
可以回图形界面了。
11,启动数据库:
[root@localhost root]# su postgres
[postgres@localhost root]$ postmaster -i -D /usr/local/pgsql/data
12,新建个数据库测试一下:
[root@localhost root]# su postgres
[postgres@localhost root]$ createdb /usr/local/pgsql/data/mydb
13,进入交互工具psql
[postgres@localhost root]$ psql /usr/local/pgsql/data/mydb
14,这时就可以输入SQL命令了:
建表:/usr/local/pgsql/data/mydb=# CREATE TABLE mytable(id varchar(20),name varchar(20));
插入:/usr/local/pgsql/data/mydb=# INSERT INTO mytable values('2007001', 'postgres');
查询:/usr/local/pgsql/data/mydb=# SELECT * FROM MYTABLE;
六,Apache2安装(使用httpd-2.0.58.tar.gz):
1,进到存放httpd-2.0.58.tar.gz的文件夹
[root@localhost root]# cd /home/lsp
2,[root@localhost lsp]# tar -xzvf httpd-2.0.58.tar.gz
3,[root@localhost lsp]# cd httpd-2.0.58
4,[root@localhost httpd-2.0.58]# ./configure --enable-so
5,[root@localhost httpd-2.0.58]# make
6,[root@localhost httpd-2.0.58]# make install
7,启动Apache HTTP服务器:[root@localhost httpd-2.0.58]# /usr/local/apache2/bin/apachectl start
8,请求第一个网页,用浏览器打开http://localhost/,看到if you can see this...就说明配置正确了。
七,php安装(使用php-4.4.4.tar.gz):
1,进到存放php-4.4.4.tar.gz的文件夹[root@localhost root]# cd /home/lsp
2,[root@localhost lsp]# tar -xzvf php-4.4.4.tar.gz
3,[root@localhost lsp]# cd php-4.4.4
4,[root@localhost php-4.4.4]# ./configure --prefix=/usr/local/php4 --with-pgsql=/usr/local/pgsql --with-apxs2=/usr/local/apache2/bin/apxs --enable-so
5,[root@localhost php-4.4.4]# make
6,[root@localhost php-4.4.4]# make install
7,安装完后编辑APACHE的配置文件 /usr/local/apache2/conf/httpd.conf
找到 “AddType application/x-gzip .gz .tgz” 在其下添加如下内容:
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
8,把解压缩后文件夹里的php.ini-dsit拷贝到/usr/local/php4/lib/下并改名为php.ini
八,使用测试(如果上面的Apache和postgreSQL服务都启动着,可以省略1,5。这里以完整操作方法为准):
1,启动Apache HTTP服务器:[root@localhost php-4.4.4]# /usr/local/apache2/bin/apachectl start
2,在服务器文档目录/usr/local/apache2/htdocs/下建立一个简单的测试文件test.php
写入代码:<?php echo "php run"; ?>
3,用浏览器打开http://localhost/test.php。这时可以看到php run字样表示和Apache的配置成功了。
4,连接postgreSQL测试。编辑test.php:
<?php
$db = pg_connect("host=localhost port=5432 dbname=/usr/local/pgsql/data/mydb user=postgres ");
if ($db) {echo "pg_connect is seccess<br>"; }
?>
5,启动数据库
[root@localhost root]# su postgres
[postgres@localhost root]$ postmaster -i -D /usr/local/pgsql/data
6,用浏览器打开http://localhost/test.php,这时可以看到:
pg_connect is seccess
至此,linux下php+Apache+PostgreSQL环境配置完毕。 |
|