Press "Enter" to skip to content

Preparing for Game 2 – Learning PHP and MySQL

In order for my next game to be able to save user data and transfer data for turns and chat I’ll need to set up a server and learn how to get data on and off it vial simple HTTP commands. I began my adventure today and will chronicle what I’ve done so others can easily set up a test system. I feel that what I’m trying to do is so basic (send data to be written to a database and retrieve that data)

First thing’s first, set up Apache Server. This was pretty easy: download the ZIP for Apache 2.0, extract the files to the directory of your choice (I chose c:/Apache), make a few minor changes to its config file, and then just open up some ports on your router and unblock them from your firewall. That’s it! I had this part of the project going before noon today and was pretty happy with the information I was able to find.

There are a ton of guides out there on how to set up Apache server (2.0 Win32) in Windows, so I’m not going into great detail here. One thing I should mention is that you should be careful with security. If you’re just testing an app then shut down your server when not testing. Once the server is installed you should see an icon in your taskbar’s icon try (tiny up arrow over by the clock). Left clicking on this will allow you to quickly start/stop/restart the server.

After you’ve downloaded the ZIP for Apache server 2.0 for win32 x86 and extract it to the directory of your choice you can start meddling with the configuration file. It’s called httpd.conf and located in the Apache/conf folder. Simply open it up with Notepad and make the following changes:

  • Find thisServerName localhost:80 and replace localhost with whatever name you want. This will be the name you type into your browser on the server computer to check things as you set them up. I left mine alone.
  • You also might want to change this ServerAdmin admin@localdomain to whatever email address you might want to use. Again I left this alone as my server won’t need email functionality.
  • If you don’t want to use the default directory for you website’s files then change the DocumentRoot “C:/Apache/Apache2/htdocs” to the directory of your choice.
  • Change the line DirectoryIndex index.html to also include index.php – we’ll use that later after we set up PHP.
  • Next we’ll want to set up a password. This is done by going to the Apache/bin directory then hold shit and right click in a blank area of the Windows Explorer window and “Open Command Window Here” for a command prompt. Type htpasswd -c “c:/Apache/Apache2/pw.txt” yourName. Replace the directory with your actual directory and replace yourName with whatever name you want for the admin account. You’ll then be prompted to create a password and you’re done.
  • Now we need to create a script to manage the login. Create a file in Notepad and name it .htaccess then enter the following:

  • Restart Apache server and then open a browser and enter localhost if all went well you should be prompted to enter your username and password. If you didn’t create any index.html or index.php yet then you won’t see anything else, so go ahead and create that if you want.
  • Now you’re going to want to set this up so that you can access it via the web so open up your router’s settings and port forward port 80 for the IP address of your server. Then set your server’s IP to be in the DMZ (usually under WAN setup).  You may also want to make sure the computer you’re using as a server has a fixed IP on the network and the address has been reserved on the router. 
  • Finally you’ll want to open up your firewall and add an exception for two-way traffic on port 80. Now you should be able to go to any computer on the internet and login to see your website.
That’s all it takes. Many other guides I see have a bit more detail, but they seem like they expect you don’t know much about changing your router settings or how to navigate Windows Explorer to find files. I hope that this guide is a bit more to-the-point and helps the slightly advanced user get up and running quickly. If you’re stuck on any point you might want to search Google for a more detailed guide. For many I hope this will get you up and running in a jiffy.
 
Next up is setting up PHP and then MySQL. Thanks for reading, see you next time!

Loading

Leave a Reply

Your email address will not be published. Required fields are marked *