An issue while hosting laravel project in server(local and live) - php

I want to host a laravel project in a dedicated server(aws, ubuntu 14.04).
So I placed the project in /var/www/html. When I go to 11.111.11.111/projectFolder/public the default welcome page is showing up,
but when I move to 11.111.11.111/projectFolder/public/login, I get an error - Page not found, interestingly 11.111.11.111/projectFolder/public/index.php/login, the login page is showing up but styles and jss files are missing.
Failed to load resource: the server responded with a status of 404 (Not Found)
http://11.111.11.111/js/app.js Failed to load resource: the server responded with a status of 404 (Not Found)
All these css and js files are present in public folder of laravel app.
These work perfectly when I run project using php artisan serve
The .htaccess file is as below,
<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}]
I just want to change the .htaccess file, so when I type 11.111.11.111shows the application as when run normally.

If you want to see your project directly with http://11.111.11.111, you must change the DocumentRoot setting in your httpd.conf file.
In your /etc/apache2/sites-available/000-default.conf file, change the directory root to:
DocumentRoot /var/www/html/projectFolder/public

Related

Laravel 8.4 – Remove Public from URL

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]

Files in Public folder don't show up [Laravel]

I have a website in production that cannot access some folders in public/css. I checked permissions on all folders, checked my .htaccess in public folder, I cannot find the reason why some folders show up in my local version Local, but not in my production version Prod.
For example for this :
<link rel="stylesheet" href="{{ asset('css/directives/gallery.css') }}"/>
In my local version, it works because the folder directives shows up, but in production I get a 404 error.
Failed to load resource: the server responded with a status of 404 (Not Found)
This is how it looks on my production server Production Files, and inside directives
Website is written in PHP using Laravel 5.4, below is my .htaccess file in production, it is the same as in my local version.
Thanks
<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>
Give all permissions to the public folder
chmod -R 777 public
Is the owner and the group of 'directives' directory the same as in other directories ?

Laravel Showing Index Of / after uploading the site but works fine on localhost

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.

Deploying laravel 5.4 project in shared host

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.

laravel app generating an internal server error on shared hosting

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>

Categories