OS and server information:
I previously had php 5.3.x installed but decided to upgr
I got this kind of problem. This is how I solve it. After installed Apache then I installed PHP using this command.
sudo apt-get install php libapache2-mod-php
it executes correctly but I request .php file from Apache, it gives without executing the PHP script.
Then I check PHP is enabled.
$ cd /etc/apache2
$ ls -l mods-*/*php*
but it didn't show any results. I check installed PHP packages.
$ dpkg -l | grep php| awk '{print $2}' |tr "\n" " "
Different type of PHP versions installed to my computer. Then I remove some PHP packages from my previous list, using apt-get purge.
sudo apt-get purge libapache2-mod-php7.0 php7.0 php7.0-cli php7.0-common php7.0-json
I reinstall PHP
sudo apt-get install php libapache2-mod-php php-mcrypt php-mysql
Verify that the PHP module is loaded
$ a2query -m php7.0
if not enabled with:
$ sudo a2enmod php7.0
Restart Apache server
$ sudo systemctl restart apache2
Finally, I check PHP process on Apache
create an empty file
sudo vim /var/www/html/info.php
Add this content to info.php & save.
<?php
phpinfo();
?>
Check on browser:
http://localhost/info.php
it shows correctly.I think this will help anyone.
I spent two days tracking this and found out that I was putting my PHP scripts in the wrong directory.
On my standard Ubuntu installation, I was putting the scripts in /var/www
. They should have been in /var/www/html
.
I just started PHP work, so I don't know if my solution relates to the version change you went through.
Please take a look at your addtype directives.
It looks to me like Apache is telling the browser that it's sending a document type of application/php for scripts with extensions like .php5. In fact Apache is supposed to tell the browser that the script is outputting text/html.
Please try this:
AddType text/html .php
Regarding the suggestion above that you should tell the browser that you are outputting a PHP script: It seemed like an unusual idea to me. I googled it and found that there is quite a bit of discussion about it on the web. Apparently there are cases where you might want to say that you are sending a PHP script (even though Apache is supposed to execute the script and emit text/html,) and there are also cases where the browser simply doesn't recognize that specific Mime Type.
Clearing your browser cache is always a good idea.
In case it's helpful here's a copy of my /etc/httpd/conf.d/php.conf file from a server running CentOS 5.9:
#
# PHP is an HTML-embedded scripting language which attempts to make it
# easy for developers to write dynamically generated webpages.
#
<IfModule prefork.c>
LoadModule php5_module modules/libphp5.so
</IfModule>
<IfModule worker.c>
LoadModule php5_module modules/libphp5-zts.so
</IfModule>
#
# Cause the PHP interpreter to handle files with a .php extension.
#
AddHandler php5-script .php
AddType text/html .php
#
# Add index.php to the list of files that will be served as directory
# indexes.
#
DirectoryIndex index.php
#
# Uncomment the following line to allow PHP to pretty-print .phps
# files as PHP source code:
#
#AddType application/x-httpd-php-source .phps
After struggling a lot I finally solved the problem.
If you are prompted to download a .php
file instead of executing it, then here is the perfect solution: I assume that you have installed PHP5 already and still getting this error.
$ sudo su
$ a2enmod php5
This is it.
But If you are still getting the error :
Config file php5.conf not properly enabled: /etc/apache2/mods-enabled/php5.conf is a real file, not touching it
then do the following:
Turns out files shouldn't be stored in mods-enabled
, but should rather be stored in mods-available
. A symlink should then be created in mods-enabled pointing to the file stored in mods-available.
First remove the original:
$ mv /etc/apache2/mods-enabled/php5.conf /etc/apache2/mods-available/
Then create the symbolic link:
$ ln -s /etc/apache2/mods-available/php5.conf /etc/apache2/mods-enabled/php5.conf
I hope your problem is solved.
I previously has a similar issue, after upgrading from 5.3 to 5.4. But my setup looks a little bit different as that I'm running Debian and using fcgid to server the PHP pages, and not the PHP5 apache/cgi module. So after I upgraded, it also installed php5_cgi, which collided with my fcgid setup, and would not execute PHP files anymore.
I had to disable the Apache Module and restart Apache
a2dismod php5_cgi
/etc/init.d/apache2 restart
Once the php5_cgi module was out of the way, fcgid was able to serve PHP pages again.
If none of the above works,
try commenting out the line
SetHandler ....
and restart apache using
/etc/init.d/httpd restart
It should work!