Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6811571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:20:39+00:00 2026-05-26T20:20:39+00:00

I have a very simple test script: <?php $DSN = "mysql:host=db.example.edu;port=3306;dbname=search_data"; try { $DB

  • 0

I have a very simple test script:

<?php

$DSN = "mysql:host=db.example.edu;port=3306;dbname=search_data";

try {
    $DB = new PDO($DSN, "username", "super-secret-password!");
} catch (PDOException $e) {
    header('Content-Type: text/plain');
    print "Could not connect to database, rawr. :-(";
    exit;
}

$SQL = "SELECT phrase FROM search ORDER BY RAND() LIMIT 10";

foreach ($DB->query($SQL) as $row) {
    print $row['phrase']."\n";
}

?>

When I execute this script from the command line, it works perfectly:

$ php test.php
corporal punishment
Stretches
voluntary agencies and the resettlement of refugees
music and learning
Nike Tiger Woods Scandal
Hermeneia
PSYCHINFO
anthony bourdain
Black-White Couples and their Social Worlds
colonization, hodge

But when I access the exact same script through my web browser, it says:

Could not connect to database, rawr. :-(

I’ve tried var_dump on the error, and the message is: "SQLSTATE[HY000] [2003] Can’t connect to MySQL server on ‘db.example.edu’ (13)".

This is puzzling. It’s the exact same script on the exact same server — why does it work when I execute it from the command line, but fail when Apache executes it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T20:20:40+00:00Added an answer on May 26, 2026 at 8:20 pm

    If this is a Red Hat-derived distribution (RHEL, CentOS, Fedora, ScientificLinux) running SELinux (or any non Red Hat derivative using SELinux), the default policy setting at time of this writing is to prohibit Apache from making external connections to other servers or databases. As root, you must enable the following two SELinux booleans. Use the -P option to persist the change across a reboot.

    setsebool -P httpd_can_network_connect=1
    setsebool -P httpd_can_network_connect_db=1
    

    Note that httpd_can_network_connect may not be necessary. Try it first turning on only httpd_can_network_connect_db.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very simple test page for PHP session. <?php session_start(); if (isset($_SESSIONS['views']))
I have a very simple question. I want to test whether a particular port
I have a very simple test program, running on Solaris 5.8: #include <stdio.h> #include
I have recorded a very simple test case Using the Selenium IDE integrated with
I have a very simple unit test that just allocates a lot of Strings:
I am using SQL Server 2008 Enterprise. I have created a very simple test
Writing a test app to emulate PIO lines, I have a very simple Python/Tk
I'm trying to create a very simple REST server. I just have a test
I have a simple question related to one-line programming. First an example: function test(a)
I have downloaded and added this very simple, one file, php web file explorer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.