Apache 2.4 does not execute PHP - php

I have a problem with apache and PHP 5.4 running on a centOS 7 machine.
Apache host have the directory index option:
<Directory my/directory>
Options Indexes
</Directory>
The directory where apache points to contains a index.php. But when I navigate the browser to the related website, the browser only shows the php code.
I've already checked, if php is activated in http.conf - and it is. The application (zabbix) should work with this version of PHP and all necessary SQL- and PHP-plugins are installed.
No more Google suggestions for this problem - any of you an idea how to solve this?
Output of /etc/http/conf.d/php.conf:
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
AddType text/html .php
DirectoryIndex index.php
#<FilesMatch \.phps$>
# SetHandler application/x-httpd-php-source
#</FilesMatch>
php_value session.save_handler "files"
php_value session.save_path "/var/lib/php/session"

Please check below thinks in your httpd config file
LoadFile "D:/wamp/php/libpq.dll" // Your sepcified path
LoadModule php5_module "D:/wamp/php/php5apache2_4.dll" // Your sepcified path
AddType application/x-httpd-php .php // Your sepcified path
PHPIniDir "D:/wamp/php" // Your sepcified path

You probably installed PHP from the distribution packages. If so, make sure Apache was restarted after that:
sudo systemctl restart httpd
If that does not help, try reinstalling the PHP packages, then restarting Apache.
If that does not help, post the contents of /etc/httpd/conf.d/php.conf here.

Related

Enable php on mac monterey

I try to install php on a mac M1 monterey, but this simple code is not interpretated :
<?php phpinfo(); ?>
I installed php with brew
brew install php
brew link php
I signed the libphp module
codesign --sign "certificate" --force --keychain ~/Library/Keychains/ /opt/homebrew/Cellar/php/8.1.2/lib/httpd/modules/libphp.so
Should I use the dynamic link instead ?
/opt/homebrew/opt/php/lib/httpd/modules/libphp.so
Loading the module in the apache2.conf file
LoadModule php_module /opt/homebrew/Cellar/php/8.1.2/lib/httpd/modules/libphp.so "certificate"
enable php page to be view in the apache2.conf file
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
DirectoryIndex index.php
</IfModule>
result of which php
/opt/homebrew/bin//php
Is the double slash normal here ?
I can access the index.php of my web directory but php is still not executed.
Thanks
As I mentioned in the comments you probably done most the steps but this guide I found has one last step it mentions for PHP. Here is the link:
https://wpbeaches.com/updating-to-php-versions-7-4-and-8-on-macos-12-monterey/
Also I found a lot of my issues went away when I started using homebrew Apache instead.
I am glad the guide was able to help you get it working.
For anyone else who is stuck, here is the relevant section from the guide:
PHP 8 and macOS Apache
One extra step is needed for PHP 8 and macOS bundled Apache:
sudo nano /etc/apache2/httpd.conf
Add the new PHP 8 and comment out the old one.
LoadModule php_module /usr/local/opt/php#8.0/lib/httpd/modules/libphp.so
Go to the end of the file and add:
<FilesMatch .php$>
SetHandler application/x-httpd-php
</FilesMatch>
Restart Apache
Sometimes php configs are added through "other" configs if you have a line as below at the end of your httpd.conf
Include /private/etc/apache2/other/*.conf
Check config files under /private/etc/apache2/other/ and make necessary changes. I had a file called +php-osx.conf in that folder I edited as following:
LoadModule php_module /usr/local/opt/php#8.0/lib/httpd/modules/libphp.so
<FilesMatch .php$>
SetHandler application/x-httpd-php
</FilesMatch>
<IfModule php_module>
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
</IfModule>

How to execute php code in html files (php-fpm and apache 2.4) on centos 7

As we have upgrade OS from centos 6.9 to Centos 7 on server. We have installed "Apache/2.4.6" and "PHP 5.6.36 (fpm-fcgi)" on this server. But we are facing problem to execute "PHP Code" in ".html" files. PHP code working fine in ".php file" but not in ".html files". I have ready many blogs but no where mentioned exact solution.
Can you please guide us how we can execute PHP code in .html files.
Note : We are using Apache 2.4, PHP-FPM and MPM_worker on centos 7.
After change below in files "/etc/php-fpm.d/www.conf" and "/etc/httpd/conf.d/php.conf" :
"security.limit_extensions = .php .php3 .php4 .php5 .htm" // in www.conf
and
SetHandler "proxy:fcgi://127.0.0.1:9000" // in php.conf
PHP code working in htm files but due to to these changes every html files renders as php. We want only php code render as php not html code render by php.
Your help would be appreciated.
This is how I configure Apache / PHP-FPM for a virtual host. It's not a public server so I'm only using HTTPS. This is from /etc/httpd/conf.d/ssl.conf:
<VirtualHost _default_:443>
DocumentRoot "/home/myvhost/public_html"
ServerName myvirtualhost.com:443
<Directory "/home/myvhost/public_html">
allow from all
Options FollowSymLinks SymLinksIfOwnerMatch
Require all granted
php_admin_value open_basedir /home/myvhost/public_html
</Directory>
SuexecUserGroup myvhost myvhost
ProxyPassMatch ^(/.*\.php)$ fcgi://127.0.0.1:9000/home/myvhost/public_html/$1
<FilesMatch \.php$>
# SetHandler application/x-httpd-php
SetHandler "proxy:fcgi://127.0.0.1:9000"
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
</FilesMatch>
</VirtualHost>
And this is from /etc/php-fpm.d/myvhost.conf (copied from the default PHP-FPM configuration file):
[myvirtualhost.com]
user = myvhost
group = apache
listen = 127.0.0.1:9000
security.limit_extensions = .php
So basically you could just copy the "ProxyPassMatch" line and change php to html and do the same thing with "FilesMatch". You can also modify the regex but I'm not really good at that.

Apache suddenly not parsing php

So my server suddenly stopped parsing PHP (sends raw php to the client). I'm not really sure when it happened, but I just noticed it today. I was messing with some mod_rewrite stuff, but I put it back and it didn't change. Other than that I haven't changed anything (to the best of my knowledge). Ideas? It's an Ubuntu 11.10 server, BTW.
Few things to try...
First:
apachectl -t -D DUMP_MODULES | grep php
You should get something like:
php5_module (shared)
at the very least.
Secondly... how are you restarting apache? Are you sure it is getting killed? I have used an apache init.d script before that would actually run an apachectl configtest to make sure it was error free before stopping and restarting. So, perhaps you need to stop, ensure it is stopped, then start again.
Also, in your config, make sure you have something like:
<IfModule php5_module>
AddType application/x-httpd-php .php
</IfModule>
You don't necessarily need the <IfModule> directive, but doesn't hurt.
And what version of apache are you running?
check:
that PHP files have their executable bit set
that "index.php" is set as one of default index files in your web
root
that php module is loaded by apache (see apache config file, perhaps
near by enabling mod_rewrite module)
Remove the Rewrite setting might be you have return wrong.
And restart the Apache server. Hope that will resolve the issue.
Can refer to
http://www.matthewwittering.co.uk/blog/ubuntu-tips/apache-not-running-php-files.htm
https://askubuntu.com/questions/59272/php-not-working-in-apache2-after-system-upgrade
<IfModule mod_php5.c>
<FilesMatch "\.ph(p3?|tml)$">
SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch "\.phps$">
SetHandler application/x-httpd-php-source
</FilesMatch>
# To re-enable php in user directories comment the following lines
# (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it
# prevents .htaccess files from disabling it.
<IfModule mod_userdir.c>
<Directory /home/*/public_html>
php_admin_value engine Off
</Directory>
</IfModule>
</IfModule>

