Installing Apache, MySQL and PHP
MatthewHSE
Status: Contributor
Joined: 20 Jul 2004
Posts: 122
Location: Central Illinois, typically glued to a computer screen
Reply Quote
Hi folks, it's been awhile since I've been able to stop by here, but my schedule is about to slow up a bit (I hope!) so hopefully I'll be able to be around more often now.

Anyway, I'm trying to delve into running a server of my own off my home computer on a static IP. It's a Windows 2000 box, but obviously I want to run Apache for my web server.

I installed XAMPP awhile back, and though it works well for development, I've heard it's not a good idea to use for a production server due to security issues.

I've had a terrible time in the past trying to get Apache, MySQL and PHP installed individually and running together. I've followed all the instructions in the various tutorials around the web, but I never could get them all to talk to one another.

So I'm wondering at least two things:

1.) Are there any packages similar to XAMPP that are suitable for a production server, or,

2.) Have the install instructions changed for Apache, MySQL and PHP since the latest versions came out? (All the tutorials seem to be a couple versions behind.)

So far my own research on these topics has brought me up empty-handed. I'm not about to run an IIS server, so I'd really like to know how to get Apache and such running properly and securely.
Back to top
techAdmin
Status: Site Admin
Joined: 26 Sep 2003
Posts: 4127
Location: East Coast, West Coast? I know it's one of them.
Reply Quote
MatthewHSE, good to see you back. Your question is very good. Most serious advice I've come across suggests compiling apache/php/mysql from source. That's for real production servers, since that's what gives the most optimally tuned results.

However, that's not necessary in your case, or most average user's cases. XAMPP type installs are definitely a quick and dirty way to get the setup running, but leave you with basically no idea of what's going on at all. And the XAMPP site itself explicitly warns against using the XAMPP package for a production server. Why? Because user friendly = insecure. It's one of the simplest formulas to master out there. This is the main fault behind IIS. Open all the ports, make the defaults full permisssions across the board, and there are no problems at all. Except for getting hacked by anyone who feels like it at any time.

Currently, the Apache/PHP/Mysql binary installers work very well, although they must be installed and configured in the correct order. Failure to correctly do each step completely before moving onto the next step will result in failure of the server system as a whole.

I can't emphasize enough the value of taking the time to learn how this stuff works, but it's time well spent in terms of deepening your understanding of the processes involved.

Take as your mantra 'RTFM' * :: that's the best saying out there, it says it all
Although the initial learning curve was present, this year's Window's installers have made your life much easier from what I can see. Mysql was especially problematic before if your os was not on the C: partition. I believe that this issue has now been resolved.

While there is some time involved in this process, I have to emphasize, since installing Apache/PHP/Mysql about 2 years ago, I have never had to do anything at all to it, it's never stopped working, all the components run as services, all my sites are run locally for testing and development, it takes me a few minutes to add a new local site. The only difference between my local sites and my web hoster sites is that I don't use .htaccess locally, since that sets unix server paths I can't duplicate on windows. All my .htaccess code is run directly in my httpd.conf file, php include paths, mod_rewrite etc. The only code modifications I do are to select mysql connection strings based on whether it's a local host or web server running the scripts. Everything is fully portable, I can run any site I do by typing in a 2 letter shortcut into my browser.

* RTFM :: Read the F*cking Manual

Apache PHP MySql Installation on Windows
With this in mind, I'll explain the install procedure, which is taken mainly from the book 'Professional PHP 4', Wrox press. Personally I wish I'd bought 'Beginning PHP 4' instead, but both have a very well written install procedure, which requires only a few searches to work out some issues along the way.

None of the step are optional, and the order of installation is also not optional. If the mysql install is not yet running as a service, the apache install cannot happen.

The versions I'm using here are:
Apache 2
PHP 4.3.2
MYsql 3.23.49

These were the latest stable binaries available when I did my last install.

If you decide to go this componet route, make sure to uninstall all the other versions of php, apache, and mysql, and stop the Windows NT services so the system doen't get confused.

