Internal Server Error Slim and .htaccess - php

First I need to say ya sorry for my bad english
I hope u can help me strangers.
I have created a domian in my linux Debian 8.
look it
<VirtualHost *:80>
ServerAdmin admin#admin.com
DocumentRoot "/var/www/saci"
ServerName saci.com
ServerAlias www.saci.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory "/var/www/saci">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
I'm using slim and I've created a folder named 'app' on the folder 'saci' with a file start.php that got this:
<?php
use Slim\App;
session_cache_limiter(false);
session_start();
ini_set('display_errors', 'On');
define('INC_ROOT', dirname(__DIR__));
require INC_ROOT . '/vendor/autoload.php';
$app = new App();
$app->get('/test', function() {
echo "this is a test.";
});
?>
Now on my folder saci I've created a folder named Public with one index.php and one .htaccess.
so now look my roots
Var > www > saci > public
index.php <------------------index daaa
.htaccess <------------------.htaccess
var > www > saci > app
start.php <----------------start
so now my problem is here
I've got an index.php with this
<?php
require '../app/start.php';
$app->run();
and a .htaccess with this
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
but when I go to my host www.saci.com I can see my index of/
with all my proyects folders But I cannot see the folder public, and if I go to www.saci.com/public
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator at admin#admin.com to inform them of the time this error occurred, and the actions you performed just before this error.
More information about this error may be available in the server error log.
Apache/2.4.10 (Debian) Server at www.saci.com Port 80
I rly DON'T HAVE IDEA of what is going wrong I need rly rly help
starting now
Thanks Steangers U rock never forget smile
Greetings from Venezuela

Related

Symfony 5: 404 page for /lucky/number application

I just started learning Symfony and try create 1th application by article https://symfony.com/doc/current/page_creation.html
WebServer: Apache 2.4.41
Server: Ubuntu 20
PHP: 7.4.3
I created domain on server symfony.
Installed in /var/www/html/symfony/ by command symfony new --full ./
Add required files (controller and write route to config/routes.yaml). Installed composer require symfony/apache-pack.
Execute $ php bin/console debug:router:
Name
Method
Scheme
Host
Path
...
app_lucky_number
ANY
ANY
ANY
/lucky/number
Opened in browser http://server.ip/symfony/lucky/number and get 404 Apache error.
Opened in browser http://server.ip/symfony/public/ and OK.
Opened in browser http://server.ip/symfony/public/index.php/lucky/number and OK.
Apache config in /etc/apache2/.../symfony.conf:
<VirtualHost *:80>
ServerName symfony
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/symfony/public
<Directory /var/www/html/symfony/public>
Options FollowSymlinks
Require all granted
#AllowOverride All
Order Allow,Deny
Allow from All
#FallbackResource /index.php
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
mod_rewrite is enable.
Anybody have any ideas how to fix it?
You need to add .htaccess in your project.
If you will use only apache configuration, you will be enabled FallbackResource index.php in your Directory
Following this configuration : https://symfony.com/doc/current/setup/web_server_configuration.html
See section : Use the following optimized configuration to disable .htaccess support and increase web server performance:

Need some assistance with my apache2 site config file

I'm trying to get apache2 to point to a PHP based application (word press in this case but the config needs to be generic enough to work for any php application).
and it either displays some basic HTML file access page or errors with "You don't have permission". I don't really know apache and I don't know PHP at all. Here's my current site_config file as it stands(with retractions replaced with ):
<VirtualHost *:80>
ServerAdmin <app_user>#localhost
ServerName amazonaws.com/<app_name>
ServerAlias *.amazonaws.com/<app_name>
DocumentRoot /home/<app_user>/<app_location>/staging/current
<Directory /home/<app_user>/<app_location>/staging/current >
AllowOverride All
Options -Indexes
Order allow,deny
Allow from all
</Directory>
LogLevel error
ErrorLog ${APACHE_LOG_DIR}/error.log
</VirtualHost>
I would also like to make it so you can have multiple websites on the same box but I'm not sure how to change the VirtualHost arg *:80 to account for that, I just get loads of ignoring errors.
I also have the following line in my apache2.conf:
DirectoryIndex index.php index.html
Folder permissions are set to 0755 for all files & folders in the project directory
output of apache2 -v:
Server version: Apache/2.4.7 (Ubuntu)
P.s. I know nothing about PHP and very little about apache2 so for this, speak to me as a total noob.
To solve The first problem I had to change the following lines:
Order allow,deny
Allow from all
to:
Require all granted
this finally allowed apache to allow users access to the folders, the second thing was to add an alias:
Alias /<app_name> "/home/<app_user>/<app_location>/staging/current"
and it started working as expected so now my site config looks like:
Alias /<app_name>"/home/<app_user>/<app_name>/<app_environment>/current"
<Directory "/<app_name>"/home/<app_user>/<app_name>/<app_environment>/current">
AllowOverride All
Options -Indexes
Require all granted
</Directory>
<VirtualHost *:80>
DocumentRoot "/<app_name>"/home/<app_user>/<app_name>/<app_environment>/current"
ErrorLog "/var/log/apache2/<app_name>.error_log"
CustomLog "/var/log/apache2/<app_name>.access_log" combined
</VirtualHost>

Cant Access a "error" folder in subdomain.localhost/error/

