Why is my php page not working?

In case we are in the same page do following

sudo apt-get install php -y sudo apt-get install php-{bcmath,bz2,intl,gd,mbstring,mysql,zip,fpm} -y

To enable PHP 7.2 FPM in Apache2 do:

a2enmod proxy_fcgi setenvif

a2enconf php7.2-fpm

update 2: Apache downloads .php file instead of rendering

After that, I faced above issue. There are similar questions like this.

I don't know why but it only happened for my .php files in /var/www/html/ root folder. everything was ok for sub-directories. (for example wordpress and phpmyadmin worked fine)

So here is my solution. I decided to enable php module. so I ran this command:

a2enmod php7.2

but I got this errors:

Considering dependency mpm_prefork for php7.2: Considering conflict mpm_event for mpm_prefork: ERROR: Module mpm_event is enabled - cannot proceed due to conflicts. It needs to be disabled first! Considering conflict mpm_worker for mpm_prefork: ERROR: Could not enable dependency mpm_prefork for php7.2, aborting

so I decided to disable mpm by running following commands:

sudo a2dismod mpm_prefork
sudo a2dismod mpm_worker
sudo a2dismod mpm_event

then restart apache:

systemctl restart apache2

then enable php7.2 (my installed version):

sudo a2enmod php7.2

and right now everything works fine.

on December 9, 2016, 5:12 AM PST

How to fix Apache 2 not executing PHP files

If your Apache 2 web server is failing to execute PHP files, learn how to quickly remedy this issue.

We may be compensated by vendors who appear on this page through methods such as affiliate links or sponsored partnerships. This may influence how and where their products appear on our site, but vendors cannot pay to influence the content of our reviews. For more info, visit our Terms of Use page.
Why is my php page not working?

Image: Jack Wallen

How many times have you set up a web server with Apache 2 only to find out that when you attempt to view a page with a .php extension, the page either attempts to save onto the local drive or it displays the PHP code in the browser? This is bad on multiple levels. First off, your website isn’t functioning properly; even worse is the idea that someone could get a first-hand glimpse of your code, which is not only a frustration, but a possible security issue.

Considering this is an easy fix, there’s no reason to avoid working with PHP and Apache 2. But how do you fix it? Let me show you. Note: I demonstrate this process on Ubuntu Server 16.04, running the latest releases of Apache 2 and PHP.

SEE: Power checklist: Managing and troubleshooting servers (Tech Pro Research)

Modify the .conf file

The first thing we must do is modify the main Apache 2 configuration file. To do this, open a terminal window and issue the command:

sudo nano /etc/apache2/apache2.conf

With apache2.conf open, all you have to do is add the following to the bottom of the file:


SetHandler application/x-httpd-php
​

Save and close apache2.conf.

Enable/disable modules

In order to get PHP to function properly, you have to disable the mpm_event module and enable the mpm_prefork and php7 modules. To do this, go back to your terminal window and issue the command:

sudo a2dismod mpm_event && sudo a2enmod mpm_prefork && sudo a2enmod php7.0

Restart Apache 2

You’re ready to restart Apache 2. Because we’ve disabled/enabled modules, we have to do a full restart of Apache 2 (instead of a reloading of the configuration files). To restart Apache, go back to the terminal window and issue the command:

sudo service apache2 restart

You should now be able to point a browser to a PHP file and watch it execute properly, as opposed to saving to your local drive or displaying code in your browser.

That’s it–Apache 2 should be functioning exactly as you need.

A simple fix

I warned you this would be a simple fix. Apache 2 is a very admin-friendly web server to configure and manage. Although one would think executing PHP would be an out-of-the box feature, it’s a very easy issue to resolve.

Happy Apache’ing!

Also See

  • How to secure your Apache 2 server in four steps (TechRepublic)
  • How to tune Apache in seconds with apache2buddy.pl (TechRepublic)
  • How to enable server-side encryption in Nextcloud (TechRepublic)
  • How to enable two-factor authentication on Nextcloud 10 (TechRepublic)
  • How to install a LAMP server on openSUSE (TechRepublic)
  • How to add virtual hosts to NGINX (TechRepublic)
  • How to install a LAMP stack on CentOS (TechRepublic)
  • When to use NGINX instead of Apache (ZDNet)

  • Networking
  • Open source
  • Security

Why PHP is not working in HTML?

The answer is in fact so simple you would want to bang your head: Simply change the file extension from ". html" to ". php"!!! Remember that you can build a webpage entirely out of PHP and all JavaScript and stuff built off JavaScript like, JQuery, bootstrap, etc will work.

How do I get PHP to work on my computer?

Note that there are several ways to configure Apache and PHP, but this is possibly the quickest method..
Step 1: Download the PHP files. ... .
Step 2: Extract the files. ... .
Step 3: Configure php. ... .
Step 4: Add C:\php to the path environment variable. ... .
Step 5: Configure PHP as an Apache module. ... .
Step 6: Test a PHP file..

Which browser is best for PHP?

Below is a list of the most popular and most efficient browsers, which are well-received by many web developers..
Mozilla Firefox Developer Edition..
Polypane..
Sizzy..
Blisk..
Brave..
Google Chrome..

How do I start PHP in browser?

Open PHP/HTML/JS In Browser.
Click the button Open In Browser on StatusBar..
In the editor, right click on the file and click in context menu Open PHP/HTML/JS In Browser..
Use keybindings Shift + F6 to open more faster (can be changed in menu File -> Preferences -> Keyboard Shortcuts ).