0

So I installed Php70* on my amazon Linux Server, and have apache (httpd) installed and when i go to view the php page on my browser, it downloads the php file instead of showing on the browser.

I tried different browsers, clearing the cache, checking the permissions to my php files and the error perists.

here is what I have on my system hope it helps; Anything else I could be missing? Any help is appreciated.

(i have a simple php file called "phpinfo.php" and in it is

on my ec2 instance at the terminal i can successfully do php phpinfo.php

php -v
PHP 7.0.14 (cli) (built: Jan 18 2017 19:13:23) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.14, Copyright (c) 1999-2016, by Zend Technologies

httpd -v
Server version: Apache/2.4.25 (Amazon)
Server built:   Jan 19 2017 16:55:49

I got all php70 packages installed:

sudo yum list installed php70*
Loaded plugins: priorities, update-motd, upgrade-helper
Installed Packages
php70.x86_64                  7.0.14-1.20.amzn1                    @amzn-updates
php70-bcmath.x86_64           7.0.14-1.20.amzn1                    @amzn-updates
php70-cli.x86_64              7.0.14-1.20.amzn1                    @amzn-updates
php70-common.x86_64           7.0.14-1.20.amzn1                    @amzn-updates
php70-dba.x86_64              7.0.14-1.20.amzn1                    @amzn-updates
php70-dbg.x86_64              7.0.14-1.20.amzn1                    @amzn-updates
php70-devel.x86_64            7.0.14-1.20.amzn1                    @amzn-updates
php70-embedded.x86_64         7.0.14-1.20.amzn1                    @amzn-updates
php70-enchant.x86_64          7.0.14-1.20.amzn1                    @amzn-updates
php70-fpm.x86_64              7.0.14-1.20.amzn1                    @amzn-updates
php70-gd.x86_64               7.0.14-1.20.amzn1                    @amzn-updates
php70-gmp.x86_64              7.0.14-1.20.amzn1                    @amzn-updates
php70-imap.x86_64             7.0.14-1.20.amzn1                    @amzn-updates
php70-intl.x86_64             7.0.14-1.20.amzn1                    @amzn-updates
php70-json.x86_64             7.0.14-1.20.amzn1                    @amzn-updates
php70-ldap.x86_64             7.0.14-1.20.amzn1                    @amzn-updates
php70-mbstring.x86_64         7.0.14-1.20.amzn1                    @amzn-updates
php70-mcrypt.x86_64           7.0.14-1.20.amzn1                    @amzn-updates
php70-mysqlnd.x86_64          7.0.14-1.20.amzn1                    @amzn-updates
php70-odbc.x86_64             7.0.14-1.20.amzn1                    @amzn-updates
php70-opcache.x86_64          7.0.14-1.20.amzn1                    @amzn-updates
php70-pdo.x86_64              7.0.14-1.20.amzn1                    @amzn-updates
php70-pdo-dblib.x86_64        7.0.14-1.20.amzn1                    @amzn-updates
php70-pecl-apcu.x86_64        5.1.5-2.2.amzn1                      @amzn-main   
php70-pecl-apcu-devel.x86_64  5.1.5-2.2.amzn1                      @amzn-main   
php70-pecl-igbinary.x86_64    1.2.2-0.1.20151217git2b7c703.5.amzn1 @amzn-main   
php70-pecl-igbinary-devel.x86_64
                          1.2.2-0.1.20151217git2b7c703.5.amzn1 @amzn-main   
php70-pecl-imagick.x86_64     3.4.2-1.4.amzn1                      @amzn-main   
php70-pecl-imagick-devel.x86_64
                          3.4.2-1.4.amzn1                      @amzn-main   
php70-pecl-memcache.x86_64    3.0.9-0.4.20160311git4991c2f.8.amzn1 @amzn-main   
php70-pecl-memcached.x86_64   3.0.0-0.1.20160217git6ace07d.2.amzn1 @amzn-main   
php70-pecl-oauth.x86_64       2.0.2-1.2.amzn1                      @amzn-main   
php70-pecl-ssh2.x86_64        1.0-5.16.amzn1                       @amzn-main   
php70-pecl-uuid.x86_64        1.0.4-7.1.amzn1                      @amzn-main   
php70-pecl-yaml.x86_64        2.0.0-1RC8.3.amzn1                   @amzn-main   
php70-pgsql.x86_64            7.0.14-1.20.amzn1                    @amzn-updates
php70-process.x86_64          7.0.14-1.20.amzn1                    @amzn-updates
php70-pspell.x86_64           7.0.14-1.20.amzn1                    @amzn-updates
php70-recode.x86_64           7.0.14-1.20.amzn1                    @amzn-updates
php70-snmp.x86_64             7.0.14-1.20.amzn1                    @amzn-updates
php70-soap.x86_64             7.0.14-1.20.amzn1                    @amzn-updates
php70-tidy.x86_64             7.0.14-1.20.amzn1                    @amzn-updates
php70-xml.x86_64              7.0.14-1.20.amzn1                    @amzn-updates
php70-xmlrpc.x86_64           7.0.14-1.20.amzn1                    @amzn-updates
php70-zip.x86_64              7.0.14-1.20.amzn1                    @amzn-updates

I saw people mentioning to change the /etc/httpd/conf/httpd.conf file to include addtype/handler so here is what I have:

grep -n "php" /etc/httpd/conf/httpd.conf
54:LoadModule php7_module   modules/libphp-7.0.so
163:    DirectoryIndex index.html index.php
175:    SetHandler application/x-httpd-php
287:    AddType application/x-httpd-php .php
288:    AddType application/x-httpd-php-source  .phps
301:    AddHandler php7-script  .php
302:    AddHandler application/x-httpd-php .phps
303:    AddHandler application/x-httpd-php .php

I also have the short_open_tags=on just in case:

grep short_open_tag php-7.0.ini
; short_open_tag
short_open_tag = On

grep short_open_tag php.ini
; short_open_tag
short_open_tag = On
jonathan1987
  • 251
  • 1
  • 6
  • 17
  • This is a long shot but how do you access the page? By url or by clicking on it in your directory listing? – davejal Feb 21 '17 at 14:38
  • maybe add execute permissions to your file? I have not encountered this issue so I am going full guessmode. – Dimi Feb 21 '17 at 14:40
  • i access the phpsite by going to http://mydomain/phpinfo.php – jonathan1987 Feb 21 '17 at 14:53
  • `public_html]$ ls -lt *.php -rwxrwxrwx 1 root root 26 Feb 21 07:23 test.php -rwxrwxrwx 1 root root 20 Feb 21 06:04 phpinfo.php` – jonathan1987 Feb 21 '17 at 14:56
  • also did a stop/start of httpd service and still nothing. – jonathan1987 Feb 21 '17 at 14:59
  • The issue here is clearly that the PHP module is not loaded / not called. Any interesting apache logs ? Did you restart your Apache after installing PHP modules ? – NaeiKinDus Feb 21 '17 at 16:29
  • If your Apache loads .htaccess files, could you try to create one in your project's root dir with the following content: ` SetHandler application/x-httpd-php ` – NaeiKinDus Feb 21 '17 at 16:33
  • i have the `FilesMatch \.php$> SetHandler application/x-httpd-php ` in my /etc/httpd/conf/httpd.conf file also above mentions that it prevevents .htaccess and .htpasswd files from being viewed by Web Clients. ` Require all denied ` – jonathan1987 Feb 21 '17 at 16:59

1 Answers1

0

I've been through the same issue too for about two days. This [link][1] solved mine!

If any of the solutions in that link doesn't work, then here are a few other things to checkout for:

  1. Advisably, uninstall php* entirely and install a new one. Be sure of the version of php you installed. You can check with php -v

  2. Work on your .htaccess file. It might be causing a download for you instead of executing your script (in some cases)

  3. Check your httpd/apache2 config files: This is very important! If you mapped the wrong or incorrect module in your config file, it can cause issues.

Check out directives such as AddHandler and AddType. It should look like the below for PHP:

AddType  application/x-httpd-php         .php
AddType  application/x-httpd-php-source  .phps

AddHandler application/x-httpd-php52 .php

This can vary depending on your PHP version.

  1. Make sure you have php-.so (linux) or php-.dll (windows) in your apache/httpd module folder (That's to be extra sure that php is enabled and that php is loaded for apache correctly).

  2. If any of these still doesn't work out,Restart your server and Hard Reload/Clear Browser Cache. Then Reload Page.

Devmaleeq
  • 541
  • 6
  • 9