Laravel Version - 5.8.
I have to deploy my Laravel project on Shared Hosting without using php artisan serve command. So for that reason, I have renamed my root file server.php file to index.php.
Will there be any security consequences or bug, if I rename the file server.php to index.php?
you don't need to rename server.php to index.php. Just move the Public/index.php to the root of the folder and change the necessary path inside the index.php after moving. It will work for sure.
If you using cPanel, you can change webroot to public very simple don't need to rename server.php. If not you can using .htaccess to redirect all request to public folder like this :
# public_html/.htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect All Requests To The Subfolder
RewriteRule ^ /public
</IfModule>
Related
Please, some help for deploy Laravel 5.2 website, in below error message in public_html/error_log :
[21-Mar-2017 07:39:30 America/Chicago] PHP Fatal error: require(): Failed opening required '/home/exoweb/public_html/allos/bootstrap/autoload.php' (include_path='.:/opt/alt/php55/usr/share/pear:/opt/alt/php55/usr/share/php') in /home/exoweb/public_html/index.php on line 22
I succeeds to start my web site, by changing the index.php file in public_html
require DIR.’/../allos/bootstrap/autoload.php’;
$app = require_once DIR.’/../allos/bootstrap/app.php’;
BUT I have an error when my controller uses a request with Eloquent, by against it works very well with query builder!
run composer update in the application directory. Always run composer update when you move an application which has composer as its dependency manager.
If there are still errors and you dont have access on Ssh , maybe tray to delete the cache files :
Bootstrap : services.php, settings.php Delete
Storage/Framework/Cache Delete all files
Storage/Framework/session Delete all files
Storage/Framework/views Delete all files
And refresh the site.
good luck :)
Have you try to access your website like your-site-url/public?
If it is running successfully in public directory then you just have a problem of redirecting.
So, place this .htaccess file into your root directory.
If your application is built in php version 7 then use this .htaccess file.
AddHandler application/x-httpd-php70 .php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
for rest of the php version<7, use this .htaccess file.
AddHandler application/x-httpd-php56 .php .php5 .php4 .php3
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
I have a Laravel 5.3 website, but now that I want to put it online on my server, I realize that I can't change the vhosts to make it work properly.
How can I make my website work, without vhost? I now that Zend Framework can run just fine using only .htaccess configurations. That is a way of doing it for Laravel?
The solution should allow the website to work both ways: with and without the vhosts!
This is may help.
copy everything from myproject/public to public_html
open public_html/index.php and set:
require DIR.'/../myproject/bootstrap/autoload.php';
$app = require_once DIR.'/../myproject/bootstrap/start.php';
and put this on top:
ini_set('eaccelerator.enable', 0);
Last create a .htaccess file on root directory.
Create an .htaccess file on your laravel's root directory.
This is to access it without the "public" on the url.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
I'm using Laravel 5.3 is there a easy way to remove public from URL? is it necessary to add a htacces. when I change the htacces it is getting a n error like below,
copy both htaccess and index.php file from public folder to root directory and then change root index.php code as below
require __DIR__.'/bootstrap/autoload.php';
$app = require_once __DIR__.'/bootstrap/app.php';
After installing Laravel, you should configure your web server's document / web root to be the public directory. The index.php in this directory serves as the front controller for all HTTP requests entering your application.
https://laravel.com/docs/5.3/installation#configuration
Do not edit .htaccess or Laravel related files, just point web server to a public directory instead of Laravel project directory:
DocumentRoot "/path_to_laravel_project/public"
<Directory "/path_to_laravel_project/public">
Then restart Apache.
Add a .htaccess file in root which contains -
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
Yes it is very simple no need to add extra htaccess,
Create a new folder in your laravel project folder.
Name it whatever you like. Example :- source
Move all the files from root into 'source' folder except 'public' folder.
4 . Move all the files from public folder to root.
5 . Change the autoload.php path
6 . Thats all. remove public folder if necessary.
In the root directory create a .htaccess file and put the following in
it
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
Even above solution(s) work(s) for you,but I would recommend not to do this.
Here is the reason why.
-You should be pointing your Apache host root to the $LARAVEL_PATH/public directory instead of $LARAVEL_PATH.
-you have to configure apache for user not access .env, git files , config folder's file
public directory is there for reason to make project a bit more secure. Solve the actual problem and don't try to break this simple but nice security addition.
Copy all files and folder from public folder to root folder and edit your .htaccess file as
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
And dont forget to change the paths in index.php file.
For details refere following links
Installing Laravel in a subfolder
https://ellislab.com/forums/archive/viewthread/151342/#734511
I have a question (and really tried already a lot of things).
this is the folder structure on my root:
.htaccess (root)
/2014
/2015
/2016
/2017
.htaccess (2017->laravel redirect)
public
index.php
css
where 2017 has a Laravel website.
I know I need an .htaccess file inside the 2017 folder to rewrite to the public folder where the index.php file is /public
This is the .htaccess file in the 2017 folder to achieve this:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
First problem I have here is that now inside my Laravel code, when I access the website via www.dotfmp.com/2017 the $REQUEST_URI contains now "2017/{page}" instead of only "{page}".
My second question is what should be my .htaccess file in the root, so that any request coming on the www.dotfmp.com website will go to /2017 folder, however www.dotfmp.com/{folder} should go to the intended folder.
An answer would be nice, an explanation even better, and a good resource the best :)
Thanks in advance
Andries
Here is my Directory Structure
localhost/project or livehost/project
-app
-bootstrap
-public
-vendor
Where i have /project as a folder inside the htdocs.
Now i am accessing the project by
localhost/project/public/
localhost/project/public/blog // for submenu
How can i remove the /project/public/ and use only the localhost/project and localhost/project/blog
And if move to live i will be having the project folder as main so How can i have the .htaccess for the localhost (which is inside the project folder) and live (which will be in the root)
Here is the .htaccess i had for the the live (where the files will be on the live)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
Rename the server.php in the your Laravel root folder to index.php and copy the .htaccess file from /public directory to your Laravel root folder. -- Thats it !! :)
First you have to make sure mod_rewrite is enabled on your server (you can go here if you don't know how to do). If it's already enabled but URL rewrite seems to not work, you can refer to "pretty URL" chapter of Laravel's documentation : http://laravel.com/docs/4.2/installation#pretty-urls