General PHP/Apache Installation

Alexej Kubarev

New member
Before you start, Please not that the information bellow might be inacurate and will rewuire some brain. The ways everything is done may and will vary depending on a operating system and version of the packages..

Downloading PHP/Apache
Before you proceed, I recommend that you take some time to download, install, and configure PHP and a Web server on your machine. Although PHP is compatible with a wide variety of Web servers, I'll assume that you will be using Apache, partly because it is currently the Web's most popular Web server and partly because it is the one most widely used with PHP. Regardless, the general installation process will not differ widely between Web servers.

You can download the PHP distribution from the official PHP site or from one of its many worldwide mirror sites. Go to http://www.php.net for the most recently updated mirror list. From here, you can download PHP in one of two formats:
· WIN32 Binary
· Source code
The Win32 binary is for Windows 95/98/NT/2000 users. While it is also possible to compile the source code on the Windows platform, for the large majority of users this won't be necessary. However, if you insist on doing so (incidentally, a process that is not discussed here), you'll need a recent Visual C++ compiler for doing so.

For non-Windows users, you'll need to build the source code. While many beginners may shudder at this thought, it is actually a rather simple process, as you'll soon learn. For those of you interested to know whether or not PHP is offered in RPM (RedHat Package Manager) distribution format; it is, although these RPMs are not available via the official PHP site. Check the discussion groups (some of which are listed at the end of this chapter) for more information regarding distribution locations and instructions.

Proceed to http://www.php.net and download the distribution that best suits your needs. Download times will vary with your connection type and speed. Additionally, the documentation is available for download. I strongly recommend downloading the most recent version.

Tip PHP 4.3.10 and 5.0.3 are the current stable versions. Of course, this version number is due to change along with the continued development of the PHP package. I recommend always down-loading the most recent stable version of the product.


If you haven't yet installed the Apache server, you will want to download the latest stable version of that as well. These packages are at
http://httpd.apache.org/download.cgi , which contains directories for a plethora of operating systems. Download the one that is specific to your needs. I will concentrate on the Apache server. Regardless of the Web server you intend to use, I strongly recommend reading through the configuration sections to gain some insight into the generalized configuration issues that you may encounter.

Installation of new software can sometimes prove to be a daunting process for newcomers. However, the PHP developers have taken extra steps to make PHP installation relatively easy. The following sections highlight the steps you should take to install and configure PHP on both the non-Windows and the Win32 platforms.

Installation and Configuration
At this point, I'll assume that you have successfully downloaded PHP and Apache. The next step is deciding how you would like to install the distribution.For non-Windows machines, there three different ways to do so: CGI binary, static Apache module, and the dynamic Apache module. As a non-Windows user, chances are you will not want to build PHP as a CGI binary. Furthermore, there are several advantages to building PHP as a server module, therefore I'll concentrate solely on building PHP both as a static and a dynamic module. As it relates to installation, the main difference between the two is that any subsequent changes to the PHP static module will require the recompilation of both Apache and PHP, while changes to the PHP dynamic module only require the subsequent recompilation of just PHP and not the server. For Windows machines, PHP can be installed as either a CGI binary or as a static Apache module. In this case, I'll concentrate upon the CGI binary, since a Windows-user might be more prone to use a Web server other than Apache, like Microsoft's Internet Information Server or Microsoft's Personal Web Server. The CGI version can easily be integrated into these servers. Although I illustrate the PHP/Apache Windows installation process, this process is very similar to that which would be used for the above-mentioned Web servers as well.

You might also need MySQL Database Server. It can be downloaded at http://www.mysql.com How to install it is described here:
http://www.php-forum.com/p/viewtopic.php?t=5507

To be Continued (need a break from typing!)
 
So! Here is a part 2!
--------------------------

Non-Windows
Regardless of the installation variation you choose, you'll need to begin by
decompressing the distributions. This is accomplished in two easy steps:
1. Unzip the packages. Once done, you'll see that the files will be left with *.tar extensions:
2. gunzip apache_x.x.x.tar.gz
3. gunzip php-x.x.x.tar.gz
4. Untar the packages. This will unarchive the distributions:
5. tar -zxvf apache_x.x.x.tar
6. tar -zxvf php-x.x.x.tar

The installation procedure will pick up from this point.

Apache Module
Installing PHP as an Apache module is rather simple. I'll take you through each step here:
1. Change location to the Apache directory:

cd apache_x.x.x

