0

I've just setup a basic LAMP server using CentOS 7 and have created 2 PHP files

PHP file 1: index.php

<?php
        echo "hello world";

        phpinfo();
?>

PHP file 2: database.php

<?php
        $conn = mysql_connect('localhost', 'removed_actual_username', 'removed_actual_password') or die('Error connecting to mysql');
        mysql_select_db('database1') or die('Database does not exist');
        print 'All OK!';
?>

index.php works fine, but database.php does not work.

database.php gives me the following error:

Forbidden

You don't have permission to access /database.php on this server.

The permissions of both files are as follows:

[root@localhost html]# ls -al
total 8
drwxr-xr-x. 2 oshirowanen oshirowanen  41 Sep 15 10:12 .
drwxr-xr-x. 4 root     root      31 Sep 14 12:01 ..
-rw-r--r--. 1 oshirowanen oshirowanen 181 Sep 15 10:11 database.php
-rw-r--r--. 1 oshirowanen oshirowanen  43 Sep 15 10:13 index.php
[root@localhost html]# 

Any idea what I have done wrong or missed?

UPDATE 1:

The PHP version is 5.4.16

oshirowanen
  • 15,297
  • 82
  • 198
  • 350
  • If you are the author of the `database.php`, please consider using updated database connector as `mysql_*` function are deprecated and subject to security and performance issues. – Anwar Sep 15 '16 at 09:23
  • have you edited your phpmyadmin.conf file ? – Bhavin Sep 15 '16 at 09:23
  • Are running a site under a folder tree owned by `root`? That's already strange. But since `index.php` is working, I have the feeling the issue must be somewhere in your apache configuration, and not your directory structure. – Ben Hillier Sep 15 '16 at 09:27
  • Does database.php work with an echo like your other file? Which Php version? Could this be the fact there is no mysql module in Php 7? – Progrock Sep 15 '16 at 09:27
  • @Progrock, I've just changed the database.php file to a simple hello world echo, and it works fine. – oshirowanen Sep 15 '16 at 09:32
  • Do you have the entries for mysql listed in phpinfo's output? – Progrock Sep 15 '16 at 09:33
  • @Progrock, yes, I can see many references to mysql in phpinfo. Although, I am using MariaDB, not sure if that is the reason for the problem? – oshirowanen Sep 15 '16 at 09:36
  • @Progrock, also, I'm using PHP 5.4.16. – oshirowanen Sep 15 '16 at 09:36
  • Can you connect to the mysql (maria) server from the CLI? – Progrock Sep 15 '16 at 09:38
  • @Progrock, yes, no problem connecting to the mysql server at all using `mysql -u [username goes here] -p` – oshirowanen Sep 15 '16 at 09:44
  • @Progrock, and `select * from mysql.user` returns the username and localhost row being used in database.php. – oshirowanen Sep 15 '16 at 09:45
  • Which hosts? Try connecting via the IPv4: 127.0.0.1. Did you restart apache (straw clutching)? – Progrock Sep 15 '16 at 09:47
  • How did you install mariadb and php mysql? Please embellish question. – Progrock Sep 15 '16 at 09:53
  • Have you specified an entry in php's config for error_log? If so can apache write to that file? Try triggering a syntax error your echo file. – Progrock Sep 15 '16 at 10:04
  • @Progrock, 127.0.0.1 gives same issue. Apache has been restarted, still have the same issue. mariadb was installed using the command `yum install mariadb-server mariadb`. Also apache can write to the error_log `[Fri Sep 16 15:07:54.161661 2016] [:error] [pid 2817] [client ::1:47974] script '/var/www/html/database2.php' not found or unable to stat`. Entry created just now. – oshirowanen Sep 16 '16 at 14:06
  • From which repos are you installing mariadb/php from? – Progrock Sep 17 '16 at 10:10
  • A bit of searching around threw up some references to selinux. Try: `setsebool -P httpd_can_network_connect_db 1`. – Progrock Sep 17 '16 at 10:26

0 Answers0