Skip to content
Advertisement

Why does PHP 7.4 with mysqli only run in root directory? [closed]

Recently my hosting site (HostGator) upgraded my site’s PHP from 5.4 to 7.4. Pages that had php with mysqli statements in them failed, after working without incident in version 5.4. Code like:

<body>
<?php include("menu_primary.html");?>
Some text
<?php 
    $servername = "localhost";
    $username = "my_username";
    $password = "my_password";
    $database = "my_database";
    
    // Create connection
    $link = mysqli_connect($servername, $username, $password, $database);
        // Check connection
        if (!$link) {
            die("Connection failed: " . mysqli_connect_error());
        }   

would fail on the statement: mysqli_connect($servername, $username, $password, $database);
but the statement <?php include("menu_primary.html");?> would execute fine. After a lot of trial and error, I got the idea to move the entire PHP file from the folder /public_html/my_app to the folder /public_html . Then everything worked fine again.
Those two files were edited as part of the upgrade from PHP 5.4 to PHP 7.4.
Question: Is there something I have to do in the /public_htmnl/.htaccess or the /public_html/php.ini files to allow embedded PHP to execute in a directory subordinate to /public_html ? Thanks for looking at this.

Advertisement

Answer

After many days I got an answer from my hosting company. The file .htaccess was the problem. When the site upgraded from 5.4 to 7.4 it added the following line:

suPHP_ConfigPath /home2/susanna

The public_html folder is subordinate to that path. Their escalated support commented out the entire section that was added:

#<IfModule mod_suphp.c>
# suPHP_ConfigPath /home2/susanna
 #<Files php.ini>
#   order allow,deny
#   deny from all
# </Files>
#</IfModule>

Now the PHP code (executing on php 7.4) can be called from a subordinate directory.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement