Issues while taking Laravel project online - php

I am trying to take my Laravel project online. I am using AWS to host it. The project is working fine in localhost. But when I try to put it online, I have to add public at the end of URL to view my project. Plus, no other route except '/' is working for me. For example, I have a route defined user/login which is working fine in localhost but not online. Here is the link to the project.

You need to correctly set the document root on your web server. The document root is the folder that apache or nginx will attempt to serve files out of. You want this to be the full path to the Laravel public folder.
I'm not an AWS expert, but if you're using Elastic Beanstalk checkout the "Document root" section on this page. If you're just spinning up an EC2 instance you'll need to alter your deployment scripts to change the Apache virtual host setup and/or nginx configuration to point to the correct folder.

Add a Procfile to your project root that contains something like the following:
web: vendor/bin/heroku-php-apache2 public
The above assumes you are using php/apache, if it is something else, then change accordingly.

Related

Symfony project not working correctly on a virtual host

Symfony project is not running on a remote virtual host because there is no index.php file in the project root directory. When I'm trying to open my symfony project on a localhost with
URL "localhost/symf.com"
it only shows me project folders instead of the home controller. I know I should open my site with Php bin/console server:start command, but how does it work on a remote virtual host?
Perhaps I should somehow change my project's root directory? But I don't have access to remote virtual host configuration
In virtual host you must run prod environment not dev as your localhost. So you must configure your Apache configuration to run your project. Use following link:
Web Server Configuration for Symfony
Be careful, in symfony 3.4 the DocumentRoot is equal to project_path/web and in symfony 4.3 is equal to project_path/public
You mentioned that you do not have access to your virtual host to set one by one configuration. In that case the best way is using docker-compose, so with running docker-compose up -d all the things you need to run your project will be generated automatically. But you must have enough knowledge about docker
Be successful.
Symfony's homepage in at 'YourProject/public/index.php'.
You have to point on this file to see your home controller.

Storage folder is not accessible on live server in Laravel 5.5

I am working on a Laravel project, I am uploading images via Admin Panel which are storing in Storage directory. When I try to access the images then it works fine on localhost. i.e.
The image is accessible by following URL on localhost:
http://localhost:8000/storage/default3.png
But when I try to access the same image on live server:
http://13.57.71.20/serio/storage/default3.png
then it doesn't work.
NOTE: serio is the folder where project is uploaded on server.
But it does work if I try the following way:
http://13.57.71.20/serio/storage/app/public/default3.png
I also tried to re-link the Storage directory by running following command:
php artisan storage:link
but nothing helped.
Change following line in .env file
APP_URL=http://13.57.71.20/serio
The problem in my view, it seems is with production url. You running it on production on url:
http://13.57.71.20/serio/
Seems to me that the directory alias serio is not properly configured for Apache/Nginx. Try running the app under http://13.57.71.20/ or you need to add an alias to the default host configuration for serio which you should map to your laravel app public folder.

What's the best way to run a laravel project with out using artisan serve?

