Allow php files to be accessed in laravel public folder - apache

I have a Laravel project that using Roxy Fileman as file manager. I put the files of Roxy Fileman under the public folder
/public/fileman
so I can access it by
<ifarame src="my.domain/fileman/index.html"></iframe>
the iframe will load data from PHP files in the plugin folder which located at
/public/fileman/php
It works well on my local XAMPP server but says E_LoadingAjax php/dirtree.php on my linux server, and returns 404 when I try directly access these files
I assume it is because PHP files are blocked from direct access for security reasons.
Then how can I allow this specific folder to be accessed? or what is a better approach to use Roxy Fileman in laravel?
.htaccess comes with Laravel:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>

Open up composer.json and find section with autoload, and add files array, see example below (I created folder folder inside public folder which contains file tst.php) so I have public/folder/tst.php
Now when I visit 1.1.1.1/folder/tst.php PHP interprets me the code.
.
.
.
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/",
},
"files": [
"public/folder/"
]
},
.
.
.

Related

Laravel Project - After upload hosting server faced the issue for 500 Server Error and website menu link issue

I have faced the issue for website not working properly.[Project file uploaded in sub folder].
Folder Path : example.com->public_html->lrvproject
Please note the below issues:
Home Page - 500 Server Error. https://www.example.com/lrvproject/
Sub Pages open - I have manually enter page path it's showing page.
Example: https://www.example.com/lrvproject/contact
After loading subpages Menu link URL showing is "https://www.example.com/contact".
I have refer the tutorial inside public(folder copy all file and paste outside public folder).
index.php [https://www.example.com/lrvproject/index.php]
if (file_exists(__DIR__.'/../storage/framework/maintenance.php')) {
require __DIR__.'/../storage/framework/maintenance.php';
}
require __DIR__.'/../lrvproject/vendor/autoload.php';
$app = require_once __DIR__.'/../lrvproject/bootstrap/app.php';
$kernel = $app->make(Kernel::class);
$response = tap($kernel->handle(
$request = Request::capture()
))->send();
$kernel->terminate($request, $response);
web.php (routes)
use Illuminate\Support\Facades\Route;
//use App\Http\Controllers\UserAuthController;
Route::get('/','HomeController#index');
Route::get('/about', function () {
return view('pages/about');
});
Route::get('/gallery','ImageGalleryController#index');
Route::get('/contact','ContactController#index');
Route::post('/contact','ContactController#sendmail');
server.php [https://www.example.com/lrvproject/server.php]
$uri = urldecode(
parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)
);
if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) {
return false;
}
require_once __DIR__.'/public/index.php';
//require_once __DIR__.'/index.php';
.htaccess [https://www.example.com/lrvproject/.htaccess]
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
# Disable Directory listing
Options -Indexes
# block files which needs to be hidden, specify .example extension of the file
<Files ~ "\.(env|json|config.js|md|gitignore|gitattributes|lock)$">
Order allow,deny
Deny from all
</Files>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Already Server Folder Permission enabled. PHP extensions enabled.
How to solve the issue. please help.
I have solved the issue. I have updated the below steps.
.env file database details updated, now my home page worked.
index.php [https://www.example.com/lrvproject/index.php] -Edit
require DIR.'/vendor/autoload.php';
$app = require_once DIR.'/bootstrap/app.php';
Web menu links URL-Edit
href="/lrvproject/contact" link path update "Contact US"
Clear Cache in Server
My Laravel Application Running in Server (Sub-folder directory)

Laravel Project Not Running On Server

I have deployed my laravel project on server. When I hit the url it gives me error but no log is generated in log folder.
This page isn’t working
[Domain Name] is currently unable to handle this request.
HTTP ERROR 500
I have moved the public folder contents to root directory and edited the index.php.
I checked the permission for storage, vendor and bootstrap folder and they have required permission.
index.php
<?php
define('LARAVEL_START', microtime(true));
require __DIR__.'/vendor/autoload.php';
$app = require_once __DIR__.'/bootstrap/app.php';
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
$response = $kernel->handle(
$request = Illuminate\Http\Request::capture()
);
$response->send();
$kernel->terminate($request, $response);
Server.php
<?php
/**
* Laravel - A PHP Framework For Web Artisans
*
* #package Laravel
* #author Taylor Otwell <taylor#laravel.com>
*/
$uri = urldecode(
parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)
);
// This file allows us to emulate Apache's "mod_rewrite" functionality from the
// built-in PHP web server. This provides a convenient way to test a Laravel
// application without having installed a "real" web server software here.
if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) {
return false;
}
require_once __DIR__.'/public/index.php';
.htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
The project is hosted on shared hosting and I've used filezilla to upload it on server. What else I need to do to make it work. This is my first uploading the project on the server.

