Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel showing code of index.php on home page

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.

like image 819
Faizan Ali Avatar asked Mar 21 '17 08:03

Faizan Ali


People also ask

Why is my php page showing code?

You've written your first PHP program, but when you go to run it, all you see in your browser is the code—the program doesn't actually run. When this happens, the most common cause is that you are trying to run PHP somewhere that doesn't support PHP.

Where does the index php file is located in laravel?

The root of Laravel app is in /public folder, so some other things like /config , /storage , /vendor etc. are higher in the directory tree than your index. php . Your domain should be pointing at the /public folder. /public/index.

What is htaccess in laravel?

htaccess file that is used to allow URLs without index. php . If you use Apache to serve your Laravel application, be sure to enable the mod_rewrite module.


3 Answers

I got the solution over here..

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

like image 143
Faizan Ali Avatar answered Oct 10 '22 20:10

Faizan Ali


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
like image 23
Saurabh Mistry Avatar answered Oct 10 '22 19:10

Saurabh Mistry


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.

like image 1
A.G. Avatar answered Oct 10 '22 20:10

A.G.