PHP is a popular server-side HTML-embedded scripting language. PHP can collect form data, generate dynamic page content and process cookies. It supports a wide range of databases including mSQL, MySQL, MS-SQL, ODBC, Oracle, and PostgreSQL. PHP also supports a wide range of protocols including IMAP, SNMP, NNTP, and POP3. PHP borrows from the best of the Perl and C worlds, and has hundreds of built-in functions to simplify most common tasks.
So the paragraph above didn't make any sense, right? Ok, here is the human-readable version: PHP is an extremely powerful scripting language. It sets you free from almost all nightmarish low-level programming tasks, and allows you to concentrate on the real job. You don't need to worry about all those technical details like how to process form data and cookies. PHP automatically handles those for you. There are no troublesome pointers that cause all sort of problems either. You can store almost all your data in incredibly flexible arrays, and read it without any hassle. There are hundreds of built-in functions for most basic and some advanced tasks. So if you are struggling with a seemingly trivial problem chances are high that there is already a built-in function that solves it automatically for you. I recommend the user annotated version of the PHP manual (see section 2.6) if you are stuck or just looking for the right function.
If you want to install PHP under Windows, you can download the latest version directly from Wow Web Designs. If you are going to install it under anything other than Windows you must download the source code at http://www.php.net/downloads.php. Then you will be able to compile PHP on your system. I will explain the installation process step by step in the next section.
For Windows
Extract the Zip file to a folder of your choice like C:\Program Files\PHP. That's all. Skip to 2.4 to learn how to configure it.
For Unix (including Linux)
First of all, make sure that Apache is installed on your system. Because PHP needs Apache to run.
Download PHP in a directory of your choice, if you already didn't. The command bellow will download it for you where x.x is the minor version number (e.g. 0.5). You can of course download it with your web browser too.
Assuming that the PHP archive is in the current directory decompress it with
gunzip -c php-4.x.x.tar.gz | tar -xvf -
This will create a directory named php-4.x.x in the current directory. Change to it by typing
cd php-4.x.x
If you want to install PHP with gd support (a graphics library that lets you generate PNG and JPEG files on-the-fly -- perfect for creating dynamic charts), you must download gd, and install it on your system first. Installation of gd is straightforward (decompress it, change to its directory, run make and make install). Once gd is installed you can compile PHP with the --with-gd option. For some reason, the PHP configuration program may complain of not finding the gd library file (libgd.a) even if it was told the full path. So, it's best to copy the file to your PHP installation directory first.
Run the configuration program with the most common options. This will configure PHP for to be installed to the default location (/usr/local/lib/php). The --with-mysql option will activate the built-in MySQL support. PHP needs to know the location of the Apache Extension Tool (apxs) in order to install itself as module of Apache, and we tell it with the --with-apxs option. apxs' full path is normally /usr/local/apache/bin/apxs, but if you installed Apache to some place else you must change it accordingly. For example the value I used for --with-apxs when I was installing PHP was /var/lib/apache/bin/apxs because Apache had been installed in /var/lib/apache on my system.
After compiling ends, copy PHP to its location by typing
make install
Congratulations! The installation is complete however there is one last thing to do: Copy php.ini-dist from the installation directory to /usr/local/lib, and change the file name to php.ini. This will be the configuration file for PHP.
The first thing you should do is to edit the Apache configuration file (httpd.conf) because PHP needs Apache to run. The configuration file is found in the conf directory of Apache. The path is normally C:\Program Files\Apache Group\Apache\conf under Windows, and /usr/local/apache/conf under Unix.
You only need to add the following lines, and restart your server (Windows: either restart Windows or enter C:\Program Files\Apache Group\Apache\apache -k restart from Start Menu > Run. Unix: run /usr/local/apache/bin/apachectl restart).
ScriptAlias /php/ "c:/program files/php/" (for Windows only - change path accordingly) Action application/x-httpd-php "/php/php.exe" (for Windows only) AddType application/x-httpd-php .php
Now, it's time to test whether PHP is running correctly. Create a file in the directory where you serve HTML documents (remember the DocumentRoot configuration directive of Apache?) that has the following line in it:
<?php phpinfo() ?>
Assuming that you save it with the name test.php to the root directory of your web site, you should see a long web page like this when you visit the URL: localhost/test.php. If you see nothing or get an error then something went wrong.
You should see a web page like this when you visit localhost/test.php.
You can download and install the free Zend Optimizer from the Zend web site. You need to create an account there first though. Zend Optimizer is a small download and comes already compiled.
"The Zend Optimizer goes over the intermediate code generated by the standard Zend run-time compiler located in the Zend Engine, and then optimizes it for faster execution" --excerpt from the official Zend Optimizer web page
For Unix (including Linux)
Decompress the archive (yes the file has an incredibly long name, and the name may change depending on the type and version of the file you downloaded from Zend):
gunzip -c ZendOptimizer-1\[1\].0.0-PHP_4.0.4-Linux_glibc21-i386.tar.gz | tar -xvf -
Change to the ZendOptimizer directory:
cd ZendOptimizer-1.0.0-PHP_4.0.4-Linux_glibc21-i386
Create a directory for ZendOptimizer in /usr/local/lib (of course you are free to put it anywhere you want) by typing
mkdir /usr/local/lib/ZendOptimizer
Copy the file ZendOptimer.so to the directory you have just created:
cp ZendOptimizer.so /usr/local/lib/ZendOptimizer
Add the following lines to your php.ini file, and restart Apache.
To see whether ZendOptimizer is really running, create a test PHP file that has the line in it, and access it with your browser. If you see the ZendOptimizer line on the left of the "Powered by Zend" logo, then it is running.
If you see the ZendOptimizer line then it is running.
Fantastic site - just what I need to get PHP-Apache-Linux-mySQL up and running. I am an amateur programmer from India, and I have developed both internet and intranet sites on the Windows platform. Now, out of curiosity and necessity, I am changing to Linux. Here's wishing myself all the best and hey, you too. Keep up the good work !!!!
I've searched TONS of web pages over the past 4 days looking for information on how to set up my server after messing it up. The information contained in this article helped me get my web pages back online.
The only thing I wish it did more of was went into greater detail on the httpd.conf file settings such as creating additional virtual hosts.
good article. But is it true that it is only possible to run on apache and maybe not personal web server? If it is possible, I hope you can give me the correct way to do it.
Great!!! thank u very much, i spent more than one day looking for a tutorial like this one, nothing was working! finally i got it!!!, im going to add a link to u on my website thanx again! from Tepatitlan Jalisco Mexico, your friend Gera!
Wow. What a great article. Previously I was running VMWare on top of Win2k so I can run apache+php+mysql. That was a pain in the ass and vmware decided to fail me this morning. I just couldn't get it running again. I much prefer running everything natively like this.
This article made all the configuring a breeze, not to mention the binaries you guys made available for us.