Download Windows Apache PHP Mysql binaries
First step is to download the latest binaries:
  • Apache 2. Make sure to read the Windows32 specific section before installing. You can read more windows apache installation instructions here
  • Mysql 4.1. Mysql was the hardest component to install with the old Windows installer, but my guess is that the newest release worked out some of the problems. Read the Windows installer directions here. Mysql recommends using the 'essential' package. Follow all such recommendations.
  • PHP Binaries. It's up to you whether you use 4 or 5, I prefer sticking with 4 since that's what most web hosters are using, although moving to 5 is probably not a bad idea now that it's been long enough for hosters to begin switching over. If your PHP 4 was well written, didn't use globals, didn't use deprecated elements, you should have little difficulty running all old 4 scripts on PHP 5.

    You can get the PHP manual documentation here


Server install order
Once you've downloaded the above, and you've READ the Windows Specific Installation links, you need to install these in the following order:
1. Mysql
2. Apache
3. PHP

You're lucky on the mysql, I haven't tested the new windows installer, but I read the docs quickly and it sounds like your life has been made much easier.

Mysql must be installed, working, and running as a windows service before you proceed to the Apache installation.

The apache installation is fairly easy. I use Apache Monitor to make start and stopping apache easier.

Once Apache is installed and running, which is easy to test by simply opening up your browser, typing in 'localhost', then you should see the default Apache index page, which says apache is working but there are no sites linked to it yet.

installing PHP is also relatively easy, and involves a few php.ini tweaks, along with telling apache that it needs to use mod_php for php requests.

Since I haven't used the new MySql installer, I can't give a specific instruction on it, but the key here is to make sure to test the mysql server to make sure it's working correctly before doing anything else.

Apache httpd.conf
This file is what configures almost every component of apache. It's where you add modules, setup virtual sites, and whatever else y ou want to do. Once apache and mysql are installed and running, it's a fairly easy process to add modules like imagemagic or gd, both image manipulation modules. Same with PERL, SSL, or whatever else you want to run locally.

You will have little luck with Apache if you don't spend some time familiarizing yourself with httpd.conf, which is a very intimidating document when you first look at it, but it's extremely well commented. Rule of thumb with it: make backups when you make changes.

httpd.conf on windows is located, assuming your OS is on the C: partition:
program files/apache group/apache2/conf/httpd.conf

Window's hosts file configuration
In order to run your sites locally using virtual domains, you need to configure your Windows 2000 hosts file, located in winnt/system32/drivers/etc /hosts

Notice the holdover from unix file system, /etc is where unix configuration files are kept too.

hosts has no extension, don't open it with notepad and try to save it, use a real text editor, as always.

A sample hosts file:
:: Code ::
127.0.0.1 localhost aa bb cc dd ee ff gg xx

When you have setup the apache virtual hosting correctly, when you for instance typed in aa into your browser, it would open your development site aa. Hosts can also be used to access sites over your network, you would simply add a line to it with the IP address of the apache server box, with the site initials after it. But not localhost, that is always linked to the loopback address of 127.0.0.1

Conclusion
if you decide to go this route, which has just been made much easier for you, you will run into certain snags along the way, although fewer than you would have in the last 2 years. Rather than try to guess what those will be, since you may not do this route at all, I'll wait for you to post your specific questions on any stage.

If you'd like, we can run through the install procedure step by step together, I can setup another apache on another windows installation I have available. Since some things are much easier now than 2 years ago, I don't want to put out unnecessary steps in case this proves to be useful to other visitors of the forum. If you want to do that, I'd recommend we make one thread for each major step, mysql installation, apache installation, and php installation, then any other modules you might want to add in the future.

Last Words
If you are going to pursue a career in web development, spend the time to learn how your primary tool, the web server, runs. All learning you achieve in this area will make you a better webmaster and web developer. There is no downside to spending this time, except of course having to spend the time. But long term it's one of the best moves you can make, I severely handicapped myself by not doing that for several years. When I finally did it, my development progress jumped up almost instantly.
Back to top
Display posts from previous:   

All times are GMT - 8 Hours