I am trying to deploy my Laravel 8 app to a folder in CPANEL (first time I've deployed Laravel). I have searched the forum and made changes as the many posts direct. I am getting 404 errors across all pages apart from the homepage and login and register pages. This is a common error but I cant find a solution. Dont shoot me.
1.All files uploaded to url/laravel/blog
Public folder moved outside and renamed public_html
The /laravel folder now has two directories /blog and /public_html
index.php in the public_html folder updated:
require DIR.'/../blog/vendor/autoload.php';
$app = require_once DIR.'/../blog/bootstrap/app.php';
New .htaccess file added to the root of the public_html and set to chmod 755 (detailed below)
Renamed the cache folder in the /bootstrap folder so that new cache is created (I hope)
Database is linked within the .env file
I am out of ideas, I have created a test html file in the public folder and I can see this in the browser when I navigate to it. I am learning and any help will be appreciated.
<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]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
I needed to point the subdomain/add-on domain to the public folder. No need to move anything or change Htaccess etc.... Credit to https://stackoverflow.com/users/2325620/james-clark-developer
Try this in your .htaccess
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^$ public/index.php [L]
RewriteRule ^((?!public/).*)$ public/$1 [L,NC]
</IfModule>
Related
I am working on creating a website that converts text into speech. I am using the script from codecanyon which is Developed with PHP 7.4.x and Laravel 8.4.x . The issue I am facing is that I don't want to show /public URL as a permalink to access the website. Now, if I type mywebsite.com/pubic then the website is accessible otherwise if I write mywebsite.com then it only shows the files. I followed some of the previous queries posted on StackOverflow but got no results.
The topic I followed is Laravel 5 – Remove Public from URL
I tried even by renaming server.php , copying .htaccess and rewriting it. But those all resulted in a screen showing up errors or even blank.
My .htaccess file is;
<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]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
To remove the /public from the URL you are not going to use the .htaccess file.
What you are going to do instead is set the /public folder as the serving directory for your Server.
If you use Apache, just go to your /etc/apache2/sites-available/000-default.conf file and change the DocumentRoot from {your base folder}/ (usually /var/www) to {your base folder}/public
The content of public folder should go to the public folder of your server (fe it's public_html on my server), and everything else should be stored in a different folder (fe laravel_mywebsite). Then you should go to public_html/index.php and change the folder paths based on where you put your Laravel app.
If you want to only use .htacces, you just need to rewrite all requests from /public to /
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ /public/$1 [L,R=301]
I am trying to upload a basic site made under Laravel FW. I uploaded the site outside the public_html folder in a folder called laraveltest. I moved the public folder from here to the public_html folder. In this folder I have the index.php file and I changed two lines to :-
inside (public_html/public/index.php)
require __DIR__.'/../laraveltest/vendor/autoload.php';
$app = require_once __DIR__.'/../laraveltest/bootstrap/app.php';
I also changed my .env files that located outside public_html folder, and there a is a folder in the root called laraveltest. I changed the username/ database name and also the password.
When i load the site now, i used to get the page says Index Of / .
After doing some research and youTube videos, I then added a .htaccess file inside the (public_html) folder.
.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 ^ public/index.php [L]
</IfModule>
Now when I reload the page, I get an error
This page isn’t working mylivewebsite.com is currently unable to handle
this request. HTTP ERROR 500
I have also checked the permission and it is all set to 0777 as well.
Please let me know how can I make my website run correctly.
I‘m facing some problems with my Laravel 5.4 project. I’ve created my project on localhost everything is working, no problems. Now I need this project to work on shared host. So, I rent a server, create database, create a folder in the same level as public_html, upload all files and folders (except public folder and its content) in this folder. Public folder content I put in public_html folder. I also make changes in my index.php file in public folder and changed two lines:
require __DIR__.'/../my_folder/bootstrap/autoload.php';
$app = require_once __DIR__.'/../my_folder/bootstrap/app.php';
In .env file besides database connection lines, I’ve also changed line DB_HOST=127.0.0.1 to DB_HOST=localhost
When I try to run my project on shared host, the starting page works perfect, but when I try to navigate to other pages, I‘m getting error connecting with routes (NotFoundHttpException in RouteCollection.php)
My .httacces file content is:
<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]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
Maybe I need some changes here? I really appreciate any help.
I have this .htaccess in the laravel installation directory
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
And this .htaccess in the public directory of the laravel installation directory (this one came with the 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]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
So, if I access the root/installation directory in the browser, like this http://something where something is the installation directory and has it's own virtual host on localhost, then it works and if I access it like this http://something/public then it works too. But this setup doesn't work on the production server. If I access my website(which is a subdomain) on production server like this http://sub.something.com then it doesn't work, this shows me Page not found error, but this works http://sub.something.com/public
What am I doing wrong?
I have namecheap.com shared hosting
On share hosting subdomain, it's good your folder structure look like this:
I assume it's a linux server (Apache)
--public_html
----subdomainFolderName (content of public folder)
-------.htaccess
-------index.php
-------etc
-------laravelFolder [Public folder will not be inside here]
----------app
----------bootstrap
----------config
----------etc
Edit subdomainFolderName/index.php
Change line 22
require __DIR__.'/../bootstrap/autoload.php';
TO
require __DIR__.'/laravelFolder/bootstrap/autoload.php';
Change line 36 $app = require_once __DIR__.'/../bootstrap/app.php';
TO
$app = require_once __DIR__.'/laravelFolder/bootstrap/app.php';
This way you will not have issues with .htaccess and your URL will not contain /public
I'm trying to deploy a laravel app on shared hosting. Here is what I did.
I zipped the entire laravel-app directory on my local machine.
I uploaded it and then unzipped the app in the public_html folder on the server.
I changed the file permissions of the public_html/larvel-app and public_html/laravel-app/storage and public_html/laravel-app/public to 777.
I removed the line 'public' in the .gitignore file.
I then copied the index.php and .htaccess file from laravel-app/public to the homepage and pointed to the necessary autoload folders (the ones about require and the $app variable to laravel-app/public).
Problems: If I navigate to my-website homepage, all the HTML for the homepage is being pulled in but no CSS or JavaScript or images. If I navigate to my-website/laravel-app/public, I see an internal server error message (error 500). However I have been able to view the files of other folders in the laravel-app subdirectory.
I include a copy of my .htaccess file code here.
<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]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>