1

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...

simbabque
  • 53,749
  • 8
  • 73
  • 136
Luciano Jeong
  • 325
  • 1
  • 10
  • 1
    The "_Please help me_" in the title will do opposite to helping you. I removed it. – zdim Aug 03 '17 at 09:26
  • First things first: Welcome to SO! I see you read the Guide on how to ask a good question. Nice! – Gewure Aug 03 '17 at 09:42
  • Second things second: @Сухой27 i really don't see why this is "exact duplicate" of an existing question. It clearl isn't. The answer you linked is a "general guide" - not anything into detail/specific - but that is clearly what is needed/asked here. Marking-Madness, much? Mods: please unmark as duplicate. it isn't. – Gewure Aug 03 '17 at 09:49
  • @Gewure OP can find valuable information on mentioned page since: `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.` strongly suggests that this is the case. – mpapec Aug 03 '17 at 10:02
  • https://stackoverflow.com/questions/2165022/how-can-i-troubleshoot-my-perl-cgi-script would also benefit by adding this https://stackoverflow.com/a/30617910/223226 – mpapec Aug 03 '17 at 10:08
  • 1
    @Сухой27 "setsebool -P httpd_can_network_connect_db on" it works!! thanks – Luciano Jeong Aug 03 '17 at 11:03
  • 2
    @Gewure there are no _mods_ in the sense that you mean here. Moderators do not reopen questions. The community does. Once you have enough reputation, you'll be able to cast reopen votes. Just like with close votes, a question needs 5 of those to be reopened, unless one of the voters has the hammer, like Сухой27 did with closing. If I'd vote to reopen, that would suffice as I also hold a gold Perl tag badge. However I am not going to do it, because I am not qualified to make that decision. The moderators have nothing to do with it though. – simbabque Aug 03 '17 at 12:56
  • 1
    @Сухой27 I added the other link to the duplicates' list, as you said and OP confirmed – zdim Aug 03 '17 at 18:19

0 Answers0