Home php教程 php手册 [转]Apache+PHP3+PostgreSQL作为基于Web的数据库平台的安装

[转]Apache+PHP3+PostgreSQL作为基于Web的数据库平台的安装

Jun 21, 2016 am 09:13 AM
apache pgsql postgresql

apache|web|数据|数据库

发信人: xiaoning (我要飞), 信区: Linux
标  题: Apache+PHP3+PostgreSQL作为基于Web的数据库平台的安
发信站: BBS 水木清华站 (Thu Jan 20 16:00:28 2000)
  
以下将说明使用Apache+PHP3+PostgreSQL作为基于Web的数据库平台的安装和配置方法

关于Apache、PHP3和PostgreSQL的更多内容可以从软件的附带文档、Linux的HOWTO文件
  
以及以下站点处找到:
Apache: http://www.apache.org
PHP3: http://www.php.net
PostgreSQL: http://www.postgresql.org
1. PostgreSQL的安装和设置
1.1 获得源程序
PostgreSQL最新版本的源程序可以在http://www.postgresql.org找到。目前的最新版本
  
是6.5.X。以下以6.4 版为例说明安装方法。
1.2 准备工作
编译PostgreSQL需要3.75版以上的GNU make (用gmake -v检查版本号) ,2.7.2版以上的
  
GNU C(用gcc -v 检查版本号)以及bison和flex(通常这两种工具都已经安装了) 。
PostgreSQL的默认安装位置为/usr/local/pgsql/,系统文件约需3-10M空间。附带的测

程序在运行时需要约20M空间,所以安装时应注意预留足够的空间,建议/usr/local/pg
sql/
目录下保证有50M以上空间。另外展开和编译源程序约需30-60M空间。
对多用户的应用环境,建议设置一个专用用户名,例如 postgres :
$ su 首先登录为root
# /usr/sbin/adduser postgres
另外PostgreSQL使用了System V的共享内存机制。FreeBSD默认状态不支持该机制。如使

中的内核的设置文件中无以下项目则需追加后重新编译内核:
options SYSVSHM
options SYSVSEM
options SYSVMSG
建保存源程序的目录/usr/local/src/pgsql和安装目录/usr/local/pgsql:
#mkdir /usr/local/pgsql
#chown postgres:postgres /usr/local/pgsql
#mkdir /usr/local/src
#mkdir /usr/local/src/pgsql
#chown postgres:postgres /usr/local/src/pgsql
1.3 编译
以postgres用户登录, 解压缩源程序:
# su postgres
$ tar -xzvf /tmp/postgresql-v6.4.tar.gz [假设下载文件保存在/tmp目录下]
完成后应生成一个postgresql-v6.4目录,下面开始编译:
$ cd /usr/local/src/pgsql/postgresql-v6.4/src
$ ./configure --with-mb=EUC_CN
其中,--with-mb=指定系统默认字符编码。除GB码(EUC_CN) 外,还可以指定为日语
(EUC_JP)、韩语(EUC_KR) 、台湾(EUC_TW) 、UNICODE、MULE_INTERNAL、LATIN1等。
注意,如使用6.3.2版需用--with-template=... 指定操作系统,具体内容见源程序附带
的说明文件。
configure如顺利完成,将生成GNUmakefile,Makefile.global和Makefile.port等文件。
  
$ gmake all
在编译结束后将显示以下信息:
All of PostgreSQL is successfully made. Ready to install.
安装:
$ gmake install
正常完成后,PostgreSQl的执行文件和库文件等将被安装到/usr/local/pgsql目录下。
  
