Why Xampp server allow open not existing path - php

I have a problem with xampp etc. When I typing in URL address, for example, http://localhost/project/index.php/whatever.php server opened index.php with crashed style instead Not Found
The requested URL was not found on this server or something like that because /whatever.php does not exist in the project.
In console showed:
Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://localhost/project/index.php/style/style.css".
How I can prevent the open not existing path from my project ?

All versions of Apache allow this, it's normal... To solve your issue, please, edit your httpd.conf and where you have your VirtualHost config add this line:
AcceptPathInfo Off
Like here:
<VirtualHost localhost:80>
ServerName localhost:80
ServerAlias localhost
ErrorLog "${SRVROOT}/logs/localhost-error.log"
TransferLog "${SRVROOT}/logs/localhost-access.log"
DocumentRoot "D:/Web/www"
<Directory "D:/Web/www">
Require all granted
Options Indexes FollowSymLinks Includes ExecCGI
AcceptPathInfo Off
AllowOverride All
<IfModule mod_deflate.c>
SetOutputFilter DEFLATE
</IfModule>
</Directory>
</VirtualHost>
If not enough add this line to your .htaccess
################################################################################
######################### Remove /index.php/ from URLs #########################
################################################################################
RedirectMatch 301 ^/index\.php(/.*) $1
Hope this helps.

Related

XAMPP Access Forbidden

I have just downloaded the latest version of XAMPP with PHP version 7.2.4. I have made a very simple PHP validation for a HTML form and when I press submit it comes up with the following:
Access forbidden!
You don't have permission to access the requested object. It is either read-protected or not readable by the server.
If you think this is a server error, please contact the webmaster.
Error 403
localhost
Apache/2.4.33 (Win32) OpenSSL/1.1.0g PHP/7.2.4
I'd don't know what the problem is as I have tried changing Require none to Require all granted.
Please Help!
I have experienced this problem and found out that localhost link is not configured in
httpd_vhosts.conf.
So I added this line at the bottom part of httpd_vhosts.conf
<VirtualHost *:80>
DocumentRoot "E:/xampp/htdocs"
ServerName localhost
</VirtualHost>
Well, probably this must be happening because the localhost link is not configured in your xamp vhost, try to look for the vhosts configuration file and add the same one there. Just add this block of code making the appropriate path changes until your repository so that you can access the localhost:
# Virtual Hosts
#
<VirtualHost *:80>
ServerName localhost
ServerAlias localhost
DocumentRoot "${INSTALL_DIR}/www"
<Directory "${INSTALL_DIR}/www/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#hcode.com.br
DocumentRoot "C:\ecommerce"
ServerName www.hcodecommerce.com.br
ErrorLog "logs/dummy-host2.example.com-error.log"
CustomLog "logs/dummy-host2.example.com-access.log" common
<Directory "C:\ecommerce">
Require all granted
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
</Directory>
</VirtualHost>
By default in httpd.conf your entire system directory "/" is secured and not allowed access
in httpd.conf:
# Deny access to the entirety of your server's filesystem. You must
# explicitly permit access to web content directories in other
# <Directory> blocks below.
#
<Directory />
AllowOverride none
Require all denied
</Directory>
Add the below additional under the above
<Directory /home>
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
Change /home to your hosted installation public directory - e.g. /projects or /devsite.local etc...
For more info on Apache see here: https://httpd.apache.org/docs/current/mod/core.html#directory
The 'Options' are typical .htaccess directives - change as needed
The 'AllowOverride All' gives access to the /home folder and everything under it
The 'Require local' makes sure only localhost / 127.0.0.1 has access to folder and files under /home
Hope this helps :D

Apache mod_rewrite and php

