newbie1120's avatar

Problem with access to localhost/public/index

I have problem when i access to localhost/project/public/

picture : https://puu.sh/Av2Hd/cbca28baeb.jpg

and can't continue to every function not like when i run on virtual host

picture : https://puu.sh/Av2OC/72981c31bf.jpg

and this is use php artisan serve : https://puu.sh/Av2Ph/b6e821f8ec.jpg

i need to put this project to AWS amazon ec2 and can't open this from localhost

please help, what is different from this problem and what should i do?

sorry for my englishskill

0 likes
11 replies
lostdreamer_nl's avatar

you should always setup a virtualhost to point at app/public instead of going to http://localhost/app/public In this last way, your asset() and url() functions wont work well, the routing will probably also start seeing public as a route

The easiest way for testing the app locally is with "php artisan serve"

You're on mac right? Another easy option is using laragon as your server setup (you can install it with either Apache or Nginx within a minute or 2)

https://laragon.org/

1 like
blueshift9's avatar

You'd probably get more help from a) making your issue a bit clearer and b) I wouldn't have put it in site improvements, this section is for suggestions for laracasts.com, not improving YOUR site. I'm sure plenty of people are like me and only browse the sections that are applicable to them.

newbie1120's avatar

@blueshift9 sorry for that, My issue is when i access to localhost/project/public the website functions wont work , so i need to know how can access to localhost/project/public and make functions work like i run on virtual host so, this can happen or not ? thank sir for recommend.

Cronix's avatar

Did you try setting up a vhost as @lostdreamer_nl suggested in the answer you selected as "best"?

After doing that, you'd also need to change your APP_URL in .env to be http://yourhostname.test or whatever you named it, instead of http://localhost/project/public/or whatever you have it set to now. You'd also access it with http://yourhostname.test in the browser, just like a real site.

In your views, you'd load your css/js files like

<link href="/css/vendor.css" rel="stylesheet">

assuming the file is in /public/css/vendor.css.

Then when you put laravel on a real server, everything should work after you update the APP_URL to point to just http://realhostname.com

1 like
Cronix's avatar
Cronix
Best Answer
Level 67

You shouldn't access by ip in the url, access by the server name you gave it like your first screenshot. I assume you named the server in your vm internetcafe.oo? If so, just use that, and set APP_URL=http://internetcafe.oo/ in your .env if you haven't already.

When you move the site from your dev to a production server, you'd just update APP_URL=http://livesitename.com/ in .env on the production server.

1 like
Cronix's avatar

Also, how did you setup this "vm"? @lostdreamer_nl showed several ways, but you didn't say which one you used.

1 like
newbie1120's avatar

@cronix I use laragon for virtual host , and that ip is public from production server .I assume my dns name from production server is http://mydns.com/ and i update APP_URL=http://mydns.com/ in .env right? and don't mess with virtual host internetcafe.oo right?

Please or to participate in this conversation.