Tag Archives: Apache

Setting up a web server with PHP, MySQL and Apache on Windows XP

This tutorial is designed to help newbies get a web server setup and running. This tutorial will take you from no web server, to a fully working WAMP (Windows, Apache, MySQL and PHP) web server installation including “Hello World” in PHP for the hell of it.

Usually any software bundle for web development has a few key characteristics that make it stand out

  • Platform – Windows XP
  • Database – MySQL
  • Web server – Apache
  • Programming language(s) – PHP
  • more on this.

This is called a WAMP configuration as we’ve already discussed. I’m just trying to beat it into your brain.

If you use Windows IIS web server you get WIMP. Do you see what I’m saying? We’re going to use Apache. Windows IIS is the redheaded step child of the HTTP server world.

(This post is not to be confused with setting up a development server on Linux which is often referred to as a LAMP setup.)

This tutorial is for you if

  • You want a local web server and you’re not sure how to set it up
  • You’re new to the concept of web development
  • You chose PHP as your primary language
  • You want to use MySQL as your relational database
  • You want to use Apache as your web server
  • You run Windows XP or a Windows based operating system
  • …and you’re a little new on the scene.
Video tutorial (6:15 runtime)

Things not covered in this tutorial:

  • phpMyAdmin
  • Editing hosts file and “localhost”
  • Setting up FileZilla FTP
  • Setting up MySQL
  • Making your web server viewable to the internet

There you go, if you have any questions leave them in the comments I’ll be more than happy to help. Enjoy!

This is the first of many so stay tuned!

Bryan

How to use mod_rewrite with .htaccess (Part 2)

This is a continuation of my first article you can read here on how to use mod_rewrite with .htaccess. It can be a pretty daunting task getting all of this to work together seemlessly but once you get it working, it’s so easy and so sweet to use. In the last article

  • How to enable .htaccess files
  • How to include the mod_rewrite module in the httpd.conf (Apache Config)
  • How to turn on .htaccess permissions in Apache config
  • How to turn on mod_rewrite in a .htaccess file
  • How to write mod_rewrite rules in .htaccess files
  • How to create dynamic variables with preset tags

In this article we are going to handle a little more regex but also a little more of Apache’s built-in functionality.

Lets say you have a website, http://www.crainbandy.com and you want to accept anonymous commands to the “root” URL, or http://www.crainbandy.com/command instead of using a placeholder like we did in the last article. We used the placeholder cmd/commands.

What are placeholders?
When you begin to work with .htaccess files and mod_rewrite for your URI’s you’ll realize that you have to have a placeholder to extend your URLs off of, example
http://www.crainbandy.com/cmd/signup or http://www.crainbandy.com/cmd/login the placeholder here is cmd because it is familiar to you. You are already looking for this variable so there aren’t any surprises, everything after the placeholder is turned into the command and you can deal with it accordingly. After you have a working placeholder you extend with things like /functions or /send etc. Let your imagination take it’s places. I hope you understand placeholders for URLs they are really essential with mod_rewrite (until you get into heavy regex & apache voodoo which I don’t intend to get into in this article)

What if I just want to have /login instead of /cmd/login?

Good luck, not going to happen.
…just kidding.

Well that’s the problem I ran into. The reason this was particularly hard to find an answer for is because Apache automatically searches for a folder first, then a file. So if you go to crainbandy.com/login and it’s not a folder, nor a file, nor does apache have a rule to deal with this it just crashes giving you a 404 error… Hardly the desired result. So I, being the crafty being that I am thought about using a folder /login to hold the login script, but I just don’t want to have folders for all of my root URL functions (root URL meaning, right after the base url or www.crainbandy.com/THIS IS THE BASE AREA/THIS IS POST BASE/ THIS IS POST POST BASE… etc) so I thought ah well, what if I redirect the 404 to my index.php and parse it there? Cool. You just run into more problems so then I decided to stop being a genius and use Google & the Apache manual to find this

Enter the world of RewriteCond’s and RewriteRules working together in a harmoniously violent and tasty artistic jellyish fashion.
In english, you can tell apache “If there isn’t a folder, or a file, do this” which is exactly what we need, so here’s the code.

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/.]+)$ index.php?cmd=$1 [L]

Oh so nice. notice how the start of the rule … “^” doesn’t have a placeholder? like ^cmd or ^action it just simply has that scary regex statement that like I said in my previous post, says “everything”, isn’t that crafty? All of that !-d voodoo is built-in to Apache. Basically says, Find a filename or a folder … (-d) if you can’t find it, do the rewrite rule below. So! Hope that helps you guys some more! This would allow for what I call, base URI’s (actions & commands and all kinds of stuff without placeholders) which is sexy.

You could use this for a myspace type result with the whole, “myspace.com/users_url” thing. So, hope this helps you make your site a little bit cooler.

How to use mod_rewrite with .htaccess (Part 1)

Update - I wrote the continuation to this article hereHow to use mod_rewrite with .htaccess (Part 2)” go check it out after you’re done with this one.

So maybe some of you have seen a website with URLs like this:
http://www.crainbandy.com/index.php?action=login
Or perhaps you’ve seen this
http://www.crainbandy.com/login but you’re just not sure how they get all those get variables and .php’s and things into one pretty little string? Well, I’m going to show you how to do just that.

First off you need to have Apache and the mod_rewrite module uncommented in the httpd.conf if you’re not sure open your config file and check, in /etc/httpd/conf/http.conf (I’m running Fedora linux) If you can’t find it just do a locate httpd.conf in the bash and you should be fine.

Find the line where apache loads all the modules, you’ll know because you’ll start to see a lot of LoadModule going around. Some config files will vary depending on what version of apache your running but we’re trying to achieve the same goal here so, just make sure you remove the comment (#) from the rewrite_module modules/mod_rewrite.so

It should look like this:
Load Module rewrite_module modules/mod_rewrite.so
and you’re set as far as that’s concerned.

Now we’re going to be using .htaccess to specify the mod_rewrite rules so we’ll need to make sure you’re allowing .htaccess. Look for the flag “AllowOveride All” and make sure it says just that. Then look for a flag called “AccessFileName .htaccess” These flags must be set otherwise it’s not going to work.

.htaccess just allows you to control file/folder permissions on a per-folder basis instead of overall. It comes in handy quite often, such as right now. Okay, hope you’ve got it…here we go.

I am not going to go into a huge amount of depth here (after all, it’s just part 1) but I do want to leave you with something to play with so you can make your sites look pretty and nice. If you need to do more than we do in this (you probably won’t, most average people only need a few mod_rewrite rules) then stay tune for part 2.

First things first, create a .htaccess file in your web root directory (wherever your index.html or index.php (hopefully) file is at) Inside this file, we’re going to enable mod_rewriting and make a few rules.

Lets enable mod_rewriting in our .htaccess this is done simply by putting,

RewriteEngine on


Read more