I have to configure Apache + Perl + PostgreSQL on CentOS 7 which kernel's version is 3.10.0-514.el7.x86-64. Because the server I have to configure is separated from WAN, I downloaded Everything ISO image. First, I installed CentOS in Minimal Install, using Everything ISO, not connecting to the Internet.
In this clean status, I mounted CD-ROM.
# mount /dev/cdrom /media/cdrom
then, I installed lynx and wget.
# yum --disable-repo=\* --enable-repo=c7-media install lynx wget
It was successful. and I installed Perl.
# yum --disable-repo=\* --enable-repo=c7-media install perl
It was also successful. and I intalled Apache.
# yum --disable-repo=\* --enable-repo=c7-media install httpd
It was also successful. and I modified httpd.conf like this:
<Directory "/var/www/cgi-bin">
AllowOverride None
Options +ExecCGI
AddHandler cgi-script .pl .cgi
Require all granted < /Directory >
and I wrote a test page(chmod a+x applied) and it works well.
However, the problem is Postgre SQL.
I installed it by entering
# yum --disable-repo=\* --enable-repo=c7-media install postgresql postgresql-server postgresql-contrib postgres-devel
# yum --disable-repo=\* --enable-repo=c7-media install perl-DBD-Pg
and I initialized by entering
# postgresql-setup initdb
and started the daemon.
# service postgresql start
and set a password the account of 'postgres' on unix
# passwd postgres
and set the same password of the account 'postgres' on PSQL
# psql --username=postgres
POSTGRES # alter user postgres encrypted password '1234asdf';
and set the authorization method to MD5 in /var/lib/pgsql/data/pg_hba.conf
local all all trust
host all all 127.0.0.1/32 md5
host all all ::1/128 md5
I restarted the daemon.
** Now, I wrote an example:
#!/usr/bin/perl
use DBI;
use strict;
my $driver = "Pg";
my $database = "postgres";
my $host="127.0.0.1";
my $connstr = "DBI:$driver:dbname=$database;host=$host";
my $userid = "postgres";
my $userpw = "1234asdf";
my $dbconn = DBI->connect($constr, $userid, $userpw, { RaiseError => 1 }) or die $DBI::errstr;
print "Content-type: text/html\n\n";
print disconnect();
When I run on terminal(eg. # ./foo.cgi), it works without any error. HOWEVER When I run on the browser, It shows HTTP 403 Error.
error_log is below::
[Fri Aug 04 02:10:27.471889 2017] [cgi:error] [pid 2231] [client 127.0.0.1:48724] AH01215: DBI connect('dbname=postgres;host=127.0.0.1;','postgres',...) failed: could not connect to server: Permission denied
[Fri Aug 04 02:10:27.471959 2017] [cgi:error] [pid 2231] [client 127.0.0.1:48724] AH01215: \tIs the server running on host "127.0.0.1" and accepting
[Fri Aug 04 02:10:27.471975 2017] [cgi:error] [pid 2231] [client 127.0.0.1:48724] AH01215: \tTCP/IP connections on port 5432? at /var/www/cgi-bin/cc.cgi line 14.
What can I do for this situation? I'm in trouble for several days...