安装附带文档:
$ gmake install-man
$ cd /usr/local/src/postgresql-v6.4/doc
$ make install
至此PostgreSQL的编译安装已经完成,下面开始初期设置。
1.4 初期设置
设置环境变量:
如使用的shell为bash, 则在.bashrc中添加以下命令:
PATH="$PATH":/usr/local/pgsql/bin
export POSTGRES_HOME=/usr/local/pgsql
export PGLIB=$POSTGRES_HOME/lib
export PGDATA=$POSTGRES_HOME/data
export MANPATH="$MANPTH":$POSTGRES_HOME/man
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH":"$PGLIB"
然后执行 source ~/.bashrc
如使用的shell为csh/tcsh则在.cshrc中添加以下命令:
setenv PATH="$PATH":/usr/local/pgsql/bin
setenv POSTGRES_HOME=/usr/local/pgsql
setenv PGLIB=$POSTGRES_HOME/lib
setenv PGDATA=$POSTGRES_HOME/data
setenv MANPATH="$MANPTH":$POSTGRES_HOME/man
setenv LD_LIBRARY_PATH="$LD_LIBRARY_PATH":"$PGLIB"
然后执行 source ~/.cshrc
以上环境变量是所有使用数据库的用户都需要设置的。
数据库目录的初始化:
$ initdb
可以使用的参数:
--pgdata=/pgsql/db 指定数据库目录,默认使用环境变量PGDATA指定的位置
--pgencoding=EUC_CN 指定数据库的字符编码,默认使用configure时指定的编码。
需要注意的是执行initdb的用户将拥有所建数据库目录的管理权。
使用以下命令启动PostgreSQL:
$ postmaster -S
运行测试程序:
$ cd test/regression
$ gmake all runtest
如测试程序能正常运行则说明PostgreSQL能正常运行。
为了让 PostgreSQL在系统启动时能自动启动,需作以下变更:
首先以root登录
$ su
Linux: 在/etc/rc.d/rc.local中追加以下内容:
POSTGRESDIR=/usr/local/pgsql
if [ -x $POSTGRESDIR/bin/postmaster -a -d $POSTGRESDIR/data ];then
rm -f /tmp/s.PGSQL.5432
su - postgres -c "postmaster -S -i"
echo -n 'postmaster'
fi
FreeBSD: 在/usr/local/etc/rc.d中建立名为pgsql.sh的文件,内容为:
#! /bin/sh
POSTGRESDIR=/usr/local/pgsql
if [ -x $POSTGRESDIR/bin/postmaster -a -d $POSTGRESDIR/data ];then
rm -f /tmp/s.PGSQL.5432
su - postgres -c "postmaster -S -i"
echo -n 'postmaster'
fi
修改pgsql.sh文件的权限:
# chmod 755 pgsql.sh
现在PostgreSQL的安装和设定基本已经完成了,但是目前为止能使用数据库的用户只有
postgres。
为使其他用户可以使用数据库,需要登录数据库用户和生成用户数据。
例如通过Web服务器Apache进行查询的用户,用户名为nobody:
% createuser nobody
Enter user's postgres ID or RETURN to use unix user ID: 1000 ->1000
Is user "nobody" allowed to create dataase(y/n)n
Is user "nobody" allowed to add users?(y/n)n
createuser: nobody was successfully added
删除用户可以使用命令destroyuser 用户名
PostgreSQL可以同时管理多个数据库(但数据库之间不能进行join等操作)。新建数据库

$ createdb 数据库名
新建的数据库将被放在/usr/local/pgsql/data/base的同名目录下(环境变量PGDATA指定
  
路径的base目录下)。如省略数据库名参数,将自动以用户名作为数据库名。
例如 名为db1的数据库将被保存在/usr/local/pgsql/data/base/db1目录下。
也可使用initlocation命令指定其他位置:
$ initlocation /pgsql/data
$ export PGDATA2=/pgsql/data
$ createdb -D PGDATA2 db2
则数据库db2将被保存在/pgsql/data目录下。另外PostgreSQL 6.4版可以在建立数据库

指定文字编码:
createdb -E “字符编码” “字符编码” 参见
configure、initdb。
删除数据库:destroydb 数据库名
PostgreSQL最基本的数据库管理工具是pgsql. 基本使用方法:pgsql 数据库名
1.5 安全设置:
PostgreSQL提供了基于主机的认证方式host based authentication(HBA) 、基于口令的
  
用户身份认证和用户操作权限设置等安全机制。
1.5.1 HBA方式和基于口令的用户身份认证方式
HBA方式的设置文件为pg_hba.conf。其格式为:
host DBNAME IP_ADDRESS ADDRESS_MASK USRAUTH [AUTH_ARGUMENT]
host: 固定标志,不能修改
DBNAME: 数据库名,all代表所有数据库
IP_ADDRESS,ADDRESS_MASK:指定IP地址,也可指定子网,如192.168.10.0/255.255.2
55.0
USERAUTH: 对用户的认证方式,包括ident(RFC1413) 、trust(不进行认证) 、reject
(拒绝符合条件的访问) 、password [passwd_file](根据flat file口令文件进行认证)