I am trying to put all of my error documents into one folder in my website root.
Ideally I would like all of my error documents to go into http://subdomain.localhost/error/ but whenever I load the URL in my browser I get a message Access forbidden! Error 403.
I then removed the .htaccess file from the document root. The content of the .htaccess file is:
ErrorDocument 403 /err_docs/401
ErrorDocument 401 /err_docs/401
ErrorDocument 404 /err_docs/404
ErrorDocument 500 /err_docs/500
IndexIgnore * # prevent directory listing
Order deny,allow
Allow from *
/err_docs/ is my current folder for my error documents - (Because /error doesn't work).
Upon inspecting the apache error log I find:
[Thu Jun 25 13:46:57.445385 2015] [autoindex:error] [pid 5104:tid 1760] [client 127.0.0.1:51853] AH01276: Cannot serve directory C:/xampp/apache/error/: No matching DirectoryIndex (index.php,index.pl,index.cgi,index.asp,index.shtml,index.html,index.htm,default.php,default.pl,default.cgi,default.asp,default.shtml,default.html,default.htm,home.php,home.pl,home.cgi,home.asp,home.shtml,home.html,home.htm) found, and server-generated directory index forbidden by Options directive
I have tried the following:
Removed .htaccess from the document root. (From both the sub domain and the domain).
Checked that there isn't another .htaccess file in apache's folders
I am happy to go finding the result on google but I have no idea what to search. Can any body tell me where to start looking for the issue, or what to look for?
Update
This is the contents of my virtual hosts config file:
NameVirtualHost localhost:80
<VirtualHost *:80>
<Directory "C:\web">
Options Indexes FollowSymLinks MultiViews Includes ExecCGI
AllowOverride All
Order Allow,Deny
Allow from all
Require all granted
</Directory>
ServerName localhost
ServerAlias localhost
DocumentRoot "C:\web"
</VirtualHost>
#######################################
NameVirtualHost localhost:80
<VirtualHost *:80>
<Directory 'C:\\Personal\\Web'>
Options Indexes FollowSymLinks MultiViews Includes ExecCGI
AllowOverride All
Order Allow,Deny
Allow from all
Require all granted
</Directory>
ServerName personal.localhost
ServerAlias personal.localhost
DocumentRoot 'C:\\Personal\\Web'
</VirtualHost>
#######################################
I was having exactly same problem today. While googling I came to this question. Since the question was unanswered and none of the comments helped me, I asked a new question with my observation that /error was being served from ServerRoot instead of DocumentRoot. In the comments I got a suggestion to check for an alias for /error. Finally I got the alias in the file xampp/apache/conf/extra/httpd-multilang-errordoc.conf. Commenting the Alias directive makes error folder in document root accessible. Please note that commenting the alias may have side-effects as there are many uses of /error folder-files in other configuration files mostly to define ErrorDocument.

Slim Framework routing doesn't work in my code

I'm new to this, I have a problem with following code:
<?php
require_once 'vendor/autoload.php';
require_once 'lib/controller/Root.php';
require_once 'lib/controller/General.php';
$app = new \Slim\Slim(array(
'debug' => true,
));
$root_controller = new Root();
$general_controller = new General();
$app->map('/', function() use ($app, $root_controller) {
$root_controller->index();
})->via('GET', 'POST');
$app->map('/vorstand', function() use ($app, $general_controller) {
$general_controller->vorstand();
})->via('GET', 'POST');
$app->map('/satzung', function() use ($app, $general_controller) {
$general_controller->satzung();
})->via('GET', 'POST');
$app->run();
?>
I'm using the slim framework and I can't call the routes localhost/vorstand or localhost/satzung everytime I get "Not found" And I have no explanation for that :/ only localhost which means the route "/" works.
For Apache server, two things need to be check.
1.The .htaccess file in the directory (same directory with your index.php) contains:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
2.You also need a directory directive to enable .htaccess files and allow the RewriteEngine directive to be used. This is sometimes done globally in the httpd.conf file, but its generally a good idea to limit the directive to just your virtual host by enclosing it in your VirtualHost configuration block. This is generally setup in your configuration in the form of:
<VirtualHost *:80>
ServerAdmin me#mysite.com
DocumentRoot "/path/www.mysite.com/public_html"
ServerName mysite.com
ServerAlias www.mysite.com
#ErrorLog "logs/mysite.com-error.log"
#CustomLog "logs/mysite.com-access.log" combined
<Directory "/path/www.mysite.com/public_html">
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Add AllowOverride All to your DocumentRoot Directory.

Silex slugs cause 404 page not found

Following the documentation, Silex allows "slugs" to be passed in via the URL for use within your code.
The following example works:
$app = new Silex\Application();
$app->get('/', function () {
return 'HAI';
});
However, the following gives a 404 Not Found:
$app = new Silex\Application();
$app->get('/{slug}', function ($slug) {
return 'HAI' . $slug;
});
How can I fix this 404?
In case it's of any relevance, here's my Apache Vhost:
<VirtualHost 127.0.0.1:80>
DocumentRoot "/var/www/Silex/web"
DirectoryIndex index.php
<Directory "/var/www/Silex/web">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
...and my directory structure:
/src
|-- bootstrap.php
/tests
/vendor
/web
|-- index.php
It turns out that this was an Apache issue. It was assumed that you could either use a .htaccess file, or a vhost. You actually need to use both.
.htaccess:
FallbackResource /index.php
Note: You can only use FallbackResource if using Apache 2.2.16 or higher.
vhost
<VirtualHost 127.0.0.1:80>
DocumentRoot "/var/www/Silex/web"
DirectoryIndex index.php
<Directory "/var/www/Silex/web">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
An alternative is to place the contents of the .htaccess file (the FallbackResource directive) within the vhost itself, and get rid of the htaccess.
As soon as I added the .htaccess, the slug in my second example worked.

Categories