2. Configure Apache. You can use any path you like. Keep in mind that a slash does not follow the pathname:

./configure -prefix=[path]

3. Change the location to the PHP directory and configure, build, and install the distribution. The option with-config-file-path specifies the directory that will contain PHP's configuration file. Generally, this path is set to be /usr/local/lib, but you can set it to be anything you wish:

./configure -with-apache=../apache_x.x.x -with-config-file-path=[config-path]
make
make install

4. Change back to the Apache directory. Now you will reconfigure, build, and install Apache.

The other-configuration-options option refers to any special configuration options that you would like to pass along to the Apache Web server. This is beyond the scope of this post. I suggest checking out the Apache documentation for a complete explanation of these options:

5. ./configure -activate-module=src/modules/php4/libphp4.a
6. -other-configuration-options
7. make
8. make install
9. The final step involves modifying Apache's httpd.conf file. Some of these
modifications relate specifically to Apache, while others are necessary to
ensure that PHP scripts can be recognized and sent to the Web server.

First, locate the line that reads:
10. ServerName new.host.name

Change this line to read:
ServerName localhost

Next, locate the following two lines (if they do not exist: add them):
#AddType application/x-httpd-php .php
#AddType application/x-httpd-php-source .phps

These lines need to be uncommented in order for PHP-enabled files to work correctly on the server. To uncomment these lines, simply remove the pound symbol (#) from the beginning of each line. Save the file and move up one directory. Start the Apache server using the following command:

./bin/apachectl start

Voilà! PHP and Apache are now ready for use. For testing purposes, insert the following code into a file and save the file as phpinfo.php to the Apache's document root directory. This is the directory called htdocs (by default), located in the Apache installation directory.

Code:
<?php
php_info();
?>
Open this file up in a browser on the server. You should see a lengthy list of information regarding PHP's configuration. Congratulations, you've successfully installed PHP as an Apache Module.

Dynamic Apache Module
The Dynamic Module is useful because it allows you to upgrade your PHP distribution without having to recompile the Web server as well. Apache considers it just another one of its many modules, like ModuleRewrite or ModuleSpelling. This idea becomes particularly useful when you want to add some kind of support to PHP later, encryption, for example. All you have to do is reconfigure/compile PHP in accordance with the encryption support, and you can immediately begin using it in your Web applications. Here is the installation process:

1. Change location to the Apache directory:
2. cd apache_x.x.x
3. Configure Apache. You can use any path you like. Keep in mind that a slash does not follow the pathname. The -other-configuration-options option refers to any special configuration options that you would like to pass along to the Apache Web server. I suggest checking out the Apache documentation for a complete explanation of these options:

4. ./configure -prefix=[path] -enable-module=so
-other-configuration-options
5. Build the Apache server. After typing make, you will see a bunch of
messages scroll by. This is normal.
6. make
7. Install the Apache server. After you type make install, another bunch of
messages will scroll by. Again, this is normal. Once this has finished, you'll
see a message stating that you have successfully installed the server.
8. make install
9. Assuming no errors occurred, you're ready to modify Apache's "httpd.conf" file. This file is located in the conf directory in the path that you designated in step 4. Open this file in your favorite text editor. Locate the following line:

10. ServerName new.host.name
Modify this line to read:
ServerName localhost

11. Change location to the directory in which you downloaded PHP. Then,
configure, make, and install PHP. You will need to specify the path irectory
pointing to the apxs file. This file can be found in the bin directory of the path you designated in step 4.

12. ./configure -with-apxs=[path/to/apxs]
13. make
14. make install
15. Reopen Apache's httpd.conf file for another modification. In order for incoming requests for PHP-enabled files to be properly parsed, the file extension must coincide with the one as specified in the Apache server's configuration file, httpd.conf. This file contains a number of options, which can be modified at the administrator's discretion; a few of these options relate directly to PHP. Open the httpd.conf file in your favorite text editor.

Towards the end of the file are two lines similar to the following (if they do not exist: add them):
16. #AddType application/x-httpd-php .php .php
17. #AddType application/x-httpd-php-source .phps
18. You must uncomment these in order for PHP-enabled files to work correctly on the server. To uncomment these lines, simply remove the pound symbol (#) from the beginning of each line.
19. Save the file and move up one directory (to cd).

Start the Apache server using the following command:
20. ./bin/apachectl start

PHP and Apache are now ready for use.

For testing purposes, insert the following code into a file and save the file as phpinfo.php to the Apache's document root directory. This is the directory called htdocs(as i already said, by default), located in the Apache installation directory.

Code:
<?php
php_info();
?>

Open this file up in a browser on the server. You should see a lengthy list of information regarding PHP's configuration. Congratulations, you've successfully installed the Dynamic Apache Module.

----
End of part 2.. (COFFE BREAK!)
 
Installation on Windows 95/98/NT
If you have installed an application on the Windows operating system, you have probably found it to be very easy. Click a few buttons, agree to a few statements, and the application is installed. And so is the case with the installation of Apache and PHP on a Windows machine.

1. Double-click the Apache executable to begin the installation. You will be
greeted with an installation wizard. Read attentively and accept the licensing agreement.
2. The wizard will suggest a default installation directory (C:\Program Files\Apache Group\Apache2). This is fine, but you may want to shorten it to just C:\Apache\. However, it's up to you.
3. Next you will be prompted for the installation type. Just pick Typical. After you make your choice, the installation process is carried out.

4. Attempt to start Apache to ensure that everything is working. At this point you need to make the differentiation as to the type of version of apache you are running. Apache2 has an Apache Monitor that is used to monitor Apache services.
5. Finally, go to a browser installed on the server and enter http://localhost/.
You should see a default page stating that the installation has been carried
out correctly.
6. Now it's time to install PHP. Change the directory to wherever you downloaded the PHP package. Extract it to the directory of your choice usingan unzipping application.
8. Go to that directory and look for a file entitled "php.ini-dist". Rename this file to php.ini and place it in the C:\Windows\ directory.
9. Go back to the PHP directory. Look for two more files, php4ts.dll or php5ts.dll. Place these files in the C:\Windows\ directory.
10. Return to the Apache http.conf file, again opening it up in a text editor. There are a few modifications that you need to make:

Then search for "AddType". You will need to add the following two lines:
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

Then Go to LoadModule and add the following:
LoadModule php4_module "C:\PHP\sapi\php4apache2.dll"
or
LoadModule php4_module "C:\PHP\php5apache2.dll"
Depending on your installation path and PHP version

11. PHP and Apache are now ready for use.

For testing purposes, insert the following code into a file and save the file as "phpinfo.php" to the Apache's document root directory. This is the directory called htdocs located in whatever directory you specified in step 4.
Code:
<?
php_info();
?>

Caution Although successfully completing the steps outlined above does make it possible for the Web server/PHP configuration to be used for testing purposes, it does not imply that your Web server is accessible via the World Wide Web. Check out the official Apache site (http://www.apache.org) for information regarding this matter. Furthermore, although the preceding steps suffice to get the PHP package up and running, you will probably be interested in modifying PHP's configuration to best suit your needs.
 
PHP Configuration
Although PHP will correctly run given its default configuration setting, you can make quite a few modifications to fine-tune the installation to your needs. The php.ini file, copied by default into the /usr/local/lib/ (or c:\Windows) directory during the installation process, contains all of these configuration settings.
Regardless of the platform and Web server used in conjunction with PHP, the php.ini file will contain the same default set of parameters, from which several important characteristics of the PHP installation can be administered. This file contains all of the characteristics relevant to how your installation will act when PHP scripts are executed. The PHP engine reads the php.ini file when PHP starts up.

General Configuration Directives
Reiterating all of the configuration directives is beyond the scope of this book, but there are several directives worth mentioning, as most the developers may find them particularly useful. I'll mention other directives as appropriate in subsequent chapters.

short_open_tag [on | off]

The short_open_tag [on | off] configuration directive determines the use of the short PHP escape tags <?… ?>, in addition to the default tags.

asp_tags [on | off]
The asp_tags [on | off] configuration directive determines the use of ASP style tags in addition to the default tags. ASP style tags are those that enclose PHP code as follows:
Code:
<%
print "This is PHP code.";
%>

precision [integer]

The precision [integer] configuration directive sets the number of significant digits displayed in floating point numbers.

safe_mode [on | off]
Turning on safe mode is a particularly good idea if you have several users on your system. Essentially, turning on safe mode eliminates the possibility that a user can use a PHP script to gain access to another file on the system, for example, the passwd file on a Linux machine. Safe_mode works solely on the CGI version of PHP.

max_execution_time [integer]

The max_execution_time [integer] configuration directive determines the
maximum number of seconds that a given PHP script may execute. This prevents runaway scripts from eating up valuable system resources.

display_errors [on | off]

The display_errors [on | off] configuration directive display the errors in the browser.

log_errors [on | off]

The log_errors configuration directive determines whether or not errors are logged to a file. If log_errors is turned on, the directive error_log designates which file the errors are logged to.

error_log [filename]

If log_errors is turned on, error_log designates the filename to which all errorsshould be logged.

magic_quotes_gpc [on | off]
When magic_quotes_gpc is activated, all special characters contained in user or database data will automatically be escaped with the necessary backslash. By the way, "gpc" stands for "get/post/cookie".

Personally, I find it more efficient to keep magic_quotes_gpc turned off and to escape the special characters explicitly. Regardless of the way you ultimately decide to do it, there can be no compromise or your data may be corrupted. If magic_quotes_gpc is "on", then never physically escape special characters with a backslash; otherwise, make it a habit to always do so.

register_globals [on | off]
When register_globals in "on" your script will be injected with a post and get varibles and you will be able to use them by simply calling their name. If a script is not well thought through: this will be a danberouse security hole. Therefore its recommended to keep them "Off". You will have to use $_POST['name'] to get post variables and $_GET['name'] to get url-varibles, $_SERVER for server varibles, $_SESSION $_COOKIES for session and cookie varibles respectivly..

-----------------
Now if you excuse me i will need a rest! :)
 
i see that the order of installation is apache first, then Php. is there a prerequisite to installing apache? should i enable WinxXP IIS first?
 
Damn, i just wish that people would NOTICE this post sometimes :)
As i see there are people who are asking about how to do that while everything is explined here..
 
I have found this tutorial very helpful. Much better than Janet Valades' site for PHP and SQL...
 
Re part3:
8. ... Rename this file to php.ini and place it in the C:\Windows\ directory.
9. Go back to the PHP directory. Look for two more files, php4ts.dll or php5ts.dll. Place these files in the C:\Windows\ directory.

For this step it is usually better to place them in the apache/bin directory, as they get loaded just the same and are easyier to find when they need changing / editting.
 
Hi inorder to install PHP/APACHE we need to visit their official websites..and can be downloaded for free...
 
What a great tutorial! This will help everyone who wants to get started. Thanks for writing it.
 
I noticed the original post was from 2005. Are these instructions still current?
 
For the latest about Apache Installation, please visit the Apache website.
 
I've created a tutorial, where I talk about installing the Apache + PHP + MySQL system, using the latest versions of each, in the Windows environment.
Whoever is interested, I will soon say that it is a non-traditional installation, where each element is installed individually. None of them is installed as a service, so it does not occupy memory space when it is not running.

This can be seen at:

http://usr.ed48.com/vc14/en/
 
Hey, what's up!
I need some help with PHP7 configuration on windows...

My Apache is working fine!

8. Go to that directory and look for a file entitled "php.ini-dist". Rename this file to php.ini and place it in the C:\Windows\ directory.

----------
I didn't find the file "php.ini-dist", then I renamed "php.ini-develpment" file for php.ini and placed it in the C:\Windows\ directory.
----------

In my case I placed php7ts.dll file in the C:\Windows\ directory, and made the modifications in Apache's http.conf file as you said...

Then search for "AddType". You will need to add the following two lines:
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

In my case: LoadModule php7_module "C:\PHP\php7apache2_4.dll"


But my PHP and Apache was not now ready for use after all those changes....
 
It looks like you've stumbled upon an old tutorial (January 2005).

Sorry, I don't (read as won't) use windoze, but I can offer two options (more exist, but involve getting deep into the os and will require a new list of expletives) :

1)
Try to un-install it and then install it using wamp or xammp. Have a really good look for un-installing instructions as files end up getting loaded all over the place and the un-installer (windoesn't) daren't delete a lot of files just in-case it's needed by something else - leading to previous settings being applied.

2)
Install a linux distribution either by the side of your windoze or maybe as a VM, or better still (IMO) just overwrite windoze with it. Ubuntu, Mint, Xubuntu ... there are many out there but those are three of the easiest to get the hang of, Mint might be the most familiar if you are used to the doze. Disclaimer (my opinion) over writing windus will remove it from your system, you do so of your own accord - I call it freedom, others may disagree, make your own mind up. Installing Linux will give you an environment similar to many (if not most) hosting providers and should lead to an easier transfer from testing to live.
 
Back
Top