Access Forbidden on heroku while deploying laravel app - heroku

I am trying to host a laravel application oh heroku. But i'm gettin the access forbidden message. I have created the Procfile and placed the following code
web: vendor/bin/heroku-php-apache2 public/
I have also placed the following code in my composer.json
"php artisan clear-compiled",
"php artisan optimize",
"chmod -R 777 public/"
I also have checked if the htaccess file exist in public directory.
I'm still getting the error. Please help me with this some one

Make sure your Procfile is inside the root directory of your project (not inside public/), and that it contains web: vendor/bin/heroku-php-apache2 public

Related

Error when running database seeder through Heroku

I am unable to setup a packages folder structure with db:seed on Laravel framework.
I was able to deploy and migrate the regular Laravel project on heroku,
but I am having issue trying to use the class argument for the artisan db:seed command.
my folders structure:
root-dir/packages/clientname/projectname/app
root-dir/packages/clientname/projectname/config
root-dir/packages/clientname/projectname/database/seeders
root-dir/packages/clientname/projectname/resources
In composer I have autoload > psr-4 mapped to the packages seeders folder
"autoload": {
"psr-4": {
"ClientName\\ProjectName\\Database\\Seeders\\": "packages/clientname/projectname/database/seeders/"
}
},
running the following command
$ heroku run --app client-project php artisan db:seed --class=\\ClientName\\ProjectName\\Database\\Seeders\\DatabaseSeeder
returns an error
In Container.php line 811:
Target class [Database\Seeders\ClientNameProjectNameDatabaseSeedersDatabaseSeeder] does not exist.
Note the backslashes have been removed. How can I resolve this issue?
Checking out the source for this command, it appears there's a fair bit of escaping going on. I would suggest either double-escaping your backslashes like this:
heroku run --app client-project php artisan db:seed --class=\\\\ClientName\\\\ProjectName\\\\Database\\\\Seeders\\\\DatabaseSeeder
Or try some quoting around the command:
heroku run --app client-project 'php artisan db:seed --class=\\ClientName\\ProjectName\\Database\\Seeders\\DatabaseSeeder'

Error 403: You don't have permission to access / on this server

Deployed my web app to Heroku, no errors. However when I got to open the app, it says 403 You don't have permission to access / on this server.
I have already looked into the spelling of "Procfile" and I tried using the code provided on another forum but it springs an error when I try to deploy it.
"php artisan clear-compiled",
"php artisan optimize",
"chmod -R 777 AAS/public/"
]
This is the error that shows in the server logs.
2019-05-07T15:41:17.899066+00:00 app[web.1]: [Tue May 07 15:41:17.895803 2019] [autoindex:error] [pid 138:tid 140579161761536] [client 10.11.89.47:16532] AH01276: Cannot serve directory /app/: No matching DirectoryIndex (index.php,index.html,index.htm) found, and server-generated directory index forbidden by Options directive, referer: https://dashboard.heroku.com/
I understand this is due to trying to access the app folder instead of public folder but I have no clue how to correct that.
I hope the server accesses the public folder, and displays the web app correctly.
All advice is welcome.
Thanks in advance.
-Michael
If you are deploying php file then you need to keep php file in folder like web and your Procfile should look like web: vendor/bin/heroku-php-apache2 web/

Laravel Artisan make command issue

I am trying to make a middleware using artisan php artisan make:middleware AuthorizedUserOnly but I get ErrorException like below.
file_get_contents(/mysite.com/www/local/composer.json) Failed to open stream no such file or directory.
This is my document root.
-local
-Laravel application folders
-artisan
-index.php
-composer.json
.htaccess
I changed my directory structure to work with shared hosting. And It was working fine.
KEY NOTES
Other artisan commands work. Like I tried php artisan route:list & php artisan config:cache & php artisan tinker.
This directory structure works fine.But as the error says that it is trying to find composer.json in local directory while it is on document root.
php artisan make:model command spits the same Exception
What could be the possible issue and solution ?
Solution : I moved my composer.json file to local directory and it worked fine. So new directory structure is
-local
-Laravel Application Folders
-composer.json
-artisan
-index.php
.htaccess
HOW ?
I am not sure about this yet. But this is the possible reason. php artisan make command create some files. So to included these created files into system execute composer dump-autoload. So to run composer it looks for in the same directory where artisan lives which is local directory in my case.
IMPORTANT
I changed laravel default directory structure to successfully run my applicaiton on SHARED HOSTING which laravel DOESNOT RECOMMEND.
We should follow the recommendations made by laravel to avoid any similiar issue. Specially never to mess with default directory structure at least.

Laravel 5.1 manualy clearing views cache, caused error 500

I just removed all files inside laravelApp/storage/framework/views and all of routes now return error 500.
Command php artisan views:clear and php artisan cache:clear tested, but had no affect.
Error reporting is set to E_All, APP_DEBUG is true both in app.php and .env file, But i see only a simple error 500 (generated by browser).
How can i fix it?
i set permission for my folder that cointain all files
sudo chown -R www-data:www-data /var/www/myweb
(ubuntu)
and it is ok!

laravel services.json not created

Sometimes my services.json is missing after running composer update or php artisan clear-compiled.
I checked the permissions and even changed it to 777 on the storage folder but it does not help. How can I debug whats wrong?
There are no entries in my laravel log and nothing in my apache log. I'm using "laravel/framework": "4.1.*"
Just run a php artisan serve and stop, this will create the services.json file.
Ensure your web server has access to the files/folders specifically app/storage/meta/services.json if this file/folder is not there create it and add some json to see if you can accesss it in the browser.
If forbidden/denied see permissions below:
Check you have these folders
app/storage/views
app/storage/logs
app/storage/sessions
Set everything to be read/write
chmod -R 777 /app/storage
Create services.json and add the following
{
"providers": []
}
After creating the above try loading the project or php artisan serve

Resources