OS X Lion Apache & PHP not communicating - php

My apologies if this has already been answered - I'm having difficulty finding a solution however.
I'm attempting to make the OSX 10.7.4 Apache, PHP, MySQL leap... I followed this http://echodittolabs.org/blog/2011/09/os-x-107-lion-development-native-apache-php-homebrew-mysql-or-mariadb, which for the most part went flawless (I had a minor hickup with the .plist but that is fixed).
Apache works fine. PHP works fine (thru terminal). I cannot get any PHP file to work via the browser however. I've uncommented LoadModule php5_module libexec/apache2/libphp5.so as well as included the IfModule php5_module piece. I've checked the modules loaded by apache which includes PHP5. Apache error_log provides nothing
Thoughts? (Please don't say use MAMP).

Try adding this line to your IfModule php5_module block:
AddHandler php5-script .php
So it looks like this:
<IfModule php5_module>
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
AddHandler php5-script .php
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
</IfModule>

Related

Rename file with multiple file extensions [duplicate]

I just installed phpdocumentor, but received strange errors. I finally tracked down the problem.
Phpdocumentor creates various files such as someFile.php.txt which contains PHP code, but aren't meant to be parsed. Turns out, my server is parsing them. I've also tested a file name called someFile.txt, and it isn't being parsed.
How do I prevent my PHP server from parsing files such as someFile.php.txt?
My server is PHP Version 5.4.20, Apache 2.2.15, and CentOS 6.4. My /etc/httpd/conf.d/php.conf file is as follows:
#
# 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
It turns out that the default settings of CentOS Apache actually allow this and it is a known vulnerability. In order to fix it, you will need to edit your Apache config settings. Your PHP settings are typically in /etc/httpd/conf.d/php.conf. The default looks like this
AddHandler php5-script .php
AddType text/html .php
We need to change it to
#AddHandler php5-script .php
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
AddType text/html .php
Restart Apache and that should be the end of parsing any file with an extension after .php
Now, that $ is very important because this is using regex and within regex a $ means "end of string". So that means the file has to END with .php (i.e. no .php.txt) to be parsed by PHP.
I'm having the same problem on CentOS 6.5, and I needed to fix this in a virtual environment where I don't have access to php.conf.
I used the following in a .htaccess file.
# Match anything that ends with .php.txt
<FilesMatch \.php\.txt$>
RemoveHandler .php
ForceType text/plain
</FilesMatch>
I don't allow uploads by users, so I'm not worried about any security implications. I just wanted to get the .php.txt extension working. This did the trick.

Prevent PHP from parsing non-PHP files such as someFile.php.txt

I just installed phpdocumentor, but received strange errors. I finally tracked down the problem.
Phpdocumentor creates various files such as someFile.php.txt which contains PHP code, but aren't meant to be parsed. Turns out, my server is parsing them. I've also tested a file name called someFile.txt, and it isn't being parsed.
How do I prevent my PHP server from parsing files such as someFile.php.txt?
My server is PHP Version 5.4.20, Apache 2.2.15, and CentOS 6.4. My /etc/httpd/conf.d/php.conf file is as follows:
#
# 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
It turns out that the default settings of CentOS Apache actually allow this and it is a known vulnerability. In order to fix it, you will need to edit your Apache config settings. Your PHP settings are typically in /etc/httpd/conf.d/php.conf. The default looks like this
AddHandler php5-script .php
AddType text/html .php
We need to change it to
#AddHandler php5-script .php
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
AddType text/html .php
Restart Apache and that should be the end of parsing any file with an extension after .php
Now, that $ is very important because this is using regex and within regex a $ means "end of string". So that means the file has to END with .php (i.e. no .php.txt) to be parsed by PHP.
I'm having the same problem on CentOS 6.5, and I needed to fix this in a virtual environment where I don't have access to php.conf.
I used the following in a .htaccess file.
# Match anything that ends with .php.txt
<FilesMatch \.php\.txt$>
RemoveHandler .php
ForceType text/plain
</FilesMatch>
I don't allow uploads by users, so I'm not worried about any security implications. I just wanted to get the .php.txt extension working. This did the trick.

PHP execution on apache server

I have installed MySQL 5.5.34 , Apache 2.2.15 and PHP 5.5.4 in respective order on my linux Redhat system (2.6.32-220.17.1.el6.x86_64).
When the php script is being run on the web browser, it is being interpreted as html by apache although its working fine in command line.
I have done the following changes in the httpd.conf file:
I have uncommented LoadModule php5_module modules/libphp5.so .
The .php index has been defined as follows:
DirectoryIndex index.html index.php .
<FilesMatch "\.ph(p[2-6]?|tml)$">
SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch "\.phps$">
SetHandler application/x-httpd-php-source
</FilesMatch>
RewriteEngine On
RewriteRule (.*\.php)s$ $1 [H=application/x-httpd-php-source]
It would be of great help, if anybody could assist me in this.
Looks like problem is there: \.ph(p[2-6]?|tml)$, it's doesn't match the *.php file names.
Try to rename any php file to .php3 and try to acces directly from browser. Or just change the regexp to \.php$

Apache server wont start after trying to configure it to run with php

I installed apache server 2.2.19 on a vista machine. It was running fine but I tried to configure it to use php by modifying the httpd.conf file. These are the lines I added
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
PHPIniDir “C:\PHP”
I added this below this line
AddType application/x-gzip .gz .tgz
I also added this line
LoadModule php5_module “C:\PHP\php5apache2_2.dll”
I added this below this line
#LoadModule vhost_alias_module modules/mod_vhost_alias.so
I tried to restart the apache server but every time i do so it returns an error message that The requested operation has failed. What could be the problem?
I don´t have any experience with installing it on windows, but the following lines seem very wrong to me:
PHPIniDir “C:\PHP”
LoadModule php5_module “C:\PHP\php5apache2_2.dll”
Is that really what you added? If it is, I would suggest changing it to:
PHPIniDir "C:\PHP"
LoadModule php5_module "C:\PHP\php5apache2_2.dll"
Note that I am using " instead of the curly quotes you are using.
If you are having problems I would suggest just downloading Xampp for Windows. It takes the manual steps out of installing the separate components.
Normaly, this is how you would set up PHP under Apache...
(adjust for your paths)
LoadFile "D:/WampDeveloper/Components/Php/php5ts.dll"
LoadModule php5_module "D:/WampDeveloper/Components/Php/php5apache2_2.dll
<IfModule php5_module>
PHPIniDir "D:/WampDeveloper/Config/Php"
<Directory "D:/WampDeveloper/Websites/*/webroot">
AddType text/html .php .php4 .php5 .phps
AddHandler application/x-httpd-php .php .php4 .php5
AddHandler application/x-httpd-php-source .phps
</Directory>
</IfModule>
You will do better to use a pre-made Apache, PHP, and MySQL solution for Windows.
XAMPP
WampServer
WampDeveloper Pro

Fail to interpret PHP in Windows 7 Apache. Why?

I have follow every step of setting up apache & php in Windows 7.
I have the following set in the Httpd.conf:
LoadModule php5_module "C:/PHP/php5apache2_2.dll"
<IfModule mime_module>
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .php
</IfModule>
PHPIniDir "C:/PHP/"
if it is .html, it displays no problem. (e.g. localhost/index.hmlt)
if it is .php, then it displays the source code (e.g. localhost/phpinfo.php in which phpinfo.php is:
I run the phpinfo.php in command line and there is no problem. it is the apache server that doesn't recognized PHP. so what may be wrong?
You are encasing the type code in the wrong module
<IfModule mime_module>
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .php
</IfModule>
should be
<IfModule php5_module.c>
AddType application/x-httpd-php .php .phtml .php3
AddType application/x-httpd-php-source .phps
</IfModule>
most distributions will include a php config file that does this for you in the correct way
DC

Categories