Celeb Glow
updates | April 03, 2026

php showing source code in localhost

i have apache2 (Server version: Apache/2.4.7 (Ubuntu) Server built: Mar 10 2015 13:05:59), mysql and phpmyadmin.

While accessing php file by or

It shows up source code instead of executing.

Ubuntu 14.04 LTS

enter image description here

3

4 Answers

I can think of 3 possibilities:

  1. You don't have PHP installed. In that case run:

    sudo apt-get install php php-mysql
  2. You have PHP installed but not enabled. You can try running:

    sudo a2enmod php7
    sudo service apache2 restart 
  3. You have PHP installed and enabled but you haven't restarted apache.

    sudo service apache2 restart
5

you need to install libapache2-mod-phpsudo apt-get install libapache2-mod-phpit is no longer pulled by other packages as a dependency in 14.04 it named libapache2-mod-php5, in 16.04 they dropped the number at the end for a meta package

0

For Ubuntu 20.04, I had to run:

sudo a2dismod mpm_event 

It tells you to restart Apache2, but you don't need to at this point. Then enable php 7.4 using:

sudo a2enmod php7.4

Then restart Apache2: sudo systemctl restart apache2

Hope this helps!

3

After Upgrading to Ubuntu 17.10 this morning my answer was a combination of Sledge Hammer's and GM-Script-Writer-62850's answer. The exact commands I needed were:

sudo apt-get install libapache2-mod-php
sudo a2enmod php7.1
systemctl restart apache2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy