Often times when people install WAMP [or LAMP] stacks on their machines, they’ll commonly use
http://localhost/ to access their local server. I did so for years until I started working with dynamic sub domains and needed to use something other than
localhost to access my server.
Example.com [or example.org, example.net] is a special domain as defined in RFC 2606 used for, you guessed it, examples. These domains will never be available to the public, so there’s no need to worry about not being able to access the actual site in the future.
Setting this up involves three main parts:
- Set up a static IP on your machine.
- Configuring Apache.
- Editing your host file.
Everyone will have their
httpd.conf file set up differently, so use this as an example of how to accomplish this. Keep in mind this file fragment should appear at the bottom of
httpd.conf. I have also included my SSL layer here as well. It’s not important for most installations, but I included to show how to use it with example.com.
The main theory behind this is to set up everything under a VirtualHost:
192.168.1.23 is my machine’s static IP, so be sure to replace it with YOUR static IP
# apache # NameVirtualHost *:80 # Dir structure # Listen 192.168.1.23:80 ServerName 192.168.1.23:80 <VirtualHost *:80> DocumentRoot "S:/apache/htdocs/website1.com/" # DocumentRoot "S:/apache/htdocs/website2.com/" # DocumentRoot "S:/apache/htdocs/website3.com/" # DocumentRoot "S:/apache/htdocs/website4.com/" # DocumentRoot "S:/apache/htdocs" ServerName www.example.com:80 </VirtualHost> # PMA # <VirtualHost *:80> DocumentRoot "S:/apache/htdocs/sql" ServerName sql.example.com:80 </VirtualHost> # SSL -- Don't include this if you don't use SSL # LoadModule ssl_module modules/mod_ssl.so SSLRandomSeed startup builtin SSLRandomSeed connect builtin SSLMutex default SSLSessionCache none Listen www.example.com:443 <VirtualHost *:443> DocumentRoot "S:/apache/htdocs/website1.com/" # DocumentRoot "S:/apache/htdocs/website2.com/" # DocumentRoot "S:/apache/htdocs/website3.com/" # DocumentRoot "S:/apache/htdocs/website4.com/" # DocumentRoot "S:/apache/htdocs" ServerName www.example.com:443 SSLEngine On SSLCertificateFile S:/apache/conf/pfs.crt SSLCertificateKeyFile S:/apache/conf/pfs.key SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown ErrorLog logs/ssl_www.example.com-error.log </VirtualHost>
Some directories are commented out, this allows me to run multiple sites on the server root. I just un-comment the site I want to work on, comment out the rest, restart the server and I’m good to go.
Host files are like mini, stripped-down DNS servers that sit on your machine. This is where you tell your computer, “When I type in http://www.example.com, I want it to go to my local server, not the internet”. Once again, this is something widely available on the net:
Once you have your host files editable, add this to the bottom [don't over-write existing entries!] … also be sure to replace:
192.168.1.23 with YOUR static IP:
192.168.1.23 localhost 192.168.1.23 example.com 192.168.1.23 www.example.com 192.168.1.23 sql.example.com
Using your machine’s static IP over
127.0.0.1 will allow other machines on your net work to connect to your server via http://www.example.com … but you’ll need to edit those machine’s host files as well .. just use the same info from above on all your machines. Also make sure your firewall allows communication on Apache’s ports [80, 443].
You will more than likely have to restart your web browser or possibly your computer to get this to work.
Using a DNS server would eliminate the host file layer of this guide, but since I don’t use one, it’s not in this tutorial … but it would be ideal for larger companies or offices [after all, it's just me, myself and I in my company].
One thing I will openly admit about this tutorial is that I have very little experience configuring apache. everything you see here I found around the internet and played with it until it worked. With that said, if you are more knowledgeable with apache config and have something to add, PLEASE DO SO! :-)Read Full Post | Make a Comment ( 5 so far )
LAST UPDATED SEPTEMBER 11, 2010
Installing memcache on Windows XP / Vista is kind of like voodoo for those of us who are not disciplined with compiling code from source. I initially attempted to install memcache a few months ago after reading a few articles about how much performance it can pump into your web application. The problem is that memcache was written with Linux in mind, not windows. So you can’t download any installers or exe files from memcache’s site for windows … which leaves people like me, who use WAMP stacks to develop applications, out in the cold.
So after a few hours of Googling I found a cocktail of methods and files to get memcache to work for win32.
A few things about memcache:
Memcache is a daemon, meaning it runs as a separate service on your machine. Just like MySQL runs as a separate service. In fact, to use memcache in PHP you have to connect to it, just like MySQL.
Think of memcache as the
$_SESSION variable for PHP, but instead of it working on a per-user basis, it runs over the entire application — like MySQL. In fact, you can use memcache as you session handler for PHP.
This is how I got memcache to work on my windows machine:
- Download memcache from code.jellycan.com/memcached/ [grab the 'win32 binary' version]
- Install memcache as a service:
- Unzip and copy the binaries to your desired directory (eg. c:\memcached) [you should see one file, memcached.exe] – thanks to Stephen for the heads up on the new version
- If you’re running Vista, right click on memcached.exe and click Properties. Click the Compatibility tab. Near the bottom you’ll see Privilege Level, check “Run this program as an administrator”.
- Install the service using the command: c:\memcached\memcached.exe -d install from the command line
- Start the server from the Microsoft Management Console or by running one of the following commands: c:\memcached\memcached.exe -d start, or net start "memcached Server"
Now that you have memcache installed, you’ll have to tie it in with PHP in order to use it.
Check your php extensions directory [should be something like: C:\php\ext] for php_memcache.dll
If you don’t have any luck finding it, try looking at one of these sites:
- downloads.php.net/pierre/ [thanks to Henrik Gemal]
- pecl4win.php.net/ext.php/php_memcache.dll [currently down]
- www.pureformsolutions.com/pureform.wordpress.com/2008/06/17/php_memcache.dll for PHP 5.2.*
- kromann.info/download.php?strFolder=php5_1-Release_TS&strIndex=PHP5_1 for PHP 5.1.* [thanks, Rich]
- Now find your php.ini file [default location for XP Pro is C:\WINDOWS\php.ini] and add this line to the extensions list:
- Restart apache
- Run this code to test the installation: [found on www.php.net/memcache]
<?php $memcache = new Memcache; $memcache->connect("localhost",11211); # You might need to set "localhost" to "127.0.0.1" echo "Server's version: " . $memcache->getVersion() . "<br />\n"; $tmp_object = new stdClass; $tmp_object->str_attr = "test"; $tmp_object->int_attr = 123; $memcache->set("key",$tmp_object,false,10); echo "Store data in the cache (data will expire in 10 seconds)<br />\n"; echo "Data from the cache:<br />\n"; var_dump($memcache->get("key")); ?>
If you see anything but errors, you are now using memcache!
Memcached, by default, loads with 64mb of memory for it’s use which is low for most applications. To change this to something else, navigate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\memcached Server in your registry, find the ImagePath entry and change it to look something like this:
“C:\memcached\memcached.exe” -d runservice -m 512
Now when you start the service via net start “memcached Server”, it will run with 512mb of memory at it’s disposal.
[Thanks to Travis]
If anyone is wondering what other options can be set (other than the memory limit), run “memcached -help” in a command prompt window. Then modify the ImagePath command line per this article with the desired switches and values.