.php files not being parsed by HTTPD

Update:
My problem was with httpd.conf after all, not php.ini. I was missing the following:
<FilesMatch \.php$> SetHandler application/x-httpd-php </FilesMatch>
http://wiki.apache.org/httpd/PHPDownload
(check other answers below too)
Original Question
I'd like a way to test my php.ini file, because my server currently cannot parse .php files. I'm having problems with my MimeTypes for PHP and I don't see any errors when I restart HTTPD.
If apache (or what web server you use) does not pass the control to the php - then you forgot to add AddType application/x-httpd-php .php into your httpd.conf

phpmyadmin - save file to disk

when i point my browser to http://localhost/phpmyadmin, instead of showing me its front page, it comes up with save as dialog.
I'm running:
Apache/2.2.3 (Debian) PHP/5.2.0-8+etch13 Server
I've reinstalled both apache2 and php5.
After re-install i don't have httpd.conf file, how can i get it back? Is there a standard file which i can just copy into /etc/apache2?
I did a locate httpd.conf and the only file i got was the empty file i have under /etc/apache2/ which i made.
Did you configure the php extension to send an http header?
In httpd.conf:
AddType application/x-httpd-php .php
EDIT
The file is not necessarily named httpd.conf, that's just the default name. Try searching for other configuration files in the Apache directory -- the extension probably is .conf but it might be something else...
If you used apt-get on debian to install apache2, try /etc/apache2/apche2.conf
/EDIT
I also get this problem when I install ISPconfig. I solved the problem by this tutorial:
http://www.howtoforge.com/perfect-server-debian-wheezy-apache2-bind-dovecot-ispconfig-3-p4
I think the main code is change suphp.conf config.
sudo nano /etc/apache2/mods-available/suphp.conf
comment out the <FilesMatch "\.ph(p3?|tml)$"> section and add the line AddType application/x-httpd-suphp .php .php3 .php4 .php5 .phtml - otherwise all PHP files will be run by SuPHP
<IfModule mod_suphp.c>
#<FilesMatch "\.ph(p3?|tml)$">
# SetHandler application/x-httpd-suphp
#</FilesMatch>
AddType application/x-httpd-suphp .php .php3 .php4 .php5 .phtml
suPHP_AddHandler application/x-httpd-suphp
<Directory />
suPHP_Engine on
</Directory>
# By default, disable suPHP for debian packaged web applications as files
# are owned by root and cannot be executed by suPHP because of min_uid.
<Directory /usr/share>
suPHP_Engine off
</Directory>
# # Use a specific php config file (a dir which contains a php.ini file)
# suPHP_ConfigPath /etc/php5/cgi/suphp/
# # Tells mod_suphp NOT to handle requests with the type <mime-type>.
# suPHP_RemoveHandler <mime-type>
</IfModule>
Hope I can help someone :)
I think you just do not know where that config file is. I don't think apache can run without httpd.conf. Here is how you can find your config:
$>locate httpd.conf
/etc/httpd/conf/httpd.conf
$>vim /etc/httpd/conf/httpd.conf
Once you located it, find where other AddType reside and add
AddType application/x-httpd-php .php
Last thing you need to do is restart your httpd, it depends on install, but doing apachectl restart does the trick. You might have to locate it just like you did with httpd.conf file and type in the entire path to the file.
Afterwords, your phpmyadmin should come up.
I dont know anything about this but... does someone knows a way in javascript to download selected files, for example I select through checkboxes 2 files, and then I click on a button in order to download these 2 files choosing the route where i will save the archives

Categories