SitePoint Sponsor

User Tag List

View Poll Results: How would you rate this tip on a scale of 1 to 10. 1 being the lowest.

Voters
11. You may not vote on this poll
  • 1

    1 9.09%
  • 2

    0 0%
  • 3

    1 9.09%
  • 4

    1 9.09%
  • 5

    1 9.09%
  • 6

    0 0%
  • 7

    1 9.09%
  • 8

    3 27.27%
  • 9

    1 9.09%
  • 10

    2 18.18%
Results 1 to 8 of 8
  1. #1
    SitePoint Wizard holmescreek's Avatar
    Join Date
    Mar 2001
    Location
    Northwest Florida
    Posts
    1,707
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Lightbulb Apache for Windows Faster Deployment

    Hello Everyone,

    I've been developing with PHP/MySQL under Windows 2000 and currently XP for about 2 years now. I wanted to share an important tip with other programmers here that may help in speeding up deployment time. That is how to set up Apache on a windows machine to use the same paths that your hosting company has set up for you. Read on...

    Typically, every hosting company on the web will set up the paths to where your html/php files are supposed to be uploaded. For instance, with one of my hosting accounts the path to my files look something like this :

    /home/accountname/www/

    Unfortunatly, by default, when you install Apache for Windows and run http://localhost/ to test your site Apache points to the C:\apache\htdocs directory.

    The Problem :

    First, and I assume others have been doing this, each time I need to work on a different clients website I have to move the contents of htdocs to a backup folder, then copy the contents of the different client into the htdocs folder.

    Second, I usually set up a file called paths.php that define the absolute paths to where I keep all of my include files. The include files in mind, for instance the include file that contains the password for my mysql database, I store in a folder in the root of my site. This prevents someone from http'ing the files. For instance my index.php would include("paths.php") paths.php would contain :

    <?php

    $MYLIB = "c:\apache\phplib\";

    #$MYLIB = "/home/myaccount/phplib/";

    ?>

    You will note that I use the first line when testing on my local machine, then when I get ready to upload to my hosting company I have to use the second line instead...more work!!


    The Objective:

    Quit wasting time!

    Ok, I first considered setting up a linux box on my network and setting up Apache configured just like my hosting provider. Where as I could actually set up a directory called /home/myaccount/phplib. Well, next problem is that you can't use something like Dreamweaver on your pc to manipulate your project files located on the linux machine!


    Second, I considered installing Apache on a different partition. But again, by default Apache wants you to put your files in c:\apache\htdocs. Now we are back to using the paths.php with the $MYLIB variable again.


    OK THE QUICK APPROACH (I PROMISE)

    My solution to all of the delimas mentioned above became quite clear.

    For instance, I keep all of my projects in seperate folders in My Documents\websites\. For example say I have a client called abc fence I would have created the following folder :

    My Documents\websites\abcfence\home\myaccount\www

    The www folder contains what is typically stored in C:\apache\htdocs.


    Second, I edited C:\apache\conf\httpd.conf and changed the following :

    change DocumentRoot="c:/apache/htdocs"
    to
    DocumentRoot="z:/home/myaccount/www"

    change <Directory "c:/apache/htdocs">
    ot
    <Directory "z:/home/myaccount/www">


    Next, I use the old DOS subst command. SUBST associates a drive letter with an existing directory. For instance, you have a directory called C:\BOB if you type :

    subst Z: C:\BOB

    Whenever you change to Z: drive and do a directory you actually see the contents of C:\BOB. Is it becoming clear now?

    Ok, back to the next step. Finally, I did this :

    SUBST Z: "C:\Documents and Settings\Administrator\My Documents\websites\washcomall\"


    After restarting Apache, if you type in http://localhost your browser will be displaying files located in :

    z:\home\myaccount\www\



    IN CONCLUSTION

    By using this method I have several advantages.

    1) I no longer have to define two different paths to my library files.

    2) The paths on Z: drive match the directory structure of my hosting companies.

    3) Using something like Dreamweaver, when I define my site root all I have to use is Z:\home\myaccount\www


    Again, I thought this would be some valuable information for others developing apps for under XP running APACHE.


    I'm always around to answer questions. Please contact me anytime.

    John Warren
    holmescreek@holmescreek.com
    http://www.holmescreek.com/

  2. #2
    SitePoint Wizard holmescreek's Avatar
    Join Date
    Mar 2001
    Location
    Northwest Florida
    Posts
    1,707
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I also wanted to mention that you can also create a batch file that automatically sets up z: to point to different projects you may be working on. I create a windows shortcut that runs :

    C:\DEV.BAT

    DEV.BAT contains :

    @echo off

    subst /D
    subst z: %1


    Next, I create shortcuts on my desktop that runs this batch file for each of my clients.

    In short, if you wanted to work on BIGAUTOS website you would set up a shortcut to run :

    C:\DEV.BAT "C:\Documents and Settings\Administrator\My Documents\websites\BIGAUTOS"

  3. #3
    Non-Member CapitalWebmaster's Avatar
    Join Date
    Mar 2002
    Location
    Braselton, Georgia USA
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I hope someone will find your tip helpful if they are at a lost. It's great when someone takes the time to spread the news of fix's they've found for their troubles. Had I known this was an issue with a lot of people, I would have offered my solution back when I installed on my Win98 and Win2000pro machines, the Apache server with PHP and CGI/Perl. It took about a day of research and trial & error to configure it just right, and it works great on the D: side of my drive's partition. And I won't even go into the MySQL install here.

    I've been running Apache on both platforms for more than a year now without any trouble. In regards to paths and where my client website project folders are located, it is a cinch. May I ask you, why not use this approach?

    Start a new client folder in htdocs under Apache named appropriate for the client site, i.e. vetnet. Where all the site work will go just like it will on the live host, thus D:\Apache\htdocs\vetnet. And in your browser will go 127.0.0.1/vetnet. The path to which, would be D:\Apache\htdocs\vetnet. I don't know what you mean or why you'd have to clear the htdocs folder for each client. All my clients are in there to stay.

    The most complicated thing is the fact that the path goes into a mainconfig file for the entire site that you must change before going live. You have to anyways for MySQL host, user, and pass. But it's just one line, one time.

    I wouldn't change the way I do it now unless I needed to. If however you could provide a solution to this, than you would have my deepest admiration:

    1. I would like to test the sites local by typing into the browser the actual would-be address, i.e. www.vetnet.com. And to be able to use http & https.

    2. I would like for my local MySQL to be set exact to my host MySQL in regards to host, user, and pass.

    In other words, when my site is complete locally, I need not change one single thing. Simply upload as-is and there it will be. Is this even possible without a DNS to resolve domain name. I've done a lot of research and have come up empty so far. What do you know about this? I hope you don't mind my saying, but I can't believe you actually go through all that stuff to set up a new client for development. I just create a new folder and off I go.

  4. #4
    SitePoint Member
    Join Date
    Apr 2002
    Location
    Bay Area, CA
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I love this tip. I had COMPLETELY forgotten about the SUBST command. Anyways, on to my $.02...

    I don't like the idea of subdirectories off the htdocs directory. It limits your ability to define root-based urls/links/image locations, etc. You would need to make every link a relative link. Not my preference.

    My httpd.conf is set up to listen on multiple ports, thus allowing me to use http://localhost:port#1 as one of the sites I develop and http://localhost:port#2 as another, and so on. This allows me to use relative or root-based links to everything. There are plenty of ports available that aren't already being used for something. (visit here to see a complete(?) list and search for "Unassigned", or many people fall back on the numbers in the 8000-8099 range. Some are taken however they should be fine to use for local development).

    In the PHP/ASP that I write, I write an if/then block to do a comparison against the SERVER_NAME server variable to set my include() home paths. Thus...

    Code:
    if ($_SERVER["server_name"] == "localhost") {
       $includepath="c:\\projects\\web\\client";
    } else {
       $includepath="//home/client/www";
    }
    or, if you prefer the ternary method...

    PHP Code:
    $includepath = ($_SERVER["server_name"] == "localhost") ? "c:\\projects\\web\\client" "//home/client/www"
    That way I don't need to comment/uncomment lines. The config files containing all my site variables (MySQL info, color constants, etc.) are based off the $includepath variable. It's served me quite nicely.

    Keep coding!
    matte
    silent (e)
    www.silent-e.com

  5. #5
    SitePoint Enthusiast
    Join Date
    Mar 2002
    Location
    Salt Lake City Utah
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up why not just

    use a linux box for dev? I normally have a couple of old cheapie K6-2 or slot-1 celerons laying around from work (but I know you could pick up the same for <$50 in the paper) that I keep set up with Linux. it's not that hard to set up for a user such as an ISP does.

    Just another $.02

  6. #6
    SitePoint Addict Caterwomtious's Avatar
    Join Date
    Dec 2001
    Posts
    222
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How do you set up Apache to listen on different ports? To me, this sounds like the best solution on offer!

  7. #7
    SitePoint Addict
    Join Date
    Nov 2000
    Location
    London, UK
    Posts
    223
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've gotta agree with imbiz:
    Clearly what you should do is set up a linux box on your network. If you did so, you could do all those beautiful things you wanted. This is the setup I use, and it took me about 2 hours initially to set up (I did it between projects), and I currently need about 1 min to setup a new client.

    1) Being able to use the domain name e.g. www.vetnet.com
    If you have the linux box set up, make sure to write down its IP. Then, open up your hosts file in Windows (do a search under the Windows directory for "hosts"), and add a line mapping the linux box's ip to whatever domain it is. Then open up apache's conf file and setup a new virtualhost that maps that domain name to the /home/clientname/www

    2) Being able to edit it directly through Dreamweaver
    To do this what I did was to set up Samba on the Linux box. What I have it do is depending on the username and password I provide when I login to samba, it drops me into the client's directory e.g. /home/clientname. I then setup my Dreamweaver projects to have their home directories as this:
    \\username:password@lin.ux.box.ip, making sure that the username is the proper client's. Then, when you switch projects, it puts you directly onto the linux box, in the right directory and tadaaa! It works!

    3) Making it fast and easy
    Make a PHP script locally (Windows box) that displays a form into which you just enter the domain name. The script should then add the linux machine's ip and map it to the domain name you entered into the hosts file. After that, it should forward you (use header("Location: blah")) to a php file on the linux box, passing the domain name through the querystring. DON't use one of the domain names you've set up, just use something like 192.168.0.10/step2.php.

    The thing that takes a bit of time and is a pain to setup is a new client on the linux side. However, you can write a simple PHP script that will add the required entries for you. First, cut all of the <VirtualHost> entries from your current httpd.conf, and add them to a new file called vhosts.conf. Add a line in the httpd.conf where the virtual host entries used to be:
    Include vhosts.conf
    Then setup a php script in apache's htdocs directory that'll display a form asking for these infos:
    - username
    - password
    When you submit it, it should first login itself in as root. Then it must run the system("adduser $username") command, and give the password, so the user is created. Then it should create a <VirtualHost> entry in the vhosts.conf, using the domain name passed to it from the other script, and create the www directory in the new user's home directory. Finally, have it reload apache's config by either running /etc/init.d/httpd reload or apachectl reload (assuming apachectl is in the PATH). Save the file into apache's default htdocs directory as whatever you called it when you linked to it from the first file.

    You're done! Now, whenever you want to add a client, simply do this:
    http://localhost/wizard.php (that's what i called mine). Give it the domain you want, and click Go! or whatever.
    It'll redirect you. Add the username+pword you want, and click Go!. You now have your new client setup.
    Then all you have to do is go into dreamweaver and add a new project as explained above. You should set the http url to be the domain name that you setup.

    Enjoy this setup, it's really quite powerful once you've created it. The linux box I use is an old 90mhz pentium with 1gig of disk space and 48 megs of ram, running apache, mod_php, mod_perl, mod_jk+tomcat, MySQL, PostgreSQL, and some other stuff like postfix, squid, imapd, bind, etc. So as you can see yo don't need anything too powerful to do this. At one point I even had it working on a spare laptop...

    If you need help setting this up PM me.
    Last edited by FatPiper; Apr 14, 2002 at 04:17.

    ... what's the world coming to?

  8. #8
    SitePoint Enthusiast
    Join Date
    Jul 1999
    Location
    York, UK
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Rather than using different ports you could use different addresses (127.0.0.x - which I believe are all reserved for internal use). The only disadvantage to this is that you cannot access these sites (except for 127.0.0.1) from across your LAN.

    The code is as follows (goes in httpd.conf):-

    [CODE]<VirtualHost 127.0.0.2>
    DocumentRoot d:/sitename
    ServerName 127.0.0.2
    ErrorLog logs/127.0.0.2-error_log
    </VirtualHost>[CODE]

    If you wanted to do the port method I believe that:-

    [CODE]<VirtualHost localhost:81>
    DocumentRoot d:/sitename
    ServerName Name
    ErrorLog logs/Log81-error_log
    </VirtualHost>[CODE]

    should work. Someone please correct me if I am wrong.

    CapitalWebmaster I suggest that you use "silent (e)"'s tip of using if statments in PHP/Perl coding to elimitate the need for commenting out lines.


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
  •