SitePoint Sponsor

User Tag List

Page 2 of 2 FirstFirst 12
Results 26 to 44 of 44
  1. #26
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,756
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ralph.m View Post
    Check out this page:

    Creating a virtual host in MAMP
    I was going to buy MAMP Pro but I'd have to upgrade to Snow Leopard and that is NOT going to happen!!

    So, Ralph, can you please explain to me in layman's terms what we are doing with these "virtual hosts"?

    (I skimmed the link you sent and will do that after training today.)

    By setting up a virtual host, what will I have to d/change as I go from Development (i.e. MAMP) to Production (i.e. GoDaddy)?

    And how will this affect my code? (I guess it will make my life/code easier, right?!)

    Thanks,


    Debbie

  2. #27
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Virtual hosts are how Apache maps hostnames (like "www.sitepoint.com" or "localhost") to DocumentRoots (the folders with websites) you want it to host.

    By creating a virtual host for each site you want to work on, you'll be able to type something like http://yoursitename into your browser and see your site.

    Since your sites will each have their own host and not sit in a subdirectory, all your paths to stylesheets, images and scripts that use URLs relative to the root will work exactly the same on your computer as they do on GoDaddy.

    In other words, you won't have to maintain a configuration file or make any changes when working on your site on your computer versus when it's on your host. If you never hard code your hostname into your code (which you never need to), you can literally upload the code anywhere to any domain and your site will function without any change.

    You do not need to buy anything. Apache, and everything else MAMP installs, is free software.

  3. #28
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,756
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dan Grossman View Post
    Virtual hosts are how Apache maps hostnames (like "www.sitepoint.com" or "localhost") to DocumentRoots (the folders with websites) you want it to host.

    By creating a virtual host for each site you want to work on, you'll be able to type something like http://yoursitename into your browser and see your site.

    Since your sites will each have their own host and not sit in a subdirectory, all your paths to stylesheets, images and scripts that use URLs relative to the root will work exactly the same on your computer as they do on GoDaddy.

    In other words, you won't have to maintain a configuration file or make any changes when working on your site on your computer versus when it's on your host. If you never hard code your hostname into your code (which you never need to), you can literally upload the code anywhere to any domain and your site will function without any change.

    You do not need to buy anything. Apache, and everything else MAMP installs, is free software.
    *Still in training*

    Okay, that sounds pretty "cutting-edge" for me, but what about this last "kink"...

    My life - in learning LAMP - has been relying heavily on MAMP and its built in link to phpMyAdmin and NetBeans.

    Between those three apps I've got a great development environment that even a dummy like me can be pretty dangerous in?!

    So if I follow the instructions that Ralph sent me a link on, and based on your description, what am I going to have to do with NetBeans?

    Right now - when I get started every day - I launch MAMP, click on the phpMyAdmin link in MAMP and launch NetBeans. I then go into my "01_MyProject" folder in NetBeans, click on whatever php file I'm working on, enter/update code, and then do Shift + F6 to execute my .php page. (NetBeans does all of the rest as far as knowing how to do all of this "back-end plumbing" that has been messing me up so much!!)

    What do I need to change in NetBeans so I can do what I just described above and keep my same development workflow?

    Thanks,


    Debbie

  4. #29
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,644
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by Dan Grossman View Post
    He was just repeating what has already been said about why you had a problem. You do not want to change your rules. Adding [R=301] would turn the rewrite into a redirect and change the URL in the address bar from the "pretty URL" bad to the "ugly URL".
    Dan, the point is that the R=301 is a terrible way to eliminate the "missing support files problem" whereas either of the two recommended methods would resolve her problem. I'm not sure why you and Ralph are going off on tangents like this and hope that DD would actually try the solutions recommended.
    Quote Originally Posted by DoubleDee View Post
    That would explain A LOT of the problems I have been having!!

    So what is the exact syntax??
    As shown in the previous post, merely replace all the (sorry, riduculous) ROOT php variables with "/" to tell browsers that they should link relative to the DocumentRoot of the domain - that is an "internal absolute" link whereas IANA — Example domains is an "external absolute" link and whatever.ext is a relative link (from the perceived location, i.e., articles/postage-meters-can-save-you-money). Do NOT, under any circumstances, undo your mod_rewrite with the R=301 because, as Dan states, that will return your "pretty" links to "ugly" status.

    As Dan provided:
    Code:
    <link rel="stylesheet" href="/styles.css" />
    
    OR
    
    <link rel="stylesheet" href="http://www.example.com/styles.css" />
    (Sorry, Dan, emphasis now required)

    SIMPLY PRECEED YOUR SUPPORT FILE LINKS WITHIN YOUR articles.php SCRIPT WITH /!

    As the tutorial Article also states, you can leave all your relative links but ONLY if you use the HTML <base> tag - AND THE ARTICLE PROVIDES AN EXAMPLE OF THE SYNTAX.
    Finally, altering the directory level by using PHP definitions the way you have is asking for problems - relative links never work correctly when you do that.

    A better way to handle your development files (assuming that they're duplicated in the development directory), is to create a single variable which will either be an empty string (production) or development/ for use within the development directory and <?=$development?> as part of your link. Of course, all this can be eliminated by using a local test server rather than abusing your production environment with testing. Because this is what you're doing, why fiddle with nonsense like development directories?

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  5. #30
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    DK...

    Quote Originally Posted by dklynn
    Dan, the point is that the R=301 is a terrible way to eliminate the "missing support files problem"
    That's why bringing it up again, when and how you did, was counterproductive. You made her think that adding R=301, or some other change to the rule, might solve her problems. I'm sure you read between the lines and saw a bit of frustration at having to undo that.

    Quote Originally Posted by dklynn
    whereas either of the two recommended methods would resolve her problem...
    Simply adding a slash before the URIs would not fix everything. The root of her site is not her document root. ("Sorry, DK, emphasis required"). Right now she accesses her site at http://localhost/01_MyProject/, so those URLs would not point to the correct path of her stylesheets or images.

    Quote Originally Posted by dklynn
    all this can be eliminated by using a local test server
    She already has one. She just talked about it again in the post you replied to. That's why we're recommending she set up a virtual host, to make the root of her site the document root on both the development and production servers, AND add that slash.

    Once we get to that point, the site will work the same everywhere, the config file won't be necessary, etc etc, and the world will be at peace.

  6. #31
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,095
    Mentioned
    448 Post(s)
    Tagged
    8 Thread(s)
    Quote Originally Posted by DoubleDee View Post
    What do I need to change in NetBeans so I can do what I just described above and keep my same development workflow?
    I can't really comment on your workflow, but once you have your site working as you want in MAMP, you can just upload all your site files to the server, and export the database through PHPMyAdmin and upload that as well.
    Facebook | Google+ | Twitter | Web Design Tips | Free Contact Form

    Forum Usage: Tips on posting code samples, images and more

    Forrest Gump: "IE is like a box of chocolates: you never know what you're gonna get."

  7. #32
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,756
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dan Grossman View Post
    DK...

    Simply adding a slash before the URIs would not fix everything. The root of her site is not her document root. ("Sorry, DK, emphasis required"). Right now she accesses her site at http://localhost/01_MyProject/, so those URLs would not point to the correct path of her stylesheets or images.
    Glad someone was listening to me!!


    She already has one. She just talked about it again in the post you replied to. That's why we're recommending she set up a virtual host, to make the root of her site the document root on both the development and production servers, AND add that slash.
    Glad someone was listening to me!!

    Thanks Dan!



    Debbie

  8. #33
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,756
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ralph.m View Post
    I can't really comment on your workflow, but once you have your site working as you want in MAMP, you can just upload all your site files to the server, and export the database through PHPMyAdmin and upload that as well.
    You're not following me.

    NetBeans has to be configured like any other IDE to point to the right physical and web paths so when I do Shift + F6 that it executes my php files.

    If I take your and Dan's advice on the virtual host, I can all but guarantee that I'll need to change how NetBeans is currently configured.

    I was hoping someone had some insight on that.

    ----

    On a side note, if I follow the tutorial you posted, is there anything I should do to back up MAMP (or the related phpMyAdmin) *before* I attempt to set up a Virtual Host??

    Hope to do this later today...

    Thanks Ralph!



    Debbie

  9. #34
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,756
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I'm really struggling to get Virtual Hosts in MAMP working correctly.

    httpd.conf
    Code:
    <VirtualHost *:80>
      DocumentRoot "/Users/user1/Documents/DEV/++htdocs/01_MyProject"
      ServerName dev
    </VirtualHost>
    
    <VirtualHost *:80>
      DocumentRoot "/Users/user1/Documents/DEV/++htdocs/00_AAA"
      ServerName testvh
    </VirtualHost>
    It seems like the first Virtual Host works if I type in http://dev/ however if I try out the second Virtual Host by typing in http://testvh/ it tries to go to www. testvh.com

    In fact, about any name I try in VH#2 does the same thing?!

    I don't think I am understanding how this is supposed to work...


    Debbie

  10. #35
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,031
    Mentioned
    152 Post(s)
    Tagged
    2 Thread(s)
    You need to enable named virtual hosts

    Code:
    NameVirtualHost *
    <VirtualHost *:80>
      ServerName server1
      # etc
    </VirtualHost>
    <VirtualHost *:80>
      ServerName server2
      # etc
    </VirtualHost>
    # etc etc etc
    Without NameVirtualHost only the first VirtualHost works (like you have now).
    See core - Apache HTTP Server

    Also, you probably this by now, but don't forget to restart Apache every time you change httpd.conf
    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  11. #36
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,095
    Mentioned
    448 Post(s)
    Tagged
    8 Thread(s)
    Quote Originally Posted by DoubleDee View Post
    You're not following me.

    NetBeans has to be configured like any other IDE to point to the right physical and web paths so when I do Shift + F6 that it executes my php files.
    I don't know how to do that. I was just suggewting you work locally and get everything the way you want it, then separately upload the whole lot t the server (which may mean a separate setup in NetBeans for the online site).

    is there anything I should do to back up MAMP (or the related phpMyAdmin) *before* I attempt to set up a Virtual Host??
    I don't think so. The files just sit on your Mac as they are. You aren't changing them at all.

    The only think I'd do differently in your setup is change

    ServerName dev

    to

    ServerName mysite.com

    (obviously change mysite.com to the real site domain).

    That way, all absolute URLs in the local files won't need to change when you put them online. Otherwise you have the same problem as before.
    Facebook | Google+ | Twitter | Web Design Tips | Free Contact Form

    Forum Usage: Tips on posting code samples, images and more

    Forrest Gump: "IE is like a box of chocolates: you never know what you're gonna get."

  12. #37
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ralph.m View Post
    ServerName mysite.com

    (obviously change mysite.com to the real site domain).

    That way, all absolute URLs in the local files won't need to change when you put them online. Otherwise you have the same problem as before.
    You're suggesting she change her hosts file to point the domain to her computer every time she works on the site? Maybe I don't understand the suggestion.

    And why ever hard code an absolute URL? I don't do it once in any of my sites.

  13. #38
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,095
    Mentioned
    448 Post(s)
    Tagged
    8 Thread(s)
    Quote Originally Posted by Dan Grossman View Post
    You're suggesting she change her hosts file to point the domain to her computer every time she works on the site? Maybe I don't understand the suggestion.
    Or maybe I don't understand my suggestion, which is more likely. I guess if she wants to work locally and online at the same time it won't work.

    And why ever hard code an absolute URL? I don't do it once in any of my sites.
    I don't use absolute URLs either, but when working with a CMS, I find it records full URLs in its config file, and also creates a lot of absolute URLs with image links etc. ( ), and to save me having to change all that when placing everything online, it's simplest to have the site files in a local folder with the same name as the domain. I admit I'm still just learning about all this, so I'm not the best person to comment on it and thus will shuddup now.
    Facebook | Google+ | Twitter | Web Design Tips | Free Contact Form

    Forum Usage: Tips on posting code samples, images and more

    Forrest Gump: "IE is like a box of chocolates: you never know what you're gonna get."

  14. #39
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,756
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ScallioXTX View Post
    You need to enable named virtual hosts

    Code:
    NameVirtualHost *
    <VirtualHost *:80>
      ServerName server1
      # etc
    </VirtualHost>
    <VirtualHost *:80>
      ServerName server2
      # etc
    </VirtualHost>
    # etc etc etc
    Without NameVirtualHost only the first VirtualHost works (like you have now).
    See core - Apache HTTP Server

    Also, you probably this by now, but don't forget to restart Apache every time you change httpd.conf
    That wasn't the problem, although that is where I was looking also?!

    Turns out I was being a dummy and forgot to go back here and update the first part of the equation/tutorial after changing my virtual host names...

    Then navigate to Macintosh HD: private: etc: hosts, and click Open...

    Place your cursor on a new line at the end of the file, and type 127.0.0.1 followed by a space and the name of the virtual host you want to create. For example, to create a virtual host called mysite add this:

    127.0.0.1 mysite
    Argh!!


    Debbie

  15. #40
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,756
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ralph.m View Post
    I don't know how to do that. I was just suggesting you work locally and get everything the way you want it, then separately upload the whole lot t the server (which may mean a separate setup in NetBeans for the online site).
    It took me quite some time yesterday, but I think I've got it working... *think*

    In NetBeans, I left Project Folder and Source Folder the same but changed my Project URL to http:// local.dev/ (in the case of this particular Virtual Host).

    I created another test NetBeans Project, and things *seem* to be working, although I'm still trying to really get my hands around what all of this does and means.

    Off Topic:

    Ya know, all of this started THREE WEEKS AGO when I was trying - and still am - add an "Add a Comment to an Article" module on my website to make it move Web 2.0 and since then I've had to: 1.) Convert physical articles to my MySQL database - which still isn't working entirely, 2.) Create "pretty URLs" and learn about mod_rewrites, 3.) Struggle with Absolute Paths, and now 4.) Learn about Virtual Hosts?!

    I am going CRAZY over all of this unforeseen extra work!!!!



    I don't think so. The files just sit on your Mac as they are. You aren't changing them at all.
    I actually changed it so I could see hidden files and then made copies (i.e. backed up) my config files before following the link you sent.

    Also, as usual, I commented the heck out of my files so I can roll-back anything that causes issues.


    Debbie

  16. #41
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,756
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dan Grossman View Post
    And why ever hard code an absolute URL? I don't do it once in any of my sites.
    I still have to revisit this today, but I still don't see why using my original approach was wrong...

    Having an *intelligent* Config file that changes where the ROOT and WEB_ROOT is located based on whether you are in "Development" or "Production" has made my life so much easier since I originally started having problems with Relative HTML Links.

    (And in fact I'm still not entirely sure I won't still have to use my Config file?!)

    The only problem I had out of all of this - as a result of my Mod_Rewrite - was/is the problem with links to my pictures in my Articles. (And I don't think this is an issue of my Config file vs. using a Virtual Host. I think it is an issue that I STILL have some major issues getting my PHP articles into MySQL and working properly, which is another thread...)


    Debbie

  17. #42
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,756
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Dan and Ralph,

    I would like to make certain that I understand how this Virtual Host thing is supposedly working. (If you could check this out, I'd appreciate the help!)

    Here is what I did/have...

    1.) Used TextWrangler to modify Macintosh HD: private: etc: hosts as follows..

    Code:
    ## Added 2011-08-13
    127.0.0.1 local.one
    127.0.0.1 local.dev
    This points the host names "local.one" and "local.dev" to my local computer, right?


    2.) Used TextWrangler to modify Applications: MAMP: conf: apache: httpd.conf as follows...

    Code:
    # Uncommented the line below on 2011-08-13
    NameVirtualHost *
    
    # Added on 2011-08-13
    <VirtualHost *:80>
    #  DocumentRoot /Applications/MAMP/htdocs
      DocumentRoot "/Users/user1/Documents/DEV/++htdocs"
      ServerName localhost
    </VirtualHost>
    
    <VirtualHost *:80>
      DocumentRoot "/Users/user1/Documents/DEV/++htdocs/00_AAA"
      ServerName local.one
    </VirtualHost>
    
    <VirtualHost *:80>
      DocumentRoot "/Users/user1/Documents/DEV/++htdocs/01_MyProject"
      ServerName local.dev
    </VirtualHost>
    This connects the Host Names to the directories which hold the physical files, right?


    3.) In NetBeans I have the following settings...

    Project Folder:
    /Users/user1/Documents/DEV/++htdocs/01_MyProject

    Source Folder
    /Users/user1/Documents/DEV/++htdocs/01_MyProject

    This is where my physical files exist, right?

    Web Root
    <Source Folder>

    Project URL
    http:// local.dev/

    This is what you type in the browser to launch the mapped physical files above, right?

    Index File
    index.php


    And when I am in each respective NetBeans Project Folder and I hit Shift + F6, it seems like the Project and Project Files seem to work properly...

    -------------------------

    So putting all of this together...

    Originally, because NetBeans stores my files in a project folder, that changes what the "Web Root" actually is. And it is different than what is on a normal production server like on my web host, GoDaddy.

    So that was messing up my paths, especially when it came to how mod_rewrite works and how HTML relative links work.

    Is that correct?


    Now by creating a Virtual Host, I am able to tell Apache to still point to the same physical files which are nested within my NetBeans Project Folder, however, the Virtual Host lets me program my website like the NetBeans Project Folder is not there, and so I can use the same code and paths that I would use on my GoDaddy account?

    Did I get that right?

    Still trying to put all of this together, AND make sure I understand it completely before I go back and change all of my code to work with Virtual Hosts and possibly break things even more so?!

    Thanks,



    Debbie

  18. #43
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,031
    Mentioned
    152 Post(s)
    Tagged
    2 Thread(s)
    As far as I can tell you hit the nail on the head there, in all the points above!! Nothing to add / change, the answer to all questions is "indeed, that's correct"
    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  19. #44
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,756
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ScallioXTX View Post
    As far as I can tell you hit the nail on the head there, in all the points above!! Nothing to add / change, the answer to all questions is "indeed, that's correct"
    Cool! One step closer towards "greatness" like all of you guys and gals!!


    Debbie


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •