127.0.0.1 working, localhost not?!

Problems with the Mac OS X version of XAMPP, questions, comments, and anything related.

127.0.0.1 working, localhost not?!

Postby alexstarbuck » 04. March 2014 17:29

It is an understatement to say I am going slightly mad... PLEASE someone come up with a solution, I have lost 3 days just with starting the damn server so I can learn and practice PHP programming

I am on OSX 10.8.2 with XAMPP 1.8.3-3

I have installed XAMPP a couple of days ago successfully, and used it for a while. Then I learned about vhosts function and wanted to use it (to have multiple sites and try different stuff) and it has all gone down the drain from there. I followed the instructions available online on various blogs but I could never get VHOSTS function to work. The worst thing is that I couldn't even get the XAMPP to its default state and work again.

De-installed everything, tried MAMP. There I got the dreaded "Couldnt write to etc/hosts file" message and de-installed that one.

Finally, I reinstalled XAMPP and decided to give it one more shot, using default settings and not using VHOSTS function as it is obviously too advanced for me for now.

PROBLEM: when I enter 127.0.0.1 into browsers address bar I get XAMPP homepage. If I put "Localhost" stupid Chrome (or Firefox) go online and search localhost with Google or try to go to localhost.com.

- I did a clean re-install of XAMPP
- I restarted my MacBook
- Started all three services with Manager utility
- Checked the notorious "hosts" file and it says as follows:

Code: Select all
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
#::1 localhost
fe80::1%lo0 localhost


I commented out the ::1. I even tried leaving just 127.0.0.1 localhost line in the file, saving it, restarting everything - no luck. I can get it to work with 127.0.0.1 but not with "localhost", not with "http://localhost", not with "http://localhost/index.php"... Nothing.

IT-IS-DRIVING-ME-NUTS.
--
Either we find a way or we make one! -Hanibal
User avatar
alexstarbuck
 
Posts: 9
Joined: 02. March 2014 23:03
Location: Croatia
Operating System: OSX 10.8.2

Re: 127.0.0.1 working, localhost not?!

Postby Nobbie » 05. March 2014 12:12

>fe80::1%lo0 localhost

This looks very very strange! Why did you do that? Remove that line!
Nobbie
 
Posts: 13171
Joined: 09. March 2008 13:04

Re: 127.0.0.1 working, localhost not?!

Postby alexstarbuck » 05. March 2014 13:03

Thanks for the reply man! I didn't put this one, It looked as if it were there from alwys.
I have removed it but still no success.

When I type 127.0.0.1 in Chrome I get Xampp start page, but when I try localhost, localhost:8888, http://localhost - no luck!

:(
--
Either we find a way or we make one! -Hanibal
User avatar
alexstarbuck
 
Posts: 9
Joined: 02. March 2014 23:03
Location: Croatia
Operating System: OSX 10.8.2

Re: 127.0.0.1 working, localhost not?!

Postby Nobbie » 05. March 2014 23:04

What happens, if you enter "ping localhost" in a terminal (a shell)?

P.S.: Why did you try "localhost:8888"?? What is the idea of testing any port (you could also try localhost:4711 or localhost:12345 or any other useless port)? Dont mess around without any sense.

P.P.S.: Could you upload your /etc/hosts file anywhere, so that i can download? It is important to upload the file itself, dont show me copy of it or similar, i really need the file as it is (originally).

P.P.P.S.: I found a lot of very strange problem reports about /etc/hosts on OSX, for example this one: http://stackoverflow.com/questions/1006 ... -2-3-secon

My own opinion? Trash the worst operating system in the world (Apple OSX), Apple is an overpriced "nice to see" designed trashbox, setup a linux PC and you will be fine. I will never understand why people like Apple. I dont like it. It is expensive and as long it runs, everything seems ok. But if any problem occurs (like yours), you are helpless and there is no help from Apple.
Nobbie
 
Posts: 13171
Joined: 09. March 2008 13:04

Re: 127.0.0.1 working, localhost not?!

Postby alexstarbuck » 06. March 2014 13:24

Hello Nobbie,

hanks for taking the time to work with me step by step! Let's take things one at a time:

- yesterday I went crazy and reinstalled Mountain Lion
- as per Lynda.com instructions I tried using built in Apache and enabling PHP in the config file
- this worked with the default server root directory (the one where it serves files from) but as soon as I changed this to the Sites directory that I recreated under my USER - I got the Forbidden message in my bvrowser.
- I DID use the sudo chmod 644 command from the tutorial for this myuser.config file but it still didnt work
- then I decided to not use this route, I shut down built in Apache and restarted XAMPP

Now I am here:

- XAMPP is running, localhost and 127.0.0.1 both work
- root directory is htdocs , I havent touched anything

My question:
What is the proper way to use htdocs to have separate folder for every site that I work on? I suppose I need to turn on VirtualHosts feature again? I am kind of affraid messing with this not to break things again

I am going to check out Linux for Mac now. If its not so complicated to use and there is SublimeText forLinux, I just might switch over ;)
--
Either we find a way or we make one! -Hanibal
User avatar
alexstarbuck
 
Posts: 9
Joined: 02. March 2014 23:03
Location: Croatia
Operating System: OSX 10.8.2

Re: 127.0.0.1 working, localhost not?!

Postby Nobbie » 06. March 2014 15:22

alexstarbuck wrote:- I DID use the sudo chmod 644 command from the tutorial for this myuser.config file but it still didnt work