I have a slight of problem.
I used simple php framework on github and have worked on it and added new functions and so on.
The framework that i have had help with is this:
https://github.com/panique/mini
Everything works perfectly in a MAMP environment, but now when i was going to test it on a live website and apache environment it does not work that good.
It obviously can read the index file since i point the directory to the directory that should be used for apache.
But when i am going to make a call to a controller (domain.com/login) it results in apache giving me :
"Not Found: The requested URL /login was not found on this server."
I have enabled rewrite with: service a2enmod rewrite, and i double checked and it is a Loaded module when looking in phpinfo().
The .htaccess file that is located in the "/var/www/html/php-project/public" directory(where i have pointed to in my virtual host file"
is the following:
# Necessary to prevent problems when using a controller named "index" and having a root index.php
Options -MultiViews
# Activates URL rewriting
RewriteEngine On
# Prevent people from looking directly into folders
Options -Indexes
# If the following conditions are true, then rewrite the URL:
# If the requested filename is not a directory,
RewriteCond %{REQUEST_FILENAME} !-d
# and if the requested filename is not a regular file that exists,
RewriteCond %{REQUEST_FILENAME} !-f
# and if the requested filename is not a symbolic link,
RewriteCond %{REQUEST_FILENAME} !-l
# then rewrite the URL in the following way:
# Take the whole request filename and provide it as the value of a
# "url" query parameter to index.php. Append any query string from
# the original URL as further query parameters (QSA), and stop
# processing this .htaccess file (L).
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
00-default.conf
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
ServerName www.domain.com
ServerAlias domain.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/php-project/public
<Directory />
AllowOverride All
</Directory>
#DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
apache.conf
<Directory />
Options FollowSymLinks
AllowOverride None
Require all denied
</Directory>
<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>
<Directory /var/www/html/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
#<Directory /srv/>
# Options Indexes FollowSymLinks
# AllowOverride None
# Require all granted
#</Directory>
AccessFileName .htaccess
I dont think the problem is within the php itself.
Thats why i don't added my code since its so many classes, but the code is as i said based on the framework in the beginning of the question.
Do any of you see any obvious problems in the conf's?
I have searched and searched for answers, but i don't seem to get it right. So i would really really appreciate some help.
Any questions, just ask on.
Thanks
Please follow the proper way of access rewrite module in apache2.
First enable the rewrite module in apache using below command-:
$ sudo a2enmod rewrite
Open the apache2.conf file
$ nano /etc/apache2/apache2.conf
Update the section
<Directory /var/www/html/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Remove the section from 00-default.conf
Remove the below lines
<Directory />
AllowOverride All
</Directory>
Then finally restart your apache2.
$ sudo service apache2 restart
or
$ sudo /etc/init.d/apache2 restart

Apache2 - Directory URL without trailing slash redirecting to different URL

I'm having a problem auto loading index.php in subdirectories with Apache2.
This is what I see in browser console when connecting:
GET http://example.com/login HTTP 301 Moved Permanently
GET http://10.0.3.10/login/
Connection Timed Out
When I type in http://example.com/login/, it works as intended. Also,
Root directory redirects to index.php properly.
I'm fairly new to this topic, would appriciate any help.
Default virtual host settings:
#NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName example.com/
ServerAlias www.example.com/
DocumentRoot /var/www/example.com/
<Directory />
AllowOverride All
DirectoryIndex index.php
</Directory>
<Directory /var/www/example.com/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
...
httpd.conf:
<IfModule dir_module>
DirectoryIndex index.php
</IfModule>
No .htaccess file used.
I think your request is handled by a virtualhost with no ServerName, and at startup httpd probably warns you that it can't find a default hostname for your local IP (10.0.3.10)
Try removing the trailing slashes from your ServerName and ServerAlias. You will need to do even more if your ServerName or ServerAlias matches the systems hostname -- namely adding a dummy ServerName to your default vhost.

Configuring a RESTful VirtualHost on Apache 2.4 with PHP

I'm trying to create a RESTful API on a VirtualHost on my Apache 2.4 server (on Ubuntu). I have a php file named dbManager.php which I am using a RewriteRule to look like an api directory. It's working great except for PUT and DELETE commands, which are returning 403 errors. Here's a redacted version of my conf file:
<VirtualHost *>
ServerAdmin onigame#gmail.com
ServerName servername.com
ServerAlias *.servername.com
DirectoryIndex index.html index.php
DocumentRoot /path/to/local/dir/
<Directory />
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
<Limit PUT DELETE>
Require all granted
</Limit>
</Directory>
# RESTful services provided for the fake "api" directory
RewriteEngine on
RewriteRule ^/api/(.*)$ /dbManager.php/$1 [L]
ServerSignature On
AddDefaultCharset utf-8
</VirtualHost>
Well, the PUT and DELETE still aren't working and returning 403. I'm also worried that I don't really want to allow PUT and DELETE everywhere on the directory, but only through the dummy api directory. What's the right way to do this?
I have managed to solve my question, but I don't really understand why it works:
<VirtualHost *>
ServerAdmin onigame#gmail.com
ServerName servername.com
ServerAlias *.servername.com
DirectoryIndex index.html index.php
DocumentRoot /path/to/local/dir/
<Directory />
Options Indexes FollowSymLinks MultiViews
AllowOverride All
</Directory>
<Directory /path/to/local/dir/>
Require all granted
Satisfy All
</Directory>
# RESTful services provided for the fake "api" directory
RewriteEngine on
RewriteRule ^/api/(.*)$ /dbManager.php/$1 [L]
ServerSignature On
AddDefaultCharset utf-8
</VirtualHost>
Best I can figure out, getting a 403 means that it's access being blocked, and not the type of HTTP request (which would result in a 405, not a 403). And the access problem is on the local directory, so it needs a special section for it. But I really don't understand why the two lines I put there make things work. The Require directive, that sort of makes sense. But the Satisfy directive, from what I can tell from the documentation, should default to All.
And yet when I remove either line, it doesn't work.

Enabling pretty permalinks on Wordpress - apache configuration does not work

Probably this error has a pretty easy solution but I've been looking way to long at this and still don't get the error. I think I've tried whatever I could.
Problem: when I enable pretty permalinks on my wordpress installation (so, that it is using /%postname%/), it doesn't work. I get a 404 on all pages except for the homepage.
This page http://codex.wordpress.org/Permalinks tells me the requirements for permalinks to work:
Apache web server with the mod_rewrite module installed
In WordPress's home directory,
The FollowSymLinks option enabled
FileInfo directives allowed (e.g. AllowOverride FileInfo or AllowOverride All)
An .htaccess file (if this file is missing, WordPress will try to create it when you activate "pretty" permalinks)
If you want WordPress to update the .htaccess file automatically, WordPress will need write access to the file.
Apache web server has been installed, the mod_rewrite module has been loaded with a2enmod rewrite command (and the server has been restarted multiple times after). So, under /etc/apache2/mods-enabled, the symlink to rewrite.load is present. Also, when I run phpinfo command, I see that the mod_rewrite module has been loaded. You can check this as well here: http://namorti.com/phpinfo.php
Then, in /etc/apache2/sites-enabled, there was no "default" present. I copied 000-default.conf to default and edited default afterwards. It contains the following:
DocumentRoot /var/www
<Directory />
Options FollowSymLinks Indexes
AllowOverride FileInfo
</Directory>
So as far as I'm concerned, FollowSymLinks has been enabled and FileInfo directives are allowed.
As for the last two points, in my wordpress home directory (/var/www), .htaccess is present and writeable by Wordpress (I updated the permalink structure a couple of times and it updates the .htaccess file accordingly). Right now it contains the following:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
So, as far as I know, it SHOULD be working. I restarted the server (service apache2 restart) several times. I don't see what I'm missing. Anyone has a clue here?
Thanks in advance!
* EDIT *
So, I did what calcinai told me to do... I edited my /etc/apache2/sites-enabled/default file (containing the vhost). It now looks like this:
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin www.namorti.com
DocumentRoot /var/www
<Directory /var/www>
Options MultiViews
AllowOverride None
Order allow,deny
allow from all
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</Directory>
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
I've restarted apache again, but unfortunately it still doesn't work. Honestly it would have surprised me, because moving the directives from the .htaccess file to the vhost would work if the htaccess on itself would work, as everything else seemed correct enough to me...
Any other suggestions? Thanks for the effort!
Make sure the AllowOverrides directive is set to all in the vhost - that's what tells apache to look for .htaccess files in the webroot.
A better solution is actually to put your rewrite directives in the vhost, as you clearly have write access to the file. When you have AllowOverrides on, apache will look in the directory and all parent directories for .htaccess files on every request, which can be a big performance hit.
For Wordpress, your vhost should look something like:
<VirtualHost *:80>
ServerName example.com
DocumentRoot /var/www/site
<Directory /var/www/site>
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
allow from all
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</Directory>
</VirtualHost>
Solved it myself.
It had to do with the file "000-default.conf" - I copied it to "default" and edited "default", like I already mentioned in my question.
Apparently the service is using the file "000-default.conf" on itself. By copying the "default" file back to "000-default.conf" and restarting the apache service, everything works now.
One caveat: calcinai's suggestion seems like it should work, but with his suggestion in my vhost in the correct "000-default.conf" file, I got a 403 Forbidden error. When I replaced his content with my original content
DocumentRoot /var/www
<Directory />
Options FollowSymLinks Indexes
AllowOverride FileInfo
</Directory>
And then once again restarting the apache service, it all worked.
Thanks calcinai for your effort to try to help me :)
Permalink Problem
Inside of this file, we want to change all things.
sudo nano /etc/apache2/sites-available/000-default.conf
000-default.conf
- should look something like this:
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
<Directory /var/www/html/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
If you dont see like this then paste the above code inside virtual host
When you are finished, save and close the file.
Next, we need to enable the rewrite module, which allows you to modify URLs. You can do this by typing:
sudo a2enmod rewrite
After you have made these changes, restart Apache:
sudo service apache2 restart
This may help you solve this:
sudo chown -R www-data:www-data /var/www
After spending really lots of time, here is what worked successfully in my Linux machine's LAMP server. Following changes are needed for me to make it work perfectly,
Add this to your /etc/hosts file.
127.0.0.1 sitename.com
Add host entry as follows in the path /etc/apache2/sites-available/sitename.com.conf
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName sitename.com
DocumentRoot /var/www/sitename.com/public_html
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/sitename.com/public_html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Create symlink to sites-enabled.
sudo ln -s /etc/apache2/sites-available/sitename.com.conf /etc/apache2/sites-enabled/sitename.com.conf
Restart apache by using the command,
sudo service apache2 restart
This works perfectly for me. Instructions for adding host entry taken from, https://www.digitalocean.com/community/questions/wordpress-permalinks-not-working-on-ubuntu-14-04

Categories