I just deployed a Laravel app into Hosting site, and place it into their folder like this:
"example.com/public_html/{All files in a laravel directoy}"
Now, if open in a browser, https://example.com it will show error
Fatal error: require(): Failed opening required '/home/customer/www/example.com/public_html/public/../vendor/autoload.php' (include_path='.:/usr/local/php74/pear') in /home/customer/www/example.com/public_html/public/index.php on line 34
my routes/web.php looks like this:
Route::get('/', function () {
return redirect()->route('login');
});
I already ran composer install and add htaccess to the inside public_html folder
The htacess, looks like this
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com$ [NC,OR] RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteCond %{REQUEST_URI} !public/
RewriteRule (.*) /public/$1 [L]
Is my htaccess wrong, or is there any additional setup for Laravel if using htaccess to point index.php to public folder?
Note:
The hosting site, set the default document root to public_html and I can not change it. So in order to point to the public folder, I need to create .htaccess file
Place .htaccess file to your root folder and activate mod_rewrite.
Here's an example of what the file should contain without determining specific addresses:
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
I think that it doesn't work in your case because of the condition rules.
Copy the Laravel contents in a directory that's hidden from the outside, one different than public_html. Let's suppose that it's /home/user1/myapp.
Move the contents of the Laravel public directory to the public_html. So, you should move /home/user1/myapp/public/* to example.com/public_html
Change the relative routes inside index.php to point to the directory of the first step.
Related
I've develop a laravel web application, and I have to upload to a hosting that already have a WordPress application, the file system looks like this:
/..
etc/
public_html/
..
wordpress_files_everywhere
..
tmp/
tmpsite/
I have not access to root folder, online to public_html, so I've created two folder inside public-html (laravel-backend, laravel-frontend).
So What I did is edit index.php in order to point laravel-backend files like this:
require DIR.'/../laravel-backend/bootstrap/autoload.php';
$app = require_once DIR.'/../laravel-backend/bootstrap/app.php';
Also I add this function to register method on app/Providers/AppServiceProvider
$this->app->bind('path.public', function() {
return base_path().'/public_html';
});
But the page still not found, I don't know what I'missing, My suspects is that I have to configure htaccess file in order to point my domain URL to public folder, But I don't know how to do it.
Any clue?
You need to make your url point directly to laravel-frontend/public and add extra ../ in index.php file. Assuming your public seats inside of laravel-frontend:
require __DIR__.'/../../laravel-backend/bootstrap/autoload.php';
$app = require_once __DIR__.'/../../laravel-backend/bootstrap/app.php';
Else, just rename your public folder to laravel-frontend and replace the existing larqavel-frontend so both folders are at the root level of public_html.
Also pay attention to how you type DIR. I think in laravel index.php it's typed as __DIR__
I could fix it by configuring the .htacess file as follows (Following the indications of this link http://enkognedo.com/internet/hosting-and-websites/89-multidomain.html)
RewriteEngine On
RewriteCond %{HTTP_HOST} wordpressUrl$ [NC]
RewriteCond %{REQUEST_URI} !/.*$
RewriteRule ^(.*)$ /$1 [L]
RewriteCond %{HTTP_HOST} laravelAppUrl$ [NC]
RewriteCond %{REQUEST_URI} !^/laravel-frontend/.*$
RewriteRule ^(.*)$ /laravel-frontend/$1 [L]
i really don't kwow if this has any security problem, by solve my issue.
I have a route issue, I can't point localhost/test/ into my index page of my site.
When I define a route like:
`Route::get("/",IndexController#index);`
localhost/test/ would work fine , but also localhost/test/admin, localhost/test/en localhost/test/foo localhost/test/undefined-route and will load my index page of the site.
and beside when I have namespace Route like:
Route::group(['namespace'=>'Admin'],function(){
Route::controller("admin"=>"AdminController");
})
If I type localhost/test/foo/admin everything works fine but when I write:
localhost/test/admin just my index page of the site.
I don't know whats wrong here, Route problem or .htaccess redirecting my and I'm not aware of it.
Sorry for code misspelling I just wrote what I recall from last night.
Note:: I have an index file in my root directory
my .htaccess file of my root directory is like below, and I replaced the server.php file of my root directory with my index.php file:
RewriteEngine On
RewriteCond %{REQUEST_URI} !-f
RewriteCond %{REQUEST_URI} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
and my .htaccess file of my public directory is like default.
Upgrading to Laravel 5.3 seems to Solved the Route Issue,
why don't you run (from terminal):
php artisan serve
then test your project at: http://localhost:8000/ instead of: http://localhost/test/
or if you are using apache, add new virtual host
I have a legacy project on a server where the actual framework is in a folder above the public_html folder. So the directory structure is like this:
domainname.com
app/
framework/
public_html/
index.php
Now I want to place this on our own server. This is an application created by the hosting company. The root folder is default. So now my directory structure is like this:
default/
app/
framework/
public_html/
index.php
Now he's pointing to the default folder instead of the public_html folder. That's the only difference with the old version. So I've added a .htaccess file to the root folder default. The content of this file is:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /public_html/$1 [QSA,L]
</IfModule>
In my public_html folder I have a .htaccess file like this:
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule . index.php [QSA,NS]
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule . /index.php [L,QSA,NS]
So when I go to my website it works. But when I click on a link I get: http://domainname.com/public_html/theclickedpage/.
But I don't want the public_html in my url. How can I fix this?
You may want to search for a way to make a virtual host. I know some of my webhost let me configure the vhost through my admin page. It will let your server consider the url without including the specified folder, but back in the stage it performs needed redirection.
You applied correct rule ,
but the problem is link for the solution of this issue you have to
remove public_html from
your all links and it will automatically redirect to your required
path without public_html.
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 am sorry about this, but my htdocs root is wrong and I can't change that. So I have to make it work in the /public folder.
I use the normal Laravel .htaccess file with the following rewrite:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
If I open http://kemtime2_neu.pr.domain.de/public I get redirected to http://kemtime2_neu.pr.domain.de/public/http://kemtime2_neu.pr.domain.de/public/login
How can I fix this?
I would love to make it work from http://kemtime2_neu.pr.domain.de/ but getting it to work with http://kemtime2_neu.pr.domain.de/public/ would be fine.
I use the 3 solution of this post and works fine:
http://web.archive.org/web/20130320184846/http://forums.laravel.io/viewtopic.php?id=1258
Solution 1 - Alternate installation path with symlink.
This is the preferred solution and in general an all-around good idea. It's possible to install your application to a folder unrelated to public_html/ and then symlink the public folder to the public_html/ path.
For example:
Install your application to /home/applications/mysite.com
Imagine that your DocumentRoot points to /var/www/vhosts/mysite.com/httpdocs
Remove the httpdocs folder from the mysite.com vhosts folder then connect the two with a symlink: ln -s /home/applications/mysite.com/public /var/www/vhosts/mysite.com/httpdocs
Solution 2 - .htaccess with mod_rewrite
This solution enables you to drop Laravel into your public folder then use a .htaccess file to redirect requests to the public folder. This solution places your application and core system code into a publicly accessible folder. This is not something that we encourage you to do with any PHP framework.
Step 1. Place Laravel in your document root folder.
Step 2. Place the following .htaccess file in your document root folder.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
Step 3. Make sure that you manually set your 'url' configuration in application/config/application.php otherwise Laravel will generate incorrect URLs. Make sure that each of your environments have the correct application.url configuration. For more information on environment-specific configurations see: http://laravel.com/docs/install#environments
Solution 3 - merge the public folder into the installation root
This solution places your application and core system code into a publicly accessible folder. This is not something that we encourage you to do with any PHP framework.
Copy the contents of the public/ folder into your Laravel installation folder then change this line in your index.php file from:
require '../paths.php';
to
require 'paths.php';
Keep in mind that any bundles, libraries, or other types of third-party code may not be designed to be publicly accessible.
Note: It's also important to note that your bundles/ and public/bundles/ directories will now conflict. When using this approach you may want to not use artisan's bundle:publish task without knowing exactly what your bundles want to publish.
I solved it partly. If I have a .htaccess in the root instead of /public with
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /public/index.php/$1 [L]
I can open http://kemtime2_neu.pr.domain.de/login but the images and css is still wrong. I need to check first if the files exist in /public. I think this is a new question.