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.
Related
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.
I'm trying to deploy my laravel (Laravel Framework 7.28.3) to Cpanel, but got a 404 error.
I uploaded my project into /public_html, modified the index.php file to point to the correct files (as below).
I think there must be some mistake in the index.php file but couldn't figure it out.
This is my first time asking my question (after searching for it several times), so hope that I will get the answer!
require __DIR__.'/../vendor/autoload.php';
$app = require_once __DIR__.'/../bootstrap/app.php';
this is my file structure in File Manager:
Deploy laravel application in Cpanel
Setup 1 : - upload file to Cpanel the root directory – not the public_html.
Setup 2 : - Open the that folder and MOVE the CONTENTS of the public folder to your cpanel’s public_html .
Setup 3 : - Navigate to the public_html folder and locate the index.php file. Right click on it and select Code Editor from the menu.
and change this line
require __DIR__.'/../folderName/vendor/autoload.php';
$app = require_once __DIR__.'/../folderName/bootstrap/app.php';
NOTE : - folderName here is in root where you laravel application stay
that's it now all your request will come inside public_html folder index.php and this file will include require __DIR__.'/../folderName/vendor/autoload.php; and run laravel application
Folder structure will look like
/laravel
/public_html/index.php
indside index.php
require __DIR__.'/../laravel/vendor/autoload.php';;
$app = require_once __DIR__.'/../laravel/bootstrap/app.php'; // here laravel is folder name
You need to make sure your application is in a folder outside of your public_html.
Then you need to make a symbolic link to everything in your public directory inside your application. This symbolic link should be placed in your public_html.
This way your business logic is not available from the outside, only from your own application.
Actually it is advisable to clone your application using git and then install it following the steps in de docs. (https://laravel.com/docs/7.x/installation)
In your public/.htaccess file replaces the code given below..make sure that you uploaded your project in the root public_html folder.
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ ^$1 [N]
RewriteCond %{REQUEST_URI} (\.\w+$) [NC]
RewriteRule ^(.*)$ public/$1
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ server.php
I have a simple user system in my site. The URL works like this: /profile/user?id=user_id
I wanted to do something like /profile/user/user_id instead, and I found the following code to use in htaccess.
RewriteRule ^user/(.*)$ user.php?id=$1 [L]
The code does work as intended, but after doing that I found out that I can't access any other file inside of the profile directory besides the index file. All of them return a 404 error.
There's a couple more of important pages in there, so I would need to access them. I can't access user.php without an ID either, but that's not my main concern, even though I would also like to access it if possible.
I'm not really used to use RewriteRule, so I'm not really sure what's going on here. What can I do?
EDIT: I was asked to give more info, here we go.
The profile folder full route is /en/profile
Structure of the profile folder:
profile/settings.php (directory index)
profile/user.php
profile/change_avatar.php
profile/change_avatar_upload.php
profile/change_email.php
profile/change_password.php
profile/custom_utgen_characters.php
profile/custom_utgen_character_editor.php
profile/reset_password.php
Other lines in the htaccess file:
DirectoryIndex settings.php
htaccess file in the root folder of the website:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
This is all the relevant option I could get, I hope it helps.
I tested your rewrite rule and directory structure and had no problems to access files in the profile directory. Can you provide more information like the complete .htaccess file and the directory structure laying under profile?
EDIT: The .htaccess in your profile folder overwrites the .htaccess in your root folder. To prevent this, you have to add the line
RewriteOptions inherit
to the .htaccess file in the profile folder.
I have been seeing several PHP online tutorials where they recommend that you have a public folder where you have your index.php and other views, css, js, etc and another folder (usually called app) where you have your classes and such. The idea is for the site to use the public folder as default so no one will be able to access the classes. The question is, once I upload the public and app folders to my server, how do I get the users to public/index.php when they type in mypage.com (without them having to type mypage.com/public).
You can use this .htaccess file, Place it in root folder of your website:
RewriteEngine on
RewriteCond %{HTTP_HOST} example\.com [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ /public/$1 [L]
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.