crypt(使用PostgreSQL的系统数据库pg_shadow进行认证) 、kbr4/kbr5(Kerberos V4/V
5认
证) 。如在作为Web 数据库使用, 使用passwd口令文件进行本地登录时可如下设置:
Host all 127.0.0.1 255.255.255.255 password passwd
passwd文件默认位置为/usr/local/pgsql/data, 有数据库管理权限的用户可以使用
pg_passwd命令管理该文件(注意:flat file口令认证方式采用明文传送口令,故要从网

上其他主机登录,建议使用crypt认证方式) 。
1.5.2 用户操作权限设置
使用SQL命令grant/revoke可以设置用户/用户组可否使用select/insert/update/rule命
令。
根据SQL标准,一个数据表文件(table) 在刚建立时只有建立该表文件的用户有权访问。
  
要分配给用户访问权限,可以使用grant命令:
grant on to
权限种类:all,select,insert,update,delete,rule
table名:被设置用户访问权限的表文件
用户/组:public(所有用户) 或用户名/组名
revoke命令作用与grant命令相反,用法如下:
revoke on from
table已设置的用户权限可以使用pgsql的\z 命令查看。
2. Apache+PHP3的安装及设置
2.1 源程序
Apache和PHP3的最新版本源程序可以从http://www.apache.org/和http://www.php.net
/找到。
以下以Apache 1.3.6和PHP3 3.0.5 为例。
2.2 编译
假设Apache和PHP3的源程序都保存在/tmp目录下,首先登录为root:
$ su
# cd /usr/local/src
# tar -xzvf /tmp/apache_1.3.6.tar.gz
# ./configure
# cd /usr/local/src
# tar -xzvf /tmp/php3-3.0.5.tar.gz
# cd php-3.0.5
# ./configure --with-pgsql --with-apache=../apache_1.3.6 --enable-track-vars
  
# make
# make install
最后一步将建立/usr/local/src/apache_1.3.6/src/modules/php3目录,并将以下文件
  
复制到该目录下:
Makefile.libdir libmodphp3.a mod_php3.c php_version.h
Makefile.tmpl libphp3.module mod_php3.h
编译和安装Apache:
设置环境变量LD_LIBRARY_PATH csh和tcsh shell使用以下命令:
# setenv LD_LIBRARY_PATH /usr/local/pgsql/lib
sh和bash使用如下命令:
# LD_LIBRARY_PATH=/usr/local/pgsql/lib
# export LD_LIBRARY_PATH
然后
# cd /usr/local/src/apache_1.3.6
# ./configure --activate-module=src/modules/php3/libphp3.a
# make
# make install
2.3 修改设置文件
# cd /usr/local/src/php-3.0.5
# cp php3.ini-dist /usr/local/lib/php3.ini
将/usr/local/apache/etc/srm.conf中以下两行内容前的#号删除,如果以.php3作为PH
P3
文件的扩展名,则将.phtml 更改为 .php3:
#AddType application/x-httpd-php3 .php3
#AddType application/x-httpd-php3-source .phps
在srm.conf文件的DirectoryIndex下增加 index.php3:
DirectoryIndex index.html index.php3
  
2.4 启动Apache
# /usr/local/apache/sbin/apachectl start
apachectl start: httpd started
在本地机上启动网络浏览器,地址栏输入http://localhost/(或在其他计算机上的浏览

地址栏输入Apache服务器地址),如能显示出Apache的开始画面则说明Apache已经
安装成功。下面测试PHP3模块工作是否正常:
# cd /usr/local/apache/share/htdocs/
# ln -s /usr/local/src/php-3.0.5 .
然后在浏览器的地址栏输入http://localhost/php-3.0.5/examples/date.php3
观察php3文件的运行结果是否正常。如日期函数能显示正确结果,则说明PHP3模块工作
正常。
至此,基于Apache Web服务器和服务器端脚本语言PHP3的PostgreSQL数据库系统的安装
已经完成 :-) 



Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP Framework Performance Comparison: The Ultimate Showdown of Speed ​​vs. Efficiency PHP Framework Performance Comparison: The Ultimate Showdown of Speed ​​vs. Efficiency Apr 30, 2024 pm 12:27 PM

