Go Installation of Apache+php3+postgresql as a web-based database platform

Source: Internet
Author: User
Tags date ini net variables table name variable access postgresql version
apache|web| Data | Database sender: xiaoning (I want to fly), letter area: Linux
Title: Apache+php3+postgresql as a web-based database platform for Ann
Letter station: BBS Water Wood Tsinghua Station (Thu 20 16:00:28 2000)

The following describes the installation and configuration method for using Apache+php3+postgresql as a web-based database platform

More about Apache, PHP3, and PostgreSQL can be included with documentation from the software, Linux howto files

And the following sites find:
1. Installation and setup of PostgreSQL
1.1 Get Source program
PostgreSQL the latest version of the source program can be found in http://www.postgresql.org. The latest version of the current

Is 6.5.X. The following example shows the installation method in version 6.4.
1.2 Preparation work
Compiling PostgreSQL requires GNU make (with Gmake-v check version number) above 3.75 version, 2.7.2 version above

GNU C (check version number with GCC-V) as well as bison and flex (usually both of these tools are already installed).
The default installation location for PostgreSQL is/usr/local/pgsql/, and the system files need 3-10m space. The accompanying test
The program needs about 20M of space to run, so you should pay attention to reserving enough space when installing, suggest/USR/LOCAL/PG
The catalogue is guaranteed to have more than 50M space. In addition, expand and compile the source program approximately need 30-60m space.
For a multiuser application environment, it is recommended that you set up a dedicated user name, such as Postgres:
$ su First log in as root
#/usr/sbin/adduser Postgres
In addition, PostgreSQL uses the shared memory mechanism of System V. The FreeBSD default state does not support this mechanism. If the
The kernel in the settings file does not have the following items that need to be appended to recompile the kernel:
Options Sysvshm
Options Sysvsem
Options Sysvmsg
Build the directory/usr/local/src/pgsql and installation directory for the Save source program/usr/local/pgsql:
#chown Postgres:postgres/usr/local/pgsql
#chown Postgres:postgres/usr/local/src/pgsql
1.3 Compiling
To Postgres user login, extract the source program:
# su Postgres
$ tar-xzvf/tmp/postgresql-v6.4.tar.gz [Assuming the download file is saved in the/tmp directory]
When you are finished, you should generate a postgresql-v6.4 directory, and start compiling the following:
$ cd/usr/local/src/pgsql/postgresql-v6.4/src
Where--with-mb= specifies the system default character encoding. In addition to GB code (EUC_CN), can also be specified as Japanese
(EUC_JP), Korean (EUC_KR), Taiwan (EUC_TW), UNICODE, mule_internal, LATIN1 and so on.
Note that if you use the 6.3.2 version of the--with-template= ... Specify the operating system, specific content see the source program comes with
's documentation.
Configure, such as the successful completion, will generate Gnumakefile,makefile.global and makefile.port files.

$ gmake All
The following information is displayed after the compilation finishes:
All of the PostgreSQL is successfully made. Ready to install.
$ gmake Install
After normal completion, PostgreSQL's execution files and library files will be installed into the/usr/local/pgsql directory.

To install the accompanying documentation:
$ gmake Install-man
$ cd/usr/local/src/postgresql-v6.4/doc
$ make Install
The compile installation for this PostgreSQL is complete, and the initial setting begins below.
1.4 Initial setting
To set environment variables:
If the shell you are using is bash, add the following command in. 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"
Then execute the source ~/.BASHRC
If the shell you are using is CSH/TCSH, add the following command in. 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"
Then execute the source ~/.CSHRC
The above environment variables are set by all users who use the database.
Initialization of the database directory:
$ initdb
Parameters you can use:
--PGDATA=/PGSQL/DB Specifies the database directory, using the environment variable pgdata the specified location by default
--PGENCODING=EUC_CN the character encoding of the specified database, using the encoding specified by default when configure.
It is to be noted that the user performing the INITDB will have administrative rights to the database directory being built.
Start PostgreSQL using the following command:
$ postmaster-s
To run the test program:
$ CD Test/regression
$ gmake All Runtest
If the test program can run normally, it shows that PostgreSQL can run normally.
To enable PostgreSQL to start automatically when the system starts, the following changes are required:
First log in as root
$ su
Linux: Append the following in/etc/rc.d/rc.local:
If [-X $POSTGRESDIR/bin/postmaster-a-D $POSTGRESDIR/data];then
Su-postgres-c "Postmaster-s-I."
Echo-n ' postmaster '
FreeBSD: Create a file named Pgsql.sh in/usr/local/etc/rc.d, which reads:
#! /bin/sh
If [-X $POSTGRESDIR/bin/postmaster-a-D $POSTGRESDIR/data];then
Su-postgres-c "Postmaster-s-I."
Echo-n ' postmaster '
To modify the permissions of the pgsql.sh file:
# chmod 755 pgsql.sh
Now the installation and setup of PostgreSQL is almost complete, but the only users who can use the database so far are
To enable other users to use the database, you need to log on to the database user and generate the user data.
For example, a user who queries via Web server Apache has a username of 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
Delete user can use command destroyuser user name
PostgreSQL can manage multiple databases at the same time (but no join operations between databases). New Database