guys I have a laravel project and its working fine. Every time I start the project by typing the command php artisan serve and then by typing the url localhost:8000 in my browser. But now I want to start my project only by typing the url localhost/projectname.
So I did a little bit of digging and found out a way to do this, I made it possible by changing the server.php file from root directory to index.php and copying the htaccess file from public folder to root directory`. This way my browser loaded only html file or php file but css files and js files were not loaded so I had to modify there link on the blade file for example:
Previously a style.css file was linked as:
<link rel="stylesheet" type="text/css" href="{{asset('front_end/assets/css/style.css')}}">
Now I link the same style.css file as below:
<link rel="stylesheet" type="text/css" href="{{asset('/public/front_end/assets/css/style.css')}}">
And It works fine.
But now I have found another problem, I have stored some files (images) in the the storage/app/public/myfolder directory so to access the files I had to use the command php artisan storage:link command and to access the files(images) from above mentioned directory from blade file I use the code below:
<img src="{{$url = Storage::url('myfolder/'.$company->logo_name)}}">
This code did worked only worked when I used to start my project using php artisan serve command. Now I its not linking so what should I do? And also can you guys tell me the way that I changed the server.php file to index.php is the right way or not? And what you guys do in your real projects?
Thank You.
When deploying a Laravel project you want your nginx or apache configuration to point to your public path of your project. Changing the server.php or index.php files are not necessary.
Apache Config Example:
<VirtualHost *:80>
ServerName project.dev
DocumentRoot "/home/vagrant/projects/project/public"
<Directory "/home/vagrant/projects/project/public">
AllowOverride all
</Directory>
</VirtualHost>
As you can see with this apache config example, it points to the public directory of your project.
You can achieve this locally by installing either Apache or nginx on your local machine.
I would recommend following Laravel's documentation guide on using Vagrant's Homestead to get an idea of how this is working before you decide to run this on a server. A link here
There is a couple of options you can take to achieve essentially the same goal. This depends on the machine you are running on and personal preference.
Laravel Valet for Mac
Laravel Homestead
WAMP for Windows
MAMP for Mac
You don't need to modify any file.
You need one of this:
Web server installed locally, Apache or Nginx
A Vagrant Virtual machine for running the project like in production environemnts like Homestead
Valet
If you decide to go with Web Server, you just need to consider to point to project/public folder instead of project.
Doing with one of this options, you won't need to modify the assets url, since public shouldn't be part of your url in any case.
First of all, don't do any tweaks in server.php file, it's fine.
To run your project with url like, http://localhost/my-project.dev or simply my http://project.dev, use WAMP or XAMPP (if working on a windows machine) and lamp for linux. You can also checkout Laravel's Homestead.
Then setup virtual host.
See this tutorial for setting up virtual host on WAMP - http://www.coderomeos.org/how-to-set-up-virtual-host-on-wamp-server
And don't put your assets in public/assets folder to prevent using storage link.

Symfony deployment on heroku points to app folder

I am trying to deploy the symfony app on heroku and I am able to update the schema and all perfectly fine however when i try to access the site I get
Forbidden
You don't have permission to access / on this server.
So using the command heroku logs --num 10 i can see the error
Cannot serve directory /app/web/: No matching DirectoryIndex
(index.php,index.html,index.htm) found, and server-generated directory
index forbidden by Options directive
As you can see heroku is trying to access /app/web/ rather than just web, because of this even my assets are being access via app/web/css which is ofcourse wrong.
So how can i get rid of this app? I do not understand why Heroku is even pointing at that.
I have gone through the steps mentioned in Symfony documentation over and over and I cant seem to find out what I am missing?
The Procfile seems to be point to web so where is this app coming from?
web: vendor/bin/heroku-php-apache2 web/
I have gone through other articles online like the one as following but nothing seems to be fixing my problem.
Symfony on Heroku: 403 Forbidden You don't have permission to access / on this server
Any help will be really appreciated.
On Heroku you need to create the .Procfile and upload that or create the app.json Schema file and then based on that Heroku will create the .Procfile for you automatically, here you can see the app.json example for Symfony app.
Another thing that needs to be crossed checked is make sure in your public directory the .htaccess file was also uploaded. In Symfony the public directory is the web folder and in my case the .htaccess file was missing.
After making sure of the above two steps my app works perfectly fine on Heroku.
Use /web/ instead of web/: add the leading slash!
Your Procfile file should contain this:
web: vendor/bin/heroku-php-apache2 /web/
Note the leading / in the path to the web folder!

Laravel Homestead Serve code not creating and connecting to folder(s)

I have tried running the following code, and even though it runs and sets the nginx blocks ok, its not linking to the folder in question with in the host machine.
serve projects.dev /home/vagrant/Code/projects.dev
When i then list the folders within the Code folder on the guest machine, i only get the folders that were created via the automated Yaml config file on init set up.
It seems not be creating the folder and/or linking to it at all with between the guest and host machines
Running it on a iMac OS Mavericks.
Vagrant 1.6.2
VirtualBox 4.3.12
That is strange. What I have is I have a folder mapped on the "folders" section from my host machine that inside contains all the sub-folders for all my projects in progress. So my nginx sites just basically link to the sub-folders inside this directory. If you have something like that it "should" show you the folders from your host inside that Code directory in your VM. Maybe post your YAML file to check it out?
My problem was the new Homestead file, use small c for spelling directory "code".
I was upgrading my homestead, so the old code folder was using capital c, spelled "Code".
I just change my Homeastead.yaml file from calling "code" to "Code".

Categories