Installing PHP on UNIX
enygma on 2001 March 11
enygma on 2001 March 11
Where to get them all
Well, to start things off, you have to have the right tools. There are three different sites that you need to visit to get the three files that you need to install all of this together and in working order. This is all assuming that you are doing this on a UNIX based operating system
So, let's get started - here's the ftp sites that you need to go to to get the files:
Apache - http://www.apache.org/dist/
MySQL - http://www.mysql.com/downloads/index.html
PHP - http://www.php.net/downloads.php
Now, each of these sites have a "latest" file that should point to the most recient release of the software. Be sure that you get the latest stable release of all of them. Otherwise, you might have a flaky MySQL server or unsupported PHP commands popping up. They should be large-ish files, but not really huge. Just putting them in your local directory is fine for now.
Getting these files is the easy part, and once you get them all downloaded completely, you might want to make a copy of them and put them somewhere so that you can use them later if you need to reinstall for some reason.
Preparing the files
Now that you have the files and some backup copies (just in case), take them and move them to the /usr/local directory on your machine. Be sure that you have enygma access to set these all up properly. Otherwise, some portions may not install right. Run the "tar" command to unpack the three files into directories and make it so that you can install them easier. The format that you'd need to unpack them is:
tar zxvf file.tar.gz
where the "file.tar.gz" is the filename, like "php-4.0.1pl2.tar.gz" and the others. This will make it list out all of the files that it unpacks and probably unpack them into a direcctory under /usr/local. This should prepare you for the next parts of the install process.
Before we start, there are several commands that you need to be familiar with. Hopefully, you've compiled some things before on your machine and know how it is supposed to work. There are a few steps that are outlined here, but as usualy, with a UNIX based operating system, there are tons of other options that you can add into the mix. Once you compile all of this and get it working and have an idea of how it's all supposed to work, you can go and add in other features. The three main commands that you'll need to remember are "configure","make", and "make install". These are not only the foundations for getting these things to work together, but also key commands for the entire OS. They are the commands that allow you to install software onto a system.
The "configure" does just what it sounds like. It gathers information about your system and sets up a file called the "Makefile" that helps compile the rest of the program when the time comes. The "make" command is the next in the process, and is the first one that actually compiles some of the files for the program. Then, the "make install" command goes through and copies the files to where they need to go. Ideally, when you run these commands things will go off without a hitch and everything will be happy. If it doesn't, you might be in a bit of a bind. It's not the easiest thing to troubleshoot, but after a while, you end up doing a lot of finger-crossing and hoping.
Beginning the Installation
Okay, once you have all of the files uncompressed and ready to go in their directories, you need to take a look at the PHP "INSTALL" file. This will help this process go a bit smoother as I step you through it.
Now, keep in mind, as we go through this, if anything that I say doesn't work or something doesn't happen quite the way that I say, you might have typed in a command wrong or you might have something different about your setup that makes the make or make install flake out.
So, anyway, on with the fun...
First things first - we need to get MySQL up and running. This will mainly involve those three commands that we talked about before (configure, make, make install). First, go to the /usr/local directory and issue this command:
ln -s mysql-VERSION-OS mysql
where the "VERSION-OS" part is the rest of the name of the directory Then, head over to the MySQL directory, /usr/local/mysql-x (where the "x" is the rest of the directory name. This will make a symbolic link in the /usr/local directory so that you have a "mysql" link there now. Once you have that done, go into the mysql directory and begin the fun. Issue these commands in this order (one after the other finishes):
./configure
make
make install
Now, between these, a lot of stuff will fly past your screen, hopefully all good. Don't worry too much if there are some things that say that there is an error or a problem. The only thing you don't want to happen is that the program just completely stops. Usually if it does that, it will give you an error and tell you waht the problem is. It's up to you to figure out what you need to do to fix that.
So, once that is all done (and depending the system it might take just a second or several hours), there are only a few more steps to getting mysql installed and running. After the "make install" finishes MySQL should be all set up and ready to be run. To do this, issue the following commands:
scripts/mysql_install_db
bin/safe_mysqld &
These will set up the initial databases (and show you how to set the enygma password) and start the server up in the background so that it doesn't clog up your console. If all went well, you should have a nice MySQL daemon running in the background waiting for you to connect to it. To check, use "ps aux" and see if there are any named "safe_mysqld" running.
Now, on to PHP and Apache - First, head over to your Apache directory (/usr/local/apache if you put it where I normally do). Once you're there, type the following command:
./configure
This will spit out a few lines and hopefully not give you any errors. If it does, see if you can figure out what it wants. If you can't tell, consult Apache. Next step, go over to the PHP directory. You can get there from here with the command:
cd php-4.0x
where the "x" is the version that you have. Usually, in linux, if you use the Tab key, it will complete the directory or other filename that matches the pattern.
Okay, so now you're in the PHP diretory. Now, we get into some fun stuff. This next part depends a bit on what you want to do. Since this tutorial is about getting MySQL, PHP, and apache working together, we'll include the MySQL stuff. If you just wanted Apache and PHP, you could take it out. The configure line for this one is a bit more complex than the last one:
./configure --with-mysql --with-apache=/usr/local/apache --enable-track-vars
This line tells the configure program to run with a few options. It tells it to look for the MySQL installation and to find the files it needs there and to do the same for the Apache files that it needs. See that stuff after the "=" on the second part? That's to help the configure command to know where the files are if it can't find it. Depending on how your system is set up, you might have to do the same kind of thing on the "--with-mysql" part too if it can't seem to find it. This should run through some of the same stuff you've seen before and tell you if it found all of the programs that it needs.
The next step is to issue the next two commands that almost every install uses:
make
make install
These will get the PHP stuff ready for use and install the files where they need to go. Hopefully, again, you will not have any errors and things will install smoothly.
We're almost done now! Just a little bit more work and you should be able to enjoy the fruits of your labor. Hop on over to the Apache directory (apache_1.3x) and issue these commands:
./configure --activate-module=src/modules/php4/libphp4.a
make
make install
These will tell Apache to use the PHP libraries that you compiled before and to install it using those settings. Again, things should go well, if they don't, check the steps before and make sure that everything got compiled in correctly.
If all goes well, you should have a nice Apache server waiting for you once you get done compiling! To get the thing fired up and working, run the "apachectl start" command in the /usr/local/bin directory. This should tell you that it is starting an Apache server. If it gives you a line about not being able to get the ServerName or something, you'll need to edit the "httpd.conf" file and change it to the host name or the IP of your machine. Then try to start the apachectl program again with the same command as before. Once you get it up and running, that's almost all there is to it.
Using the newly setup system
There's a good way to check and be sure that you have it all installed and running correctly. Find out which directory is your "enygma directory" for Apache (usually somewhere like /home/httpd or something) where your HTML files are stored. Once you find that directory, make a new file. All that needs to be in that file is:
<?php
phpinfo()
?>
This will generate a page of statistics about your system and web server and all of the things compiled in that you can view in a web browser. Just point the browser at your system and the name of the file just like it was a remote web server. If you go down the list and see a MySQL section, congratulatons! If not, go back and check and make sure that everything worked correctly. This lets you know for sure if you will be able to connect to the MySQL database that you should still have running in the background. So, that's it! Not too bad, eh? Trust me, once you've done this a few times, you'll get the whole compiling thing down pat and not have to fret too much over any errors that you have while doing it. And hopefully, you can get everything working and set up with a quick read through the documentation and possibly some help from friends.
