I was given a laravel project I need to get up and running. I am new to laravel, but after allot of work, I believe I got everything configured properly and I deployed the project to heroku.
When I do artisan serve on my guest machine in my laravel project and go to the given url everything works fine all the links works.
But I deploy it to heroku and my index page shows but none of the links work.
I get:
Not Found The requested URL /register was not found on this server.
It seems that running php artisan serve kinda activates the links, but how do I make that happen on heroku???
I should note the app is using blade.php files
What am I missing???
This is in the /resources/views
My _htaccess inside my public folder is as follows
<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 tried adding RewriteBase / doesnt help.
I also tried changing htaccess to:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
And my Procfile has:
web: vendor/bin/heroku-php-apache2 public/
Thanks
Well I resolved my issue, it seems that I had some lowercase letters in my web.routes path
that should have been Capital letters. Local host dosen't seem to mind if the words are uppercase or not, but linux does seem to mind.... Not sure if it will help, but i searched a long ass time for something so silly...
I had to restart my dynos for it to work, run heroku restart
Also make sure to have a Procfile in your root with
web: vendor/bin/heroku-php-apache2 public/
I resolved with:
In config/app.php
I changed for:
'asset_url' => env('ASSET_URL', 'https://appcreated.herokuapp.com'),
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 have an laravel app working fine on my local machine. I have just transferred it to my server (Shared hosting) and put everything on a public folder in public_html and everything else in one step above public_html. The problem is now it shows 500 internal error on every route. I have changed .htaccess code to given code on documentation, folder rights to storage and bootstrap are set to 777.
Nothing in error logs and also nothing in laravel log files. when I installed fresh laravel installation it worked on the server as well. Tried updated code with my project but still 500 internal error.
For Laravel 8 / IONOS Managed Server this works for me:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteBase /
Options +FollowSymLinks
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]
</IfModule>
If you are using IONOS (or 1and1, maybe works fot other too...), the .htaccess file should be different from the default in laravel public directory.
Replace its content with this:
RewriteBase /
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
The error may be due to the configuration of .env file.As your question is not clear enough. so i wil explain 2 methods
With vendor and .env file (Not Recomended)
- Unzip the main zip file and upload your public_html folder ( upload
vendor folder as well)
Give 777 recursive permission to storage/ and bootstrap/ folder
Create database in phpmyadmin and import .sql file
Set Database in .env file
Now normally for all shared hostings you will have jailed SSH you can contact the hosting provider to get its details.
Once you get access , use command
php artisan cache:clear
php artisan config:clear
php artisan config:cache
The file itself can be found in bootstrap/cache/config.php.
Note that the location of the compiled config file has changed recently. Yours might also be in vendor/config.php or storage/framework/config.php. With a fresh install or if you run composer update the file should be in bootstrap/cache though.
Now Directly from GIT or other Sources without Vendor(Recommended)
Make sure you copy all of the project files including the hidden ones(.env).
if You are using GIT use GIT clone to clone the project.
Check you have all the necessary PHP extensions available in php.ini as in Laravel requirements. Also, watch your PHP version!
Install composer https://getcomposer.org/doc/00-intro.md
When copied, go to your destination folder and run composer install.
Run php artisan key:generate from the command line.
then Run
php artisan cache:clear
php artisan config:clear
php artisan config:cache
http://php.net/manual/en/install.windows.commandline.php
Make sure your webserver is serving pages from project/public folder.
Even after completing these steps if Laravel is still showing error, check
your_project/storage/logs/laravel.log
Laravel default .htacces won't work for IONOS.
This is the perfect .htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteBase /
Options +FollowSymLinks
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]
</IfModule>
The laravel application seems to have routes issue with the sub-directory on server. With the running application on local machine does not work on temporary domain in sub-directory on live server. Playing around .htaccess seems to have different results.
This question is almost identical to what I would be looking for but he hasn't got any solution while I have got some work around.
The .htaccess within the laravel public have been modified to something like:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
RewriteBase /~timely/email-client //<--base has been modified
# 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 ^ index.php [L]
</IfModule>
The application will redirect you to host gator 404 page.
Also I've added .htaccess to the main directory which will forward every request to public directory.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
Upon removing the home/main .htaccess just works for / route: e.g
http://gator4057.temp.domains/~timely/email-client/public will work but all other routes are redirected to the same host gator 404 page.
Your comments and answers will be appreciated.
Thanks
Step 1. Move all email-client/public to email-client/. Now we're getting somewhere. Warning: Don't forget to copy the .htaccess file too
Step 2. Open email-client/index.php in your favorite editor and change
$app = require __DIR__.'/../bootstrap/app.php';
to
$app = require __DIR__.'/../email-client/bootstrap/app.php';
or may be
$app = require __DIR__.'/email-client/bootstrap/app.php';
and change:
require __DIR__.'/../bootstrap/autoload.php'
to
require __DIR__.'/../laravel/bootstrap/autoload.php'
or may be
require __DIR__.'/laravel/bootstrap/autoload.php'
Run command:
php artisan cache:clear
php artisan config:clear
php artisan optimize
OR
If you dont wana to do more changes try this:
Put this in index.php file
$app->bind('path.public', function() {
return __DIR__;
}
Hope work for you.
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.
Hi I am facing issues with settng pretty urls withput public in url but it is not working for me.
I already tried
Laravel 5.2 Pretty URLs,
Laravel 5 - Remove public from URL
and more similar urls but nothing seems to work for me.
I am using wamp, windows 8
I have make sure mod_rewrite is on, and is working properly.
Here is my htaccess on root.
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
my htaccess in test inside public folder
<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 have also tried pasting the htacess from public folder on root folder and removed the one from public folder but it dint work
actually the error which occurs is that my routes file skips all the patterns say if I have something like Route::get('/api/login', 'api#login') then it does works with urls containing public but when I remove public from url all the patterns are skipped. and it shows 404
I made sure all the requests are reaching public/index.php and mysterious thing is that when I print
var_dump(Request::root());
in routes.php it for url with public it says http://localhost/folderName/subFolderName/public but for the urls without public it says http://localhost/ and I think this is the reason why my patterns in routes file are not working.
P.S. I have set the title pretty urls laravel 5.4 instead of laravel routes not working because I think it is .htaccess which I needs to configure properly to get this working.
I do not want to change the folder structure because I believe in that there is some reason for which it is like this and There should be some work around for this.
Regarding setting vhosts I wont be able to do this on server (For I do not have the rights) so there is no use of setting a vhost on local as a work around as in login run I have to solve this.
Try this in your public/.htaccess
RewriteRule ^ /public/index.php [L]
And the .htaccess in root
RewriteRule ^(.*)$ /public/$1 [L]