12

I'm using Apache 2.4 on Ubuntu 16.04, it shows the content of the index.php in browser.

enter image description here

here's the code of my site's conf file:

<VirtualHost *:80>

        DocumentRoot /var/www/laravel/public
        ServerName laravel.dev

        <Directory /var/www/laravel/public>
            Options Indexes FollowSymLinks
            AllowOverride All
            Require all granted
        </Directory>
</VirtualHost>

Why the home page renders index.php as text file?

Note: I have set 777 permissions to laravel folder. PHP is also installed.

Faizan Ali
  • 973
  • 2
  • 16
  • 32
  • 1
    Possible duplicate of [why are my php files showing as plain text?](http://stackoverflow.com/questions/3555681/why-are-my-php-files-showing-as-plain-text) – Rwd Mar 21 '17 at 08:25
  • But he said he tested other PHP sites and they are working. – Amarnasan Mar 21 '17 at 08:28
  • Yes, actually I renamed apache's default index.html to index.php and it works when I pointed to /var/www/html – Faizan Ali Mar 21 '17 at 08:56
  • Just checked PHP isn't working on any site either. What happened is when I renamed Apache's default `index.html` to `index.php` it rendered the same html content and I thought it's working but when I added `` at the top, it showed the code instead. – Faizan Ali Mar 21 '17 at 09:02
  • 1
    Possible duplicate of [PHP code is not being executed, instead code shows on the page](http://stackoverflow.com/questions/5121495/php-code-is-not-being-executed-instead-code-shows-on-the-page) –  Mar 21 '17 at 09:16

3 Answers3

19

I got the solution over here..

Actually, I had to install libapache2-mod-php and activate it i.e. a2enmod php7.0

Community
  • 1
  • 1
Faizan Ali
  • 973
  • 2
  • 16
  • 32
16

add below command :

sudo apt-get install libapache2-mod-php7.2

(this will pull the default PHP version)

Reload Apache configuration changes by restarting service using below command

sudo service apache2 restart
Saurabh Mistry
  • 12,833
  • 5
  • 50
  • 71
1

I ran into same issue and was looking for answers. In my case I had multiple versions of PHP installed with all necessary libraries, including the one mentioned in answers above.

The cause of issue turned out to be not properly switching between PHP, which I do time to time while switching projects. Running again a2dismod php5.6 and then a2enmod php7.3 (switch from php5.6 to php7.3) and restarting apache did the job for me.

Hope this helps someone with similar issue like mine.

A.G.
  • 194
  • 2
  • 10