PHP Installation Introduction: PostgreSQL

Source: Internet
Author: User
Tags date net variables table name version variable access postgresql version
The following will illustrate the use of Apache+php3+postgresql as a web-based database platform for installation and configuration methods. More about Apache, PHP3, and PostgreSQL can be found in the software's accompanying documentation, Linux howto files, and the following sites:
apache:http://www.apache.org
Php3:http://www.php.net
postgresql:http://www.postgresql.org

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 current version 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, 2.7.2 version of GNU C (with Gcc-v check version number) and Bison and flex (usually both of these tools are installed).
The default installation location for PostgreSQL is/usr/local/pgsql/, and the system files need 3-10m space. The accompanying test procedure needs approximately 20M space in the operation, therefore should be careful to set aside the sufficient space in the installment, proposed/usr/local/pgsql/directory to guarantee has 50M above 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 there are no following items in the settings file for the kernel in use, append and 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:
#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 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
$./configure--WITH-MB=EUC_CN

Where--with-mb= specifies the system default character encoding. In addition to GB code (EUC_CN), you can also specify 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, and see the documentation that came with the source program.
Configure, such as the successful completion, will generate Gnumakefile,makefile.global and makefile.port files. $ gmake All displays the following information at the end of compilation: All of the PostgreSQL is successfully made. Ready to install.
Installation: $ 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:
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: Create a name in the/USR/LOCAL/ETC/RC.D named
Pgsql.sh's file, which reads:
#! /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
To modify the permissions of the pgsql.sh file:
# chmod 755 pgsql.sh

The installation and setup of PostgreSQL is now basically complete, but the only users who can use the database so far are postgres.
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 the Web server Apache is named 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 the/usr/local/pgsql/data/base (environment variable pgdata The base directory of the specified 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 specify the text encoding when establishing the database: createdb-e "character encoding" "character encoding" see Configure, Initdb.
Delete database: Destroydb database name
PostgreSQL the most basic database management tool is
Pgsql. Basic how to use: Pgsql database name

1.5 Security settings:
PostgreSQL provides a host-based authentication mode host based authentication (HBA), password based user authentication and user operation permission settings and other security mechanisms.

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 192.168.10.0/255.255.255.0
Userauth: The user's authentication methods, including ident (RFC1413), trust (do not authenticate), reject (deny 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/v5 authentication). If used as a Web database, you can set up local logins using the passwd password file as follows:
Host all 127.0.0.1 255.255.255.255 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: Flat file Password Authentication method uses clear text to transmit password, so to log on from other hosts on the network, it is recommended to use Crypt authentication method).

1.5.2 User Action permission settings
Use the SQL command Grant/revoke to set whether a user/user group can use the Select/insert/update/rule command.

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 found 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
# 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
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
#./configure--activate-module=src/modules/php3/libphp3.a
# 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 # before the following two lines in the/usr/local/apache/etc/srm.conf.
If you use. php3 as the extension of the PHP3 file, 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, the Address bar type http://localhost/(or the Apache server address in the browser's address bar on other computers), and if you can show Apache's start screen, the Apache has been installed successfully. 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 in the address bar of the browser
Http://localhost/php-3.0.5/examples/date.php3
Observe if the PhP3 file is running correctly. If the DATE function shows the correct result, the PHP3 module works fine.
At this point, the installation of the PostgreSQL database system based on the Apache Web server and server-side scripting language PHP3 has been 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.