Apache2 PHP-FPM Postgres On CentOS 6
Apache2 PHP-FPM Postgres On CentOS 6
xx
Update centos
yum y update
Disable SELINUX
sed s/SELINUX=enforcing/SELINUX=disabled/g /etc/selinux/config
Reboot centos
Reboot
for 64bit:
wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.31.el6.rf.x86_64.rpm
for 32bit:
rpm -ivh http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-68.noarch.rpm
for 64bit:
rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-68.noarch.rpm
REMI:
rpm --import http://rpms.famillecollet.com/RPM-GPG-KEY-remi
rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
After that we need to install a plugin for yum that manages repo priorities:
yum install yum-priorities
Then
nano /etc/yum.repos.d/epel.repo
postgresql-9.4 on
Adjust Iptables/Firewall
Add the following line:
iptables -F
iptables -A INPUT -p tcp --tcp-flags ALL NONE -j DROP
iptables
iptables
iptables
iptables
iptables
iptables
iptables
iptables
iptables
iptables
iptables
iptables
iptables
iptables
iptables
iptables
iptables
iptables
-A
-A
-A
-A
-A
-A
-A
-A
-A
-A
-A
-A
-A
-A
-A
-A
-A
-A
INPUT
INPUT
INPUT
INPUT
INPUT
INPUT
INPUT
INPUT
INPUT
INPUT
INPUT
INPUT
INPUT
INPUT
INPUT
INPUT
INPUT
INPUT
-p
-p
-i
-p
-p
-p
-p
-p
-p
-p
-p
-p
-p
-p
-p
-p
-p
-p
Adjust SELinux
Run the following command to make PostgreSQL work if SELinux enabled on your system.
setsebool -P httpd_can_network_connect_db 1
You may not login to PostegreSQL if you didnt run the above command.
Configure PostgreSQL-MD5 Authentication
nano /var/lib/pgsql/9.4/data/pg_hba.conf
[...]
# TYPE
DATABASE
USER
ADDRESS
METHOD
md5
md5
md5
md5
Uncomment both lines, and set the IP address of your postgresql server or set * to listen from
all clients as shown below:
listen_addresses = '*'
port = 5432
If your repository is for a slightly different version of PostgreSQL, then you can use yum search
to find the exact rpm to install:
# yum search postgre | grep odbc
postgresql-odbc.x86_64 : PostgreSQL ODBC driver
postgresql93-odbc.x86_64 : PostgreSQL ODBC driver
The above example shows us that we have ODBC drivers installed on this machine for
connecting to both MySQL and PostgreSQL.
Configure Our ODBC Connections in /etc/odbc.ini
Next, we configure the connection information specfic to our PostgreSQL database. If you
configure the /etc/odbc.ini file, it will work for all users on this machine. If we configure the
$HOME/.odbc.ini file, it will be configured for our specific user only. This is a security feature
that allows you to allow connections for only those users that merit it.
[sallydb]
Description
Driver
Database
Servername
UserName
Password
Port
Protocol
ReadOnly
RowVersioning
ShowSystemTables
ConnSettings
=
=
=
=
=
=
=
=
=
=
=
=
Success! We were able to connect successfully. I can now query the database directly by typing
my SQL at the SQL> prompt.
unixODBC isql Command Usage
We can use isql with the following usage and options:
isql Usage:
isql DSN [UID [PWD]] [options]
isql Options:
-b
-dx
-x0xXX
-w
-c
-mn
-v
-lx
-q
-3
-n
--version
/etc/odbcinst.ini
/etc/odbc.ini
/etc/ODBCDataSources
/root/.odbc.
Add it to services
Installation of PHP-FPM
Install PHP-FPM and mod_fastcgi:
yum -y install php-fpm mod_fastcgi php56w
Restart Apache:
service httpd restart
After that search after FastCgiWrapper and make sure its set to off then save the file.
The /usr/lib/cgi-bin/ directory must exist, so we create it:
mkdir /usr/lib/cgi-bin/
Comment out the AddHandler and AddType lines so it looks like here:
#
# PHP is an HTML-embedded scripting language which attempts to make it
# easy for developers to write dynamically generated webpages.
#
LoadModule php5_module modules/libphp5.so
#
# Cause the PHP interpreter to handle files with a .php extension.
#
Now create the following PHP file in the document root /var/www/html of the default Apache
vhost:
nano /var/www/html/info.php
<?php
phpinfo();
?>
Tunning FPM:
Open /etc/php-fpm.d/www.conf
Change
listen = 127.0.0.1:9000
to
listen = /tmp/php5-fpm.sock
listen.owner = apache
listen.group = apache
Open /etc/httpd/conf.d/fastcgi.conf
Change
to
FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi -socket /tmp/php5-fpm.sock
-pass-header Authorization