Recently, I am preparing to create a project to use PostgreSQL. Of course, I have to install PostgreSQL on the server. The installation is a little more troublesome than MySQL, and the record is as follows.
1. Compile and install PostgreSQL 8.4.2
Reference
Wget http://wwwmaster.postgresql.org/redir/391/f/source/v8.4.2/postgresql-8.4.2.tar.gz
Tar zxvf postgresql-8.4.2.tar.gz
CD postgresql-8.4.2
./Configure -- prefix =/usr/local/pgsql
Make
Make install
2. Create a PostgreSQL user. Because PostgreSQL cannot be initialized and started using root, you must create a new user.
Reference
PW groupadd pgsql
PW useradd pgsql-G pgsql-D/data/pgsql-S/bin/CSH
3. Create a PostgreSQL data storage directory
Reference
Mkdir-P/data/pgsql/Data
Chown-r pgsql: pgsql/data/pgsql/
4. initialize the database
Reference
Su pgsql/usr/local/pgsql/bin/initdb-D/data/pgsql/data-e utf8
5. Modify the PostgreSQL Startup File
Reference
CP contrib/start-scripts/FreeBSD/usr/local/pgsql
VI/usr/local/pgsql
# Modify pgdata =/usr/local/pgsql/Data
# For pgdata =/data/pgsql/Data
# Modify pguser = Postgres
# Pguser = pgsql
# Save and exit
VI/etc/rc. Local
# Add/usr/local/pgsql start
# Save and exit
So far, even if PostgreSQL is installed, the next step is to install PostgreSQL support for PHP.
1. Create a libpq. so.5 link.
Reference
Ln-S/usr/local/pgsql/lib/libpq. so.5/usr/lib/libpq. so.5
2. recompile PHP
Reference
. /Configure -- prefix =/usr/local/PHP -- With-config-file-Path =/usr/local/PHP/etc -- With-mysql =/usr/local/MySQL -- with-mysqli =/usr/local/MySQL/bin/mysql_config -- With-iconv-Dir =/usr -- With-FreeType-dir -- With-JPEG-dir -- With-PNG- dir -- With-zlib -- With-libxml-Dir =/usr/local -- enable-XML -- disable-rpath -- enable-discard-path -- enable-safe-mode -- enable-bcmath -- enable-shmop -- enable-sysvsem -- enable-inline-optimization -- With-curl -- With-curlwrappers -- enable-mbregex -- enable-FastCGI -- enable-FPM -- enable-force-CGI -redirect -- enable-mbstring -- With-mcrypt -- With-Gd -- enable-Gd-native-TTF -- With-OpenSSL -- With-mhash -- enable-pcntl -- enable-sockets -- -XMLRPC -- enable-zip -- disable-ipv6 -- without-pear -- With-pgsql =/usr/local/pgsql
Make zend_extra_libs = '-liconv'
Make install
3. Restart PHP-FPM.
Reference
/Usr/local/PHP/sbin/PHP-FPM stop
/Usr/local/PHP/sbin/PHP-FPM start
If no error is reported, the entire PostgreSQL installation and PHP support will be completed. We wish you a smooth installation.