2

I am currently creating a Laravel project and need to store cookies in a http://localhost:8000 address, of course, I have found out that to set a cookie through JavaScript, the domain must have two or more periods (.) in.

Obviously, with the address set to localhost:8000, cookies fail to be stored. I need to be able to fake my host to point something like http://dev.project.laravel as opposed to localhost:8000

Apologies if I'm not making sense, but hopefully you catch my drift. Thanks in advance for any help given.

  • 1
    I believe this might be what you are looking for: http://stackoverflow.com/questions/489369/can-i-use-localhost-as-the-domain-when-setting-an-http-cookie – noone May 19 '17 at 19:28
  • Then set up your vhosts on the computer you're using. I really don't understand the problem. – junkfoodjunkie May 19 '17 at 19:37
  • Sorry to be a nuisance and sound like there is no problem, but I have no idea where to configure vhosts when using a PHP web server on Mac, I can't find the exact configuration file I need to change. – ThatGeekyGinger May 19 '17 at 20:00

1 Answers1

3

Try the following:

Assuming you have Windows OS and have installed XAMPP (or similar) stack:

  1. Add the following line to httpd.conf file under # Supplemental configuration which is in the configuration folder of apache... (I have XAMP installed and for me, this path is: C:\xampp\apache\conf)

    Include conf/extra/httpd-vhosts.conf
    

it should be around line 484

if you already have that line, but its commented out, then un-commment it.

  1. Add the following to your httpd-vhosts.conf file (which, in my case, is located at C:\xampp\apache\conf\extra)--

In the first line below, change 80 to whatever port your localhost is running on... if you do not use port to access localhost, then leave it as 80)

    <VirtualHost *:80>
        DocumentRoot "C:/xampp/htdocs/"
        ServerName desired.name.of.your.site
        ServerAlias desired.name.of.your.site
    </VirtualHost>
  1. And lastly, and most importantly, add the following in your hosts file (for me, this is located at C:\Windows\System32\drivers\etc) and then restart apache

    127.0.0.1 desired.name.of.your.site
    

If you have a LAMP stack, the above should still apply... just the folder paths would need to change.

Hope this helps!

Best,

-Rush

Rushikumar
  • 1,774
  • 5
  • 18
  • 28
  • I really appreciate your efforts and am sure it'll help people in the future, but would having a Mac and running an apache server through PHP command line via Laravel have the same approach and if so do you have any clue on the directories I'd need to access to make these changes? – ThatGeekyGinger May 19 '17 at 20:30
  • 1
    Tom, I do not have any experience with Laravel (yet)... but, if your objective is simply to change localhost to a custom domain, the above should apply----definitely in the case of Windows... but paths might change for other OS's, as noted. – Rushikumar May 22 '17 at 14:31
  • 1
    Apologies for my laziness, I've found the files in Mac and your 100% correct. Thanks so much for your help. – ThatGeekyGinger May 23 '17 at 13:54