According to benchmarks, Laravel excels in page loading speed and database queries, while CodeIgniter excels in data processing. When choosing a PHP framework, you should consider application size, traffic patterns, and development team skills.

Integration and expansion of golang function concurrency control and third-party libraries Integration and expansion of golang function concurrency control and third-party libraries Apr 25, 2024 am 09:27 AM

Concurrent programming is implemented in Go through Goroutine and concurrency control tools (such as WaitGroup, Mutex), and third-party libraries (such as sync.Pool, sync.semaphore, queue) can be used to extend its functions. These libraries optimize concurrent operations such as task management, resource access restrictions, and code efficiency improvements. An example of using the queue library to process tasks shows the application of third-party libraries in actual concurrency scenarios.

How to conduct concurrency testing and debugging in Java concurrent programming? How to conduct concurrency testing and debugging in Java concurrent programming? May 09, 2024 am 09:33 AM

Concurrency testing and debugging Concurrency testing and debugging in Java concurrent programming are crucial and the following techniques are available: Concurrency testing: Unit testing: Isolate and test a single concurrent task. Integration testing: testing the interaction between multiple concurrent tasks. Load testing: Evaluate an application's performance and scalability under heavy load. Concurrency Debugging: Breakpoints: Pause thread execution and inspect variables or execute code. Logging: Record thread events and status. Stack trace: Identify the source of the exception. Visualization tools: Monitor thread activity and resource usage.

The evasive module protects your website from application layer DOS attacks The evasive module protects your website from application layer DOS attacks Apr 30, 2024 pm 05:34 PM

There are a variety of attack methods that can take a website offline, and the more complex methods involve technical knowledge of databases and programming. A simpler method is called a "DenialOfService" (DOS) attack. The name of this attack method comes from its intention: to cause normal service requests from ordinary customers or website visitors to be denied. Generally speaking, there are two forms of DOS attacks: the third and fourth layers of the OSI model, that is, the network layer attack. The seventh layer of the OSI model, that is, the application layer attack. The first type of DOS attack - the network layer, occurs when a large number of of junk traffic flows to the web server. When spam traffic exceeds the network's ability to handle it, the website goes down. The second type of DOS attack is at the application layer and uses combined

How to add a server in eclipse How to add a server in eclipse May 05, 2024 pm 07:27 PM

To add a server to Eclipse, follow these steps: Create a server runtime environment Configure the server Create a server instance Select the server runtime environment Configure the server instance Start the server deployment project

Application of algorithms in the construction of 58 portrait platform Application of algorithms in the construction of 58 portrait platform May 09, 2024 am 09:01 AM

1. Background of the Construction of 58 Portraits Platform First of all, I would like to share with you the background of the construction of the 58 Portrait Platform. 1. The traditional thinking of the traditional profiling platform is no longer enough. Building a user profiling platform relies on data warehouse modeling capabilities to integrate data from multiple business lines to build accurate user portraits; it also requires data mining to understand user behavior, interests and needs, and provide algorithms. side capabilities; finally, it also needs to have data platform capabilities to efficiently store, query and share user profile data and provide profile services. The main difference between a self-built business profiling platform and a middle-office profiling platform is that the self-built profiling platform serves a single business line and can be customized on demand; the mid-office platform serves multiple business lines, has complex modeling, and provides more general capabilities. 2.58 User portraits of the background of Zhongtai portrait construction

How to deploy and maintain a website using PHP How to deploy and maintain a website using PHP May 03, 2024 am 08:54 AM

To successfully deploy and maintain a PHP website, you need to perform the following steps: Select a web server (such as Apache or Nginx) Install PHP Create a database and connect PHP Upload code to the server Set up domain name and DNS Monitoring website maintenance steps include updating PHP and web servers, and backing up the website , monitor error logs and update content.

Java package management and integration of dependencies and version control Java package management and integration of dependencies and version control Apr 24, 2024 pm 09:48 PM

In Java, package management and version control integration are crucial, using Maven to manage dependencies and Git for version control. The integration steps include initializing the Git repository, creating the Maven function package information file, and adding it to the Git repository. In a practical case, add the CommonsLang dependency, use Maven to download it and add it to the Git repository to ensure that the team uses the same dependency version.

See all articles