Chinaunix首页 | 论坛 | 博客
  • 博客访问: 547156
  • 博文数量: 201
  • 博客积分: 7734
  • 博客等级: 少将
  • 技术积分: 1994
  • 用 户 组: 普通用户
  • 注册时间: 2010-04-09 19:18
文章分类

全部博文(201)

文章存档

2011年(28)

2010年(173)

分类:

2010-07-14 18:13:13

ApacheWeb ServerSSL則使用mod_sslApache外掛模組,而mod_ssl需要OpenSSL才能工作,所以安裝Linux時必須先安裝好OpenSSL套件(包含Source),不然就先想辦法裝 上吧!

首先要先取得以下檔案:

apache_1.3.23.tar.gz

mod_ssl-2.8.6-1.3.23.tar.gz

php-4.1.1.tar.gz

postgresql-7.2.tar.gz

 

 

然後進行解壓縮工作

tar zxvf apache_1.3.23.tar.gz

tar zxvf mod_ssl-2.8.6-1.3.23.tar.gz

tar zxvf php-4.1.1.tar.gz

tar zxvf postgresql-7.2.tar.gz

 

 

先安裝設定好PostgreSQL

cd postgresql-7.2

./configure --enable-unicode-conversion --enable-locale --enable-multibyte --enable-odbc --with-perl --with-maxbackends=1024

gmake

gmake install

 

接下來需要設定PostgreSQL執行環境

 

/etc/ld.so.conf加入下列這一行

/usr/local/pgsql/lib

 

然後執行命令

/sbin/ldconfig

 

修改/etc/profile

PATH的 部分加入/usr/local/pgsql/bin,並加入下列三行

PGLIB="/usr/local/pgsql/lib"

PGDATA="/usr/local/pgsql/data"

export PGLIB PGDATA

 

執行下列命令

mkdir /usr/local/pgsql/data

chown postgres /usr/local/pgsql/data

 

切換Userpostgres

執行下列命令用以初始化資料 庫

/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data

 

執行下列命令用以啟動PostgreSQL

/usr/local/pgsql/bin/postmaster -i -D /usr/local/pgsql/data&

 

然後在/etc/rc.local加入以下這行,以便機器啟動時就啟動PostgreSQL

su -l postgres -c "/usr/local/pgsql/bin/postmaster -i -D /usr/local/pgsql/data"&

 

 

然後先設定一下Apache,以便進行PHP4的 安裝

cd apache_1.3.33

./configure

./configure --prefix=/usr/local/apache --enable-module=info

cd ..

 

安裝PHP4

cd php-4.1.1

./configure --prefix=/usr/local/php --with-apache=../apache_1.3.33 --with-pgsql=/usr/local/pgsql --enable-trans-sid --enable-ftp --enable-discard-path --enable-url-includes

make

make install

cp php.ini-dist /usr/local/lib/php.ini

cd ..

 

 

安裝mod_ssl

cd mod_ssl-2.8.6-1.3.23

./configure --with-apache=../apache_1.3.33

cd ..

 

 

安裝Apache及產生認證檔案

cd apache_1.3.33

./configure --activate-module=src/modules/php4/libphp4.a --enable-module=ssl

make

make certificate

.....中間會問一堆問題,都是資料性,像是國碼,網站名稱等等......

 

然後會產生三個檔案,這三個檔案要保存並保護好,避免被駭客拿去...

conf/ssl.key/server.key

conf/ssl.crt/server.crt

conf/ssl.csr/server.csr

 

make install

 

然後修改/usr/local/apache/conf/httpd.conf

 

DirectoryIndex index.html改成

    DirectoryIndex index.html  index.htm  index.php  index.php3  index.shtml

以支援其他類型的Index

 

將下列註解消掉,並加入.php3字 樣,以支援PHP4

    AddType application/x-httpd-php .php .inc

    AddType application/x-httpd-php-source .phps

 

執行/usr/local/apache/bin/apachectl configtest檢查設定

如果沒問題就執行

/usr/local/apache/bin/apachectl startssl

輸入密碼後就可以啟動Apache+SSL


注:


$dbconn=pg_connect("host=localhost dbname=dbname user=user_name password=user_password")or die("数据库连接错误");

ordie('Couldnotconnect:.pg_last_error());





// 执行SQL查询


$query='SELECT*FROMauthors';


$result=pg_query($query)ordie('Queryfailed:.pg_last_error());





// 用HTML显示结果


echo"

\n";


while($line=pg_fetch_array($result,null,PGSQL_ASSOC)){


echo"\t
\n";


foreach($lineas$col_value){


echo"\t\t
\n";


}


echo"\t
\n";


}


echo"
$col_value
\n";





// 释放结果集


pg_free_result($result);





//关闭连接


pg_close($dbconn);


?>


第二代码:

<?php
//$db = null;

$host = "127.0.0.1";
$user = "postgres";
$pass = "password";
$db = "test";

//open a connection to the database server

$connection = pg_connect ("host=$host dbname=$db user=$user password=$pass");

if (!$connection)
{
die ("Could not open connection to database server");
}

//generate and execute a query

echo "Successfully connect to pgsql";
$query = "SELECT * from company";
$result = pg_query($connection, $query) or die("Error in query: $query.".pg_last_error ($connection));

//get the number of rows in the resultset

$rows = pg_num_rows($result);

echo "There are currently $rows records in the database.";

// close database connection

pg_close($connection);
?>


阅读(1285) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~