0

Edited: This is not a duplicate - other questions suggested are not the same situation. In this case, MOST html files with PHP work, there's just one file that does not work. Also, all of the answers suggested for the other problem do not solve this problem, as I have mentioned below.

We're in the middle of a transition from a CentOS 6.1 server to a CentOS 7.5 server. Versions of Apache and PHP are the same across both servers, and files are all the same. However, when I try to access my homepage (named index.html) the PHP is not executed and instead commented out in the html. Every other page on the site executes PHP fine.

  • AddType for PHP in .html files is added.
  • No short tags are being used.
  • Apache is including the same .conf and .htaccess files in both set ups.
  • Apache version 2.4.34 on both servers
  • Php version is 7.2.10 on both servers

Does anyone have any idea what I could be doing wrong here, or how I could test this? Thanks so much!

mcheah
  • 1,209
  • 11
  • 28
  • How `PHP` code can execute in `HTML` file? – Muhammad Usman Oct 01 '18 at 22:43
  • @MuhammadUsman like so: https://httpd.apache.org/docs/2.4/mod/mod_mime.html#addtype – mcheah Oct 01 '18 at 22:45
  • It is not typical to run PHP inside .html files, but obviously not impossible. Assuming "every other page" that works is a .php file (important to tell us if not) then it does seem that your AddType is failing, or there is a conflicting configuration. Would you paste your AddType line? Something like: AddType application/x-httpd-php .php .html .htm – Design.Garden Oct 01 '18 at 22:51
  • Maybe this can help: https://stackoverflow.com/questions/22853669/how-to-run-a-php-script-inside-a-html-file – Muhammad Usman Oct 01 '18 at 22:51
  • @mattavatar all other files are html too. In my setup, PHP files exclusively template files or scripts, not files that are directly served to the client. My AddType line is: `AddType application/x-httpd-ea-php72 .php .php7 .phtml` in both configurations – mcheah Oct 01 '18 at 22:57
  • @mcheah, does your application use pretty-urls? If so then your web server config may be handling things differently based on whether you are or are not navigating directly to the file. Try navigating directly to another "working" html file on your server (/actual/directory/file.html) -- does the PHP run or get printed out? – Design.Garden Oct 01 '18 at 23:03
  • @mattavatar thanks, I can navigate directly to html files and it will work fine. – mcheah Oct 02 '18 at 14:25
  • @mcheah, I just noticed that your "AddType" does not cover ".html"; instead, it covers ".phtml" -- so, I would expect that index.html would NOT be executed as a PHP file. Considering your AddType configuration then I can safely say that, despite that index.html works on the previous server, on this server it should be renamed to "index.phtml". Why does it work on the previous server? Any number of oddball reasons... for instance, the apache config on the previous server may have been changed to something incorrect after being started, so the active config is different than what in the files. – Design.Garden Oct 02 '18 at 16:38
  • @mcheah, any update on this? – Design.Garden Oct 04 '18 at 17:41
  • @mattavatar Thanks for following up. I am an idiot and didn't actually check my html file. Somehow only the index page actually had the PHP code commented out in the file itself, so once I reverted it to the original file it worked fine. The migration must have triggered it though I have no idea how or why. Sorry for wasting your time! – mcheah Oct 05 '18 at 19:12

2 Answers2

0

Are you sure that php is indeed not working? can you try adding a php echo to top of the page and see if it prints the given test text?

If both configuration files are same and all files are identical, I suspect the problem could be the location of the files and configuration not matching. If your configs are for /var/some/directory but on new setup, you moved files to new location which is /var/new/location, then config files might not work as intended.

  • thanks, I'm sure it's not working. Any idea where I should look for config files that might be out of place? I have a basic .htaccess file in the root dir, I have the httpd.conf in `/etc/apache2/conf` which is generated by all the .conf files in `/etc/apache2/conf.d`. Not sure where else I should be checking. Thanks! – mcheah Oct 02 '18 at 14:27
0

Is SELinux enabled? If it is and you're using a non-default directory for your content, you may need to set the context for the custom directory.

# chcon -R -t httpd_sys_content_t /srv/mysite
JuanKman94
  • 112
  • 1
  • 7