Error 404 while opening site, httpd.conf? - php

I have a php application that I needed to open on a local web server. I'm running Windows 7 on my VM. Have installed php 7.3.6, mysql, apache 2.4.
After some configuration trying to open my "application" with "localhost/application".
Getting "Internal error 500".
In Apache logs can see "C:/WebData/application/.htaccess: Invalid command 'order', perhaps misspelled or defined by a module not included in the server configuration"
In .htaccess I have:
order deny,allow
RewriteEngine On
RewriteBase /
RewriteRule .* index.php?url=$0 [QSA,L]
Change first line into "Require all granted"
Trying to open "localhost/application"
Getting the error "404 URL /index.php" not found
Trying to open "localhost/application/index.php"
Forwarding to "localhost/ru/main"
Getting another error "404 URL .." not found
Also after each request I see that htaccess is changing back into its initial state with "order deny,allow".
Is there something wrong with httpd.conf?

You probably don't run mod_access_compat, which means Order is not available, as it's deprecated in Apache 2.4 (see https://httpd.apache.org/docs/2.4/howto/access.html)
Now, the reason why your .htaccess files get overwritten probably lies in the PHP code you're running. Some applications try to auto-configure themselves and will write their own .htaccess file to make sure they run properly.
The fact this particular app tries to write deprecated commands without checking if the version of Apache you are running is capable of handling them is concerning and probably means it's outdated.
Do a global search on the application files and look for that Order deny, allow rule, I'm pretty sure you'll find the culprit.
If you can run a newer version of that code, do so, and if not, and if patching it manually is an option, change it to Require all granted

Related

Silverstripe not working on Plesk Server

I am trying to create a new domain which runs on SilverStripe 3.0. I am unable to figure out the issue. If I upload a custom php page then it runs fine, but my website is not working. It shows blank page but shows the favico.
If I try to open up www.mydomain.com/admin/, I get the error
Page Not Found
The requested URL /admin/pages was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
This is not a Silverstripe error page. Here is my php info Info
Please let me know if I am missing something or there is any way to figure out the issue.
Try www.yourdomain.com/index.php/admin
If that works then it is because your rewrites are not working. This can be because .htaccess isn't configured properly, or because .htaccess is not used at all (in which case you need to edit your server config).
Last I used Plesk it always used apache. If that is different now and you're using nginx as more than a forward proxy, then you will need to set up the redirects for your site manually.
It does sound like your .htaccess is not being respected. Does Plesk allow overrides for .htaccess in the local directory?
At an apache level we would have something like this stanza to ensure the the .htaccess of the project was respected;
AllowOverride All
If your .htaccess is being processed, make sure that your host has mod_rewrite enabled as that is required to access to pretty URLS.

How to check for mod_rewrite on PHP CGI

I am on shared host and PHP is inatalled as CGI script and that is all the problem i am not able to find whether mod_rewrite if enable or not
Note: I don't have any root level access so i can't much do with Shell.
I have tried the following :
1) checked in phpinfo() where i came to know about that this is the wrong place to look for in PHP-CGI.
2) I have tried getting it from apache_get_modules which agi does not work in PHP-CGI :(
3) I have tried :
if (strpos(shell_exec('/usr/local/apache/bin/apachectl -l'), 'mod_rewrite') !== false) {
// mod_rewrite is enabled
}
which is asking for path to apache and i dont have this info SHELL cant reply to me and $_SERVER has nothing.
4) I have checked with RewriteEngine On in .htaccess and after this my site is throwing 500 Internal server error may be because of RewriteEngine is not there, but i need this is written to show someone.
Any body has any idea how to check get this DONE.
Thanks
With PHP CGI there is no easy way to find out whether mod_rewrite is available or not on the server.
So, you need to find out it by making a test call to the server. You can use the following steps for this method,
Create a directory named mod_rewrite_test on the server.
Add .htaccess file in this directory with the following code,
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /mod_rewrite_test
RewriteRule .* mod_rewrite_test.txt
</IfModule>
a. first line tells apache to execute the below code only if mod_rewrite is available,
b. second line enables rewrite engine,
c. third line sets rewrite base directory path which is from DOCUMENT_ROOT
d. forth line returns the content of mod_rewrite_test.txt file to any request sent to mod_rewrite_test directory.
Create a file named mod_rewrite_test.txt in the same directory. Write ok in this file and save it.
Now, using CURL in your php script, call the URL similar to,
http://www.your-domain.com/mod_rewrite_test/test.php
and check the response.
So, as per our .htaccess code, if mod_rewrite is active and working on the server,
it will return the content of mod_rewrite_test.txt file i.e. ok even though the test.php file does not exists.
Otherwise, it will return 404 - Page not found error.
To check if mod_rewrite module is enabaled, create a new php file in your root folder of your server. Enter the following
echo phpinfo();
And access file in your browser.

What would cause Apache serving somepage.php/friendly-url yield 404 after PHP upgrade

My hoster has recently upgraded PHP to 5.3.8 and now all my installations that use a URL pattern like somefile.php/friendly-url yield a 404 ErrorDocument (where somefile.php is an actual existing PHP file which is supposed to handle the rest of the path). How do I best go about fixing this? What is the directive that tells Apache to serve said URL even if only the somefile.php part is valid but not the whole location does not really point to an existing file?
BTW: No URL rewriting is involved… Also, the 404 is clearly generated by Apache, not any scripts.
Try to add an .htaccess file to your public directory containing this line:
AcceptPathInfo On
From the PHP Manual:
Apache 2 users may use AcceptPathInfo On inside httpd.conf to define PATH_INFO.
Also have a look at the Apache2 documentation.
You probably had mod_rewrite configured differently before the upgrade... a similar thing happened to a sever I was working on about 2 months ago. Check out mod_rewrite and see if this is what you need.

