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>
Related
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>
Overview
I'm trying to host a few legacy PHP apps on Heroku with Apache. They all relied on the following deprecated syntax to parse any unknown file types (without the .php extension) as PHP.
DefaultType application/x-httpd-php
This has been replaced by AddType in Apache 2.4 (Heroku currently uses v2.4.37). Heroku also uses mod_proxy_fcgi to process PHP files via fcgi://heroku-fcgi.
Issue
I have a file foo.test and I want to have it handled by PHP FPM. Taking cues from the docs and the default Apache config provided by Heroku, here's what I've tried:
# .htaccess
<FilesMatch \.test$>
<If "-f %{REQUEST_FILENAME}">
SetHandler proxy:fcgi://heroku-fcgi
</If>
</FilesMatch>
# apache_app.conf (properly loaded via Procfile)
ProxyPassMatch "^/(.*\.test(/.*)?)$" "fcgi://heroku-fcgi/app/$1"
With both of these I get a plain-text 403 Access denied. response from PHP FPM. I'm sure both configs are properly loading and pointing to the FCGI handler because changing the endpoint results in other errors.
My Apache skills are long since rusty and I can't seem to find any good pointers online. The Apache error log is also clean. Any ideas (without the obvious "change all extensions to PHP, you dumbass") would be appreciated!
Fairly obvious solution. PHP FPM has its own configuration with a security.limit_extensions flag. It defaults to .php.
The solution was to unset that value: security.limit_extensions =. This naturally can pose some security threats, but these apps are only going up for static demo.
I was using heroku/heroku-buildpack-php but forked that to update this file. The htaccess FilesMatch should work now but I just ended up placing it into the Apache config file to avoid repetition across the sites I'll be serving.
security.limit_extensions can be customized with a configuration file passed as a Procfile argument.
https://devcenter.heroku.com/articles/custom-php-settings#php-fpm-settings
PHP-FPM settings:
In addition to php_value and php_flag for php.ini specific settings, any pool specific PHP-FPM configuration directives are valid in that configuration file, so you can use it to fine tune PHP-FPM’s behavior.
So you can set up it like the following
Procfile
web: vendor/bin/heroku-php-apache2 -C apache.conf -F fpm_custom.conf web/
apache.conf
<FilesMatch \.test$>
<If "-f %{REQUEST_FILENAME}"> # make sure the file exists so that if not, Apache will show its 404 page and not FPM
SetHandler proxy:fcgi://heroku-fcgi
</If>
</FilesMatch>
fpm_custom.conf
security.limit_extensions = .php .test
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.
I have tried reinstalling PHP. PHP is working, and Apache2 is running. I don't know why it's not opening in a browser and displaying normally.
Just so you know - my httpd.conf is empty - and instead I have everything in apache2.conf. This is because I'm using Ubuntu.
Can you help me? I know it's something simple, but I can't seem to find the answer.
Have you virtual host on this project?
Are you open php file with http://localhost/file.php or directly like file://...../file.php ?
In your apache conf:
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
Don't forget to restart apache afterwards. Let me know how it goes.
In my case there was a modification of the /etc/apache2/mods-enabled/php5.conf by module userdir
<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>
The solution is inside the config file, just comment the lines from <IfModule mod_userdir> to </IfModule>.
Try
sudo a2enmod php5
in terminal.
Assuming you are using php 5 :)
If you are using php5 the complete solution would be
sudo apt-get install libapache2-mod-php5
Then
sudo a2enmod php5
I recently had this problem, but only when accessing my site's root (e.g. http://example.com) - it worked as expected when accessing index.php explicitly (e.g. http://example.com/index.php).
The issue was that before creating index.php, I had an index.html file in the web root, but then I renamed it to index.html.bak to 'move it out of the way'. Unfortunately, that doesn't move it out of the way. For whatever reason, Apache will serve that file up with a MIME type of application/x-trash.
(As the /etc/mime.types file contains a line reading "application/x-trash ~ % bak old sik")
Maybe that will help someone else who is scratching their head as I was.
Also, when moving a site and you encounter this, make sure your .htaccess file doesn't specify a different method handler for php. We ran into this moving a wordpress site for a client.
Had same problem - and it was in the .htaccess file I had accidentally downloaded from the live server. Once you've deleted the .htaccess file, you will need to clear your cache to be able to load the .php file in your browser via http://
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