for a certain folder on my local Apache-Server (running with Ubuntu) I'd like that all *php-files will be displayed as if they were plain text-files. I need this since I only want to see the source code of these files and NOT run them.
While searching, I found that most people have the opposite problem :-) and couldn't really find a solution for me.
What would I need to include in the .htacces-file of my folder?
THANKS!
THE ANSWER:
in .htaccess-file type
php_flag engine off
#This will prevent apache from executing *.php-files
AddType text/plain php
#this wil display php-files in browser (if not, browser will want to download file!)
Thanks to Brad!
My Godaddy setup wont allow me to edit the httpd.conf files, and the php_flag command doesn't work due to how they've implemented php for me.
I was able to use this in my .htaccess file:
SetHandler default-handler
AddType text/plain php
I put this in the directory above where my FTP user is allowed to access, which forces all PHP files in that directory, as well as all sub-directories to show php as plain text.
This will work for other file types as well. All you need to do is add another line with whatever extension of file you want to be forced to display in plain text. AddType text/plain cgi for example
Look at your httpd.conf file for the AddType of .php extension, and change it fortext/plain, and php_flag engine to the offvalue just as sait by Sam Bisbee.
But prefer do these change in the httpd.conf, the .htaccess are useless if you have a dedicated server, and lowing your perfs.
But you can also just change the extensions of your PHP scripts...
Two solutions off the top of my head...
Change their file name extensions to .phps. Ex., index.phps.
Change the Content-type for them in the .htaccess file. AddType text/plain .php uses mod_mime to do this. More info at http://httpd.apache.org/docs/2.2/mod/mod_mime.html#addtype
Turn off the the PHP module in apache? (if you won't be needing php execution, of course)
Related
for a certain folder on my local Apache-Server (running with Ubuntu) I'd like that all *php-files will be displayed as if they were plain text-files. I need this since I only want to see the source code of these files and NOT run them.
While searching, I found that most people have the opposite problem :-) and couldn't really find a solution for me.
What would I need to include in the .htacces-file of my folder?
THANKS!
THE ANSWER:
in .htaccess-file type
php_flag engine off
#This will prevent apache from executing *.php-files
AddType text/plain php
#this wil display php-files in browser (if not, browser will want to download file!)
Thanks to Brad!
My Godaddy setup wont allow me to edit the httpd.conf files, and the php_flag command doesn't work due to how they've implemented php for me.
I was able to use this in my .htaccess file:
SetHandler default-handler
AddType text/plain php
I put this in the directory above where my FTP user is allowed to access, which forces all PHP files in that directory, as well as all sub-directories to show php as plain text.
This will work for other file types as well. All you need to do is add another line with whatever extension of file you want to be forced to display in plain text. AddType text/plain cgi for example
Look at your httpd.conf file for the AddType of .php extension, and change it fortext/plain, and php_flag engine to the offvalue just as sait by Sam Bisbee.
But prefer do these change in the httpd.conf, the .htaccess are useless if you have a dedicated server, and lowing your perfs.
But you can also just change the extensions of your PHP scripts...
Two solutions off the top of my head...
Change their file name extensions to .phps. Ex., index.phps.
Change the Content-type for them in the .htaccess file. AddType text/plain .php uses mod_mime to do this. More info at http://httpd.apache.org/docs/2.2/mod/mod_mime.html#addtype
Turn off the the PHP module in apache? (if you won't be needing php execution, of course)
My problem started when I was working with the .htaccess file to a directory trying to get php to run inside of html files. I tried ALOT of combinations of AddTypes and AddHandlers. I took them out and now my php files are being downloaded by the broswer instead of running. There are a few other questions on here that I have studied up and down, but they are not exactly my problem.
I'm fairly lost now, I've tried just about every combination of AddType and AddHandler. I've since decided to use mod_rewrite and just have all my files end in .php but I can't get them to run.
This is what I'm using to test:
<!DOCTYPE html>
<body>
<?php
echo("php working");
?>
</body>
</html>
Am I missing something? Luckily I made all my changes at a separate directory than the root so that the site still runs, but none of the php files in that folder can be viewed in broswer. What can I do? Any help is appreciated.
EDIT:
Just to make it clear, I was originally trying to be able to put php in my html files so I was messing around with handlers and addtypes. My server does have php. If I call a php script from a .html file, it runs. I just can't get a php file like the example I included above to open in brower ANYMORE, it used to open in browser. My fear is that I have messed something up by trying all the different handlers in .htaccess. I have since cleared my .htaccess file in hopes that would at least get me to square one, but it hasn't.
SECOND EDIT:
I went to the root directory and made a php file and it ran just fine so its definitely something I changed in the .htaccess for the particular directory. Is there anyway I can reset that directory?
have you made sure to install php correctly within apache?
if you are using php as a module, you need the following:
LoadModule php5_module "c:/php/php5apache2.dll"
AddType application/x-httpd-php .php
# configure the path to php.ini
PHPIniDir "C:/php"
or as a CGI binary
ScriptAlias /php/ "c:/php/"
AddType application/x-httpd-php .php
# For PHP 4
Action application/x-httpd-php "/php/php.exe"
# For PHP 5
Action application/x-httpd-php "/php/php-cgi.exe"
other things to consider, are the permissions set correctly on the php binaries, is the php.ini present and correct, have you restarted apache since installing php into apache?
lastly, php doesnt run within html files, you would need to set the following as pretty much the last thing in the apache config
AddType application/x-httpd-php .html .htm
Do you see the line like this in your htaccess file?
php_flag engine off
If yes, delete it.
One more thing that may help you understand what happened
The following piece of htaccess would make Php from being executed but rather downloaded as a text file
<VirtualHost *>
ServerName sourcecode.testserver.me
DocumentRoot /var/www/example
AddType text/plain php
</VirtualHost>
One more thing
I'm guessing that this topic was addressed once here-> htaccess downloading file instead of loading
I want xdebug's trace function to output files in .html instead .xt.
This are the arguments of xdebug_start_trace function:
http://grahamwideman.wikispaces.com/PHP+trace+with+XDebug
I tested them, but they're not working.
Is there a way to output files with .html format using xdebug, and avoid typing more code?
You want the xdebug.trace_format setting, the documentation is here: http://xdebug.org/docs/execution_trace
DonĀ“t forget to restart your webserver to make the new settings take effect.
There is another profiler that provides its results through a nice webinterface by default, maybe you would like to give it a try:
https://github.com/facebook/xhprof
You need to set xdebug.trace_format = 2 in your php.ini.
After that restart apache
i did it before
and the xdebug made a .xt file with html codes
like tr and td and..raw html code
this is it https://gist.github.com/057ffa704f21f645e086
i want to make a .html file to view it instantly.
i can do that by rename fun but i want xdebug do that
By far the easiest way to do this is to use an .htaccess file in your output directory to add a MIME type to files with an xt extension using the AddType directive. Like so:
AddType text/html .xt
Or you could enable it globally in your http.conf as well:
<IfModule mod_mime.c>
AddType text/html .xt
</IfModule>
If you're interested, I cover a bunch of this sort of stuff in a recent post on configuring a LAMP server and PhpStorm for debugging.
I have a quick question about changing the file types PHP parses. This website gave this line:
AddType application/x-httpd-php .php
But I'm not clear what file this goes into. Any help would be appreciated - thanks!
That line goes into a file called .htaccess, that changes the Apache server configuration for the folder it is on, and all its subfolders (Unless otherwise specified)
Your server should parse php files with the .php file extension by default though. You could use that to add custom file formats for example.
To parse .mp4 files, like you said in the comments, add to your .htaccess:
AddType application/x-httpd-php .mp4
You need to write that in your .htaccess file.
That makes Apache parse .php files through the PHP interpreter.
You can either add that to your .htaccess or httpd.conf file, depending on what you have access to.
I'm trying to set up my .htaccess file correctly and I'm having an issue.
The only thing my .htaccess file at the moment is:
AddType application/x-httpd-php .php .html .htm
This is included because my server is not parsing php in my html files.
However when this is included in my .htaccess file, when I open a page in my browser, the user is prompted to save or open the file locally.
I believe the answer to my issues is setting up an action to be done (run with php) however I cannot find out the path to my php files.
Any help is appreciated.
You will need to edit the configuration for enabled modules. On a Debian/Ubuntu type system this will be in /etc/apache2/mods-enabled The file you are looking for is php5.conf
So far all you have done is specify that (dot) htm, html or php files should be served -by default- as application/x-httpd-php, and to my knowledge there is not a single web browser that would attempt to interpret such content -- hence the save-as dialog.
Either you could fix your .htaccess file not to be broken (it is broken behaviour to serve html files as application/x-httpd-php), or you could manually output the correct HTTP headers using the PHP header() function.
Unfortunately, everyone seems to love abusing AddType (and then complain e.g. that MultiViews is broken). See this article, please.
This is not supposed to work in all cases. It depends on the AllowOverride directive of the web server.
You shoud specify the AddType in the serveur config file rather than in the htaccess.