Returning Http Status Code to Apache from PHP?

On my local development machine, I downloaded PDT + Zend Server, which included Apache 2.2.16 and PHP 5.3.5, running on Windows 7. On my local site, I included a .htaccess that includes ErrorDocuments for 404, 403, and 500. In my PHP, I use header("Http/1.0 404 Not Found") when the user requests a document that doesn't exist. On my local server, everything works great. My custom ErrorDocument appears and I'm happy.
I upload the everything to my shared host running Apache 2.2.38 and PHP 5.3.8 on a Linux server, and suddenly the ErrorDocuments only work if they don't come from PHP.
Is there some setting in PHP.ini or httpd.conf or .htaccess that allows Apace to see the error codes from PHP, which makes my dev server work correctly, but not my shared host?
In researching this, all I ever saw was "Apache doesn't see the status code once it passes off to PHP." In such a case, why does my dev server work right?
Edit
For clarity, here's the .htaccess:
# Use PHP 5.3
Action application/x-hg-php53 /cgi-sys/php53
AddHandler application/x-hg-php53 .php
#Deny Include Files
<Files *.inc>
order deny,allow
deny from all
</files>
#Provide custom error documents
ErrorDocument 404 /Errors/Http404.php
ErrorDocument 403 /Errors/Http403.php
ErrorDocument 500 /Errors/Http500.php
The .htaccess works because if the user navigates to myhost.com/jdkslfjdls the user receives the content of Errors/Http404.php.
However, if the user navigates to myhost.com/images/GetImage.php?Id=5 (when there is no image #5) the user receives no content.
If they navigate to (Internal IP Address)/images/GetImage.php?Id=5, the user receives the content of Errors/Http404.php.
A similar problem occurs if the user tries to access GetImage.php?Id=6 (when there is an image #6 but they don't have permission). On the shared server, they get a blank page or the browser's 403 error. On my dev server, they get my actual custom 403 error page.
Again, 403 error document works on the shared server if I try to access a .inc file.
Are you sure that your .htaccess file is used on the server? Sometimes the hosting company does not allow the global apache settings to be overwritten by the local .htaccess files.
If you however have access to your virtualhost configuration than you may want to look at the following directive
AllowOverride All
If instead you find
AllowOverride None
try to change as above.
Check if you have
AllowOverride ALL
in your apache.conf under the Directory directive inside the VirtualHost corresponding to your website
Anyway, that may be one possible cause, the other may be to check whether or not you have enabled mod_rewrite
On ubuntu or debian based systems, you'd simply link or copy the mod_rewrite.load from /etc/apache2/mods-available/mod_rewrite.load to /etc/apache2/mods-enabled/mod_rewrite.load
Rewrite should have nothing to do though, but I've seen cases where your .htaccess directives may require mod_rewrite
So check for those things in apache conf files.
If nothing happens contact me # phpcip#gmail.com
Hope it works.

all php pages give Internal Server Error

Since it's a friday, I can't ask my host about this, but apparently, all the .php pages on my websites are giving out the "Internal Server Error"... this started just now, I was not on my admin cp, I did 0 changes to my website today, in fact, I changed nothing for about a week now.
I host a few forums and got alerted by some users just now who were browsing and suddenly this happens.
The website in question:
cudamine.com
The error:
Internal Server Error
The server encountered an internal
error or misconfiguration and was
unable to complete your request.
Please contact the server
administrator, xxx#email.com and
inform them of the time the error
occurred, and anything you might have
done that may have caused the error.
More information about this error may
be available in the server error log.
Additionally, a 404 Not Found error
was encountered while trying to use an
ErrorDocument to handle the request.
I use cPanel X.
Should I be worried about this? Some sort of attack or something? All HTML pages work fine, it's just .php that seems to have this issue, is this a problem on my hosts end, or can I do anything about this before monday? Thanks guys, and sorry if this is the wrong place to ask. It's just that I don't want to have no site for the whole weekend...
After reading up on the web about similar situations, I found some info on the .htaccess file, I found the file and this is what's in it:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^cudamine.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.cudamine.com$
RewriteRule ^santa\-maria\/forum\/?(.*)$ "http\:\/\/cudamine\.com\/santa\-maria\/\?page_id\=7\/$1" [R=301,L]
Those two RewriteCond are 2 of my links that use php... I tried deleting this file, nothing changed though.
Definitely check the error log (should be available in CPanel).
One common occurrence I see is when a host enables SuPHP (suexec for PHP scripts) and you have group writable scripts or directories containing scripts.
If your error log shows anything like "Apache SoftException", then this is the most likely cause. You need to change the filesystem permissions on your scripts and directories to remove the group "write" bit.
Another possible cause is your host has disabled mod_rewrite or removed the appropriate overrides (FileInfo) to use the Rewrite* directives.
PHP may be writing its error log elsewhere than the standard Apache error_log. You can retrieve the log's location with ini_get('error_log'). If the value's something other than "syslog", PHP is writing its errors to a file of the same name.

Categories