I'm using Apache 2.4 on Ubuntu 16.04, it shows the content of the index.php in browser.
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.
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.
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.
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.
I got the solution over here..
Actually, I had to install libapache2-mod-php
and activate it i.e. a2enmod php7.0
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With