$ createdb Database name
The new database will be placed under the same directory as/usr/local/pgsql/data/base (environment variable pgdata specifies

The base directory of the path). If the database name parameter is omitted, the user name is automatically used as the database name.
For example, a database named DB1 will be saved in the/USR/LOCAL/PGSQL/DATA/BASE/DB1 directory.
You can also use the initlocation command to specify a different location:
$ initlocation/pgsql/data
$ Export Pgdata2=/pgsql/data
$ createdb-d PGDATA2 DB2
The database DB2 will be saved in the/pgsql/data directory. In addition, PostgreSQL version 6.4 can be established in the database
Specify text encoding:
Createdb-e "character encoding" "character encoding" see
Configure, Initdb.
Delete database: Destroydb database name
PostgreSQL's most basic database management tool is pgsql. Basic how to use: Pgsql database name
1.5 Security settings:
PostgreSQL provides host-based authentication mode host based authentication (HBA), password-based

Security mechanisms such as user identity authentication and user operation rights setting.
1.5.1 HBA mode and password-based user identity authentication method
The setup file for HBA mode is pg_hba.conf. The format is:
Host dbname ip_address address_mask Usrauth [auth_argument]
Host: Fixed flag, cannot modify
dbname: Database name, all on behalf of all databases
Ip_address,address_mask: Specifies an IP address, or a subnet, such as a
Userauth: The user's authentication methods, including ident (RFC1413), trust (not certification), reject
(Denial of eligible access), password [passwd_file] (authenticated according to flat file password files)

Crypt (authenticated using the PostgreSQL system database Pg_shadow), KBR4/KBR5 (Kerberos v4/v
5 recognize
Certificate). If used as a Web database, you can set up local logins using the passwd password file as follows:
Host all password passwd
The default location for passwd files is/usr/local/pgsql/data, and users with database administrative permissions can use the
PG_PASSWD command to manage the file (note: The Flat file password authentication method uses plaintext to transmit the password, so from the net
Other host to log on, it is recommended to use the Crypt authentication method.
1.5.2 User Action permission settings
Use SQL command Grant/revoke to set up a user/user group to use Select/insert/update/rule
According to the SQL standard, a data table file (table) can only be accessed by the user who created the table file when it was first established.

To assign access rights to users, you can use the GRANT command:
Grant < permission type > on to < user/group >
Permission type: All,select,insert,update,delete,rule
Table Name: Tables file with user access permissions set
User/Group: public (all users) or user name/group name
The revoke command function is the opposite of the grant command, as follows:
Revoke < permissions > on from < user/group >
The user rights that the table has set can be viewed using the Pgsql \z command.
2. Installation and setting of APACHE+PHP3
2.1 Source Program
The latest versions of Apache and PHP3 source programs can be from http://www.apache.org/and http://www.php.net
The following is an example of Apache 1.3.6 and PHP3 3.0.5.
2.2 Compiling
Suppose that both Apache and PHP3 source programs are saved in the/tmp directory, first log in as root:
$ su
# tar-xzvf/tmp/apache_1.3.6.tar.gz
# 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
The final step will be to create the/USR/LOCAL/SRC/APACHE_1.3.6/SRC/MODULES/PHP3 directory and the following files

Copy to this directory:
Makefile.libdir libmodphp3.a mod_php3.c Php_version.h
Makefile.tmpl Libphp3.module mod_php3.h
Compiling and installing Apache:
Set environment variables Ld_library_path CSH and tcsh Shell use the following command:
# setenv Ld_library_path/usr/local/pgsql/lib
SH and bash use the following command:
# Ld_library_path=/usr/local/pgsql/lib
# Export Ld_library_path
And then
# cd/usr/local/src/apache_1.3.6
# make
# make Install
2.3 Modify settings file
# cd/usr/local/src/php-3.0.5
# CP Php3.ini-dist/usr/local/lib/php3.ini
Remove the # number in front of the two lines in/usr/local/apache/etc/srm.conf, if the. php3 as Ph
File extension, the. phtml is changed to. PHP3:
#AddType application/x-httpd-php3. php3
#AddType Application/x-httpd-php3-source. Phps
Add index.php3 under the DirectoryIndex of the srm.conf file:
DirectoryIndex index.html index.php3
2.4 Start Apache
#/usr/local/apache/sbin/apachectl Start
Apachectl START:HTTPD started
Start the Web browser on the local machine, and the address bar enters http://localhost/(or browse on another computer)
The Address bar to enter the Apache server address), if you can show the beginning of Apache, Apache has
The installation was successful. The following test PHP3 module is working correctly:
# cd/usr/local/apache/share/htdocs/
# ln-s/usr/local/src/php-3.0.5.
Then enter HTTP://LOCALHOST/PHP-3.0.5/EXAMPLES/DATE.PHP3 in the browser's address bar
Observe if the PhP3 file is running correctly. If the DATE function shows the correct result, the PHP3 module works
Thus, the installation of PostgreSQL database system based on Apache Web server and server-side scripting language PHP3
has completed:-)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.