yii2 rest api url rewriting (hide directories)

I would like to use clean urls on my yii2 rest api.
I'm having clean urls for my frontend application but I'm failing to create clean urls for my yii2 rest api application.
I created the rest api by following the tutorial (Yii2: RESTful api: tutorial). The rest api uses a module for versioning.
Two .htaccess files have been created.
One file in my root and an another one in my "api/web" directory.
root .htaccess file
RewriteEngine on
# prevent directory listings
Options -Indexes
IndexIgnore */*
# follow symbolic links
Options FollowSymlinks
RewriteCond %{HTTP_HOST} ^api.localhost [NC]
RewriteRule ^(.*)$ api/web/$1 [L,PT]
'api/web' .htaccess file
RewriteEngine on
# If a directory or a file exists, use the request directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward the request to index.php
RewriteRule ^(.*)\?*$ index.php?r=$1 [L,QSA]
Browsing to 'http://api.localhost.com/v1/music' gives a 404 page not found error.
While 'http://api.localhost.com/api/web/v1/music' returns results
(I would like to hide 'api/web/' in my url)
'request' => [
'baseUrl' => str_replace('/api/web', '', (new \yii\web\Request())->getBaseUrl()),
],
Add this request component config in your main api config
Configure the host file to look in /project_folder/api/web

.html removal from URL using .htaccess rewrite rules

I have a static website - a bunch of static html pages. I am trying to remove .html part from the URL of my webpages. I have used an .htaccess file with the following code to do that:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
However, I am getting a 404 error. For example:
The requested URL /home/username/public_html/contact.html was not found on this server.
Ideally, it should redirect to /~username/contact.html.
Addition information
When I used "Options -MultiViews" line above the code it is giving the following error:
500 Internal Server Error: The server encountered an internal error or misconfiguration and was unable to complete your request.
Apache/2.2.15 (Red Hat) server is used here.
Why I am facing this problem? Is root is automatically getting changed from public_html/ folder?
EDIT:
Directory Structure:
Username
.gnome2 (there are empty folders inside it)
.mozilla (there are empty folders inside it)
public_html (I have put css, fonts, js, etc folders and .htaccess, contact.html, index.html, etc files here.)
.bash_logout
.bash_profile
.bashrc
Username folder is under universitynameuniverse folder (whose other folders I cannot see).
Try this code in your .htaccess:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
That’s it! You can now link pages inside the HTML document without needing to add the extension of the page.
Try this:
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule !.*\.html$ %{REQUEST_FILENAME}.html [QSA,L]
</IfModule>
## Results
# ~user/contact => ~user/contact.html (only if file exists)
It only works if the ~user/ directory actually exists on the filesystem.
If you need an external redirect instead, append an R flag to the RewriteRule directive.
The problem with your rewrite rule is that it's appending a .html suffix to the whole %{REQUEST_URI} variable which will probably result in a 404.
Update
Re-reading your question I noted that you want to map the ~user part to somewhere out of the apache webroot. In this case, try this:
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} ^/~(.+)/(.+)$
RewriteCond /home/%1/public_html/%2.html -f
RewriteRule . /home/%1/public_html/%2.html [QSA,L]
</IfModule>
## Results
# ~user/contact => /home/user/public_html/contact.html (only if file exists)

Codeigniter .htaccess: Give public access to all files and folders inside the 'public' folder

I'm using Codeigniter 2.0.3 | Apache 2.2.17 | PHP 5.3.4.
I'm want to give access to all the files and subfolders inside the 'public' folder. I've read the articles in the Codeigniter wiki and also all first 5 pages on google results and found nothing that works.
This is the files tree:
- application
- public
- css
- style.css
- img
- js
- system
- .htaccess
And this is the .htaccess I'm using to remove 'index.php' from the URL and try to give access to the folder:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /CodeIgniter_2.0.3
#Removes access to the system folder by users.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
#Checks to see if the user is attempting to access a valid file,
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#Enable access to the images and css folders, and the robots.txt file
RewriteCond $1 !^(index\.php|public|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
The website is working and 'index.php' is no longer needed in the URL, but the last condition is supposed to give access to the public folder, but its not working for me, so this http://localhost/CodeIgniter_2.0.3/public/css/style.css
file is not found.
In config.php I have:
$config['base_url'] = 'http://localhost/CodeIgniter_2.0.3/';
$config['index_page'] = '';
Please help.
Thanks!!!
With your current structure, you need to change the last RewriteCond to:
RewriteCond $1 !^(index\.php|application\/public|robots\.txt)
because your .htaccess is in the same directory as your application folder and your public folder is in your application folder, you need to explicitly mark the application/public folder as accessible.