0

I am using Amazon EC2, CentOS 7 x64_86, 1GB RAM.

(1) Run command

php -v

result

PHP 7.0.24 (cli) (built: Sep 30 2017 10:10:28) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies

(2) Run command

httpd -v

result

Server version: Apache/2.4.6 (CentOS)
Server built:   Oct 19 2017 20:39:16

(3) Run command

vi /etc/httpd/conf.d/welcome.conf

Result

#
# This configuration file enables the default "Welcome" page if there
# is no default index page present for the root URL.  To disable the
# Welcome page, comment out all the lines below.
#
# NOTE: if this file is removed, it will be restored on upgrades.
#
#<LocationMatch "^/+$">
#    Options -Indexes
#    ErrorDocument 403 /.noindex.html
#</LocationMatch>

<Directory /usr/share/httpd/noindex>
    AllowOverride None
    Require all granted
</Directory>

Alias /.noindex.html /usr/share/httpd/noindex/index.html
Alias /noindex/css/bootstrap.min.css /usr/share/httpd/noindex/css/bootstrap.min.css
Alias /noindex/css/open-sans.css /usr/share/httpd/noindex/css/open-sans.css
Alias /images/apache_pb.gif /usr/share/httpd/noindex/images/apache_pb.gif
Alias /images/poweredby.png /usr/share/httpd/noindex/images/poweredby.png

How to fix it?

Vy Do
  • 46,709
  • 59
  • 215
  • 313
  • (Indeed, I don't need virtual host at this time, because server has small RAM) and I use PHP 7. – Vy Do Oct 28 '17 at 16:17
  • OK ... so the DirectoryIndex goes in main Apache config instead of vhost config file. PHP part should not change, just find the appropriate `LoadModule *php*` as I described. Is that what you mean? – Don't Panic Oct 28 '17 at 16:37
  • I think must install connector between Apache with PHP7, like this https://www.tutorialspoint.com/articles/how-to-update-php-7-on-centos-rhel-7 but I still don't success. – Vy Do Oct 28 '17 at 17:04

1 Answers1

1

You are actually seeing 2 different problems.

Problem 1

Seeing a directory listing, instead of returning index.php. This must be because you have no DirectoryIndex specified. Check your vhost config (something like /etc/httpd/sites-available/your-site.conf not welcome.conf), and add one inside the vhost block, like:

<VirtualHost *:80>
    DirectoryIndex index.php index.html
    // ... rest of your config
</VirtualHost>

Problem 2

Apache is showing the contents of index.php instead of processing it. This means PHP support is not enabled.

  • Look for LoadModule in your Apache config, and make sure some variation of php is there, eg LoadModule php5_module, and it is not commented out.

  • Check you have a MIME type configured in Apache config, eg AddType application/x-httpd-php .php, and it is not commented out.

References for this problem:

PHP code is not being executed, instead code shows on the page

HTTPd shows PHP code instead of executing it

Don't Panic
  • 13,965
  • 5
  • 32
  • 51