This is probably not sufficient. You should as well "sudo chmod 755" to ALL folders, including the DocumentRoot and(!!!) ALL FOLDERS ABOVE!! Example:

You choose /user/home/alex/htdocs as DocumentRoot, then you must do a "sudo chmod 755" to:

/user
/user/home
/user/home/alex
/user/home/alex/htdocs

And finally the chmod 644 to all files beyond htdocs.

This is NOT Apache related - it is basic skill of rights management in Unix file systems (and OSX is a UNIX like Operating System). What do you think about learning how OSX file systems work?

alexstarbuck wrote:My question:
What is the proper way to use htdocs to have separate folder for every site that I work on? I suppose I need to turn on VirtualHosts feature again? I am kind of affraid messing with this not to break things again


There are two different solutions:

a) using VirtualHosts. This results in different domain names for different DocumentRoots. You have seen already how it looks like.

b) using ALIAS Statement. If you use ALIAS, you may point to different folders by virtual different URLs. Example.

http://localhost/alex/ ---> usually yields to htdocs/alex subfolder. But you may use an ALIAS statement in httpd.conf, that defines another folder for "alex":

ALIAS /alex /usr/home/alex/htdocs

If you have this ALIAS and you enter (again) http://localhost/alex/, it DOES NOT result in htdocs/alex, but it yields to /usr/home/alex/htdocs/

So ALIAS is slightly similar to a DocumentRoot statement, but the difference is, that you need a subfolder for the ALIAS. In any case (either you go for VirtualHost or for ALIAS): You MUST grant sufficient rights to /usr/home/alex/htdocs anyway - on the one hand on operating system level as shown above (chmod ....), and also on Apache Level by applying a <Directory ....> Configuration like you already have for the default DocumentRoot (which is already built in httpd.conf).

A very last note: installing, configuring and running a Webserver (like Apache) is NOT a task for a computer beginner. You will struggle endless if you are not well educated for computers. Usually, this is a task for an educated system Administrator, but many people think, they can install and run that piece of software simply on their own. THIS IS WRONG. A webserver (like Apache) is a big chunk of software and there are many many options to configure and think about it and you have to know lots of operating systems, of right managements, TCPIP etc. pp. - this is not a "clicky clicky" user task.
Nobbie
 
Posts: 13171
Joined: 09. March 2008 13:04

Re: 127.0.0.1 working, localhost not?!

Postby alexstarbuck » 06. March 2014 16:42

Oy,

thanks for taking the time ti run me step by step through all this.

You will not believe me but I have somehow managed to get things working without any of these... I can't recall what I did because there were so many options I tried and gone back and forward, but -

- I currently have XAMPP running
- I have put my "testsite" folder inside htdocs
- put my files inside this "testsite" folder
- check it in Chrome - AND IT WORKS!! :))

localhost gets me to XAMPP start page and localhost/testsite gets the index.php that I put inside it! I am so happy man I can't tell you. Almost 5 days of messing with the system and the server and no luch and the simplest solution worked.

Also, I understand completely what you are telling me, I understand how much I still have to learn. There is OS workflow, permissions, server admin, then tools for programming, then php and databases... So much areas to cover and extremely difficult to do on your own.
--
Either we find a way or we make one! -Hanibal
User avatar
alexstarbuck
 
Posts: 9
Joined: 02. March 2014 23:03
Location: Croatia
Operating System: OSX 10.8.2

Re: 127.0.0.1 working, localhost not?!

Postby Nobbie » 07. March 2014 13:02

alexstarbuck wrote:- I have put my "testsite" folder inside htdocs
- put my files inside this "testsite" folder
- check it in Chrome - AND IT WORKS!! :)


Oh man....

I did not know, that you were simply looking for a subfolder for your own files - this is of course very easy to do (as you see). I thought, that you want to put your own files NOT under htdocs, but somewhere else (for example in your home of your UserID).

So if you are satiesfied with this (simple) subfolder, everything is ok. The VirtualHost gives you the possibility to avoid the subfolder name ("testsite") in the URL (because you must enter localhost/testsite to access your files). If you have a VirtualHost (lets call it "testsite.local") which points directly to your own files (via DocumentRoot), then you dont need to specify a subfolder in the URL, simply http://testsite.local/ will do that.

That is the idea of a VirtualHost, it is a "virtual" domain (or "host", that is the same).
Nobbie
 
Posts: 13171
Joined: 09. March 2008 13:04

Re: 127.0.0.1 working, localhost not?!

Postby alexstarbuck » 07. March 2014 15:17

Yes, at first I wanted to not use the "htdocs" folder but "Sites" folder, which I recreated inside MyUser. But, as I ran into all sorts of problems while doing so, I re-installed everything, created a subfolder inside htdocs and it worked.

I understand the benefits of virtualhosts but it seems difficult to set up properlu (at least for a beginner) and my main goal for now is learning php/html/css. Once I am familiar with that I will dedicate some time to learn how to properly manage server. It is way to complicated to do it all at once and I am self taught so...

Thank you for your support, I appreciate it!
--
Either we find a way or we make one! -Hanibal
User avatar
alexstarbuck
 
Posts: 9
Joined: 02. March 2014 23:03
Location: Croatia
Operating System: OSX 10.8.2


Return to XAMPP for macOS

Who is online

Users browsing this forum: No registered users and 16 guests