General PHP/Apache Installation

Forum for you who has PHP installation issues

Moderators: macek, egami, gesf

User avatar
Alexej Kubarev
Site Admin
Site Admin
Posts: 2223
Joined: Fri Mar 05, 2004 7:15 am
Location: Täby, Stockholms län
Contact:

General PHP/Apache Installation

Postby Alexej Kubarev » Mon Jan 10, 2005 3:18 pm

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!)
Last edited by Alexej Kubarev on Sat Jun 25, 2005 5:08 am, edited 2 times in total.

User avatar
Alexej Kubarev
Site Admin
Site Admin
Posts: 2223
Joined: Fri Mar 05, 2004 7:15 am
Location: Täby, Stockholms län
Contact:

Part 2

Postby Alexej Kubarev » Mon Jan 10, 2005 3:31 pm

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: Select all

<?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: Select all

<?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!)

User avatar
Alexej Kubarev
Site Admin
Site Admin
Posts: 2223
Joined: Fri Mar 05, 2004 7:15 am
Location: Täby, Stockholms län
Contact:

Part 3!

Postby Alexej Kubarev » Mon Jan 10, 2005 3:46 pm

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: Select all

<?
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.

User avatar
Alexej Kubarev
Site Admin
Site Admin
Posts: 2223
Joined: Fri Mar 05, 2004 7:15 am
Location: Täby, Stockholms län
Contact:

Postby Alexej Kubarev » Mon Jan 10, 2005 3:59 pm

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: Select all

<%
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! :-)

surfthewebph
New php-forum User
New php-forum User
Posts: 5
Joined: Sat Apr 23, 2005 10:08 pm

Postby surfthewebph » Sun Apr 24, 2005 8:06 pm

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?

User avatar
Alexej Kubarev
Site Admin
Site Admin
Posts: 2223
Joined: Fri Mar 05, 2004 7:15 am
Location: Täby, Stockholms län
Contact:

Postby Alexej Kubarev » Mon Apr 25, 2005 7:53 am

NO! You should disable it...
IIS is another server software

User avatar
Alexej Kubarev
Site Admin
Site Admin
Posts: 2223
Joined: Fri Mar 05, 2004 7:15 am
Location: Täby, Stockholms län
Contact:

Postby Alexej Kubarev » Sat Jun 25, 2005 4:51 am

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..

Leviatas
New php-forum User
New php-forum User
Posts: 6
Joined: Wed Jun 20, 2007 7:55 am
Location: Durango, CO
Contact:

Postby Leviatas » Thu Jun 21, 2007 7:35 am

I have found this tutorial very helpful. Much better than Janet Valades' site for PHP and SQL...

User avatar
AeroX
New php-forum User
New php-forum User
Posts: 142
Joined: Sun May 11, 2008 1:40 am
Location: London, UK
Contact:

Re: General PHP/Apache Installation

Postby AeroX » Mon Aug 04, 2008 12:50 am

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.

raghuram
New php-forum User
New php-forum User
Posts: 6
Joined: Thu Jun 16, 2011 11:13 pm

Re: General PHP/Apache Installation

Postby raghuram » Mon Jul 25, 2011 2:18 am

Hi inorder to install PHP/APACHE we need to visit their official websites..and can be downloaded for free...

bliss
New php-forum User
New php-forum User
Posts: 24
Joined: Sun Jul 29, 2012 5:38 pm

Re: General PHP/Apache Installation

Postby bliss » Sun Jul 29, 2012 7:39 pm

What a great tutorial! This will help everyone who wants to get started. Thanks for writing it.

raphael75
New php-forum User
New php-forum User
Posts: 20
Joined: Fri Apr 06, 2012 9:54 pm

Re: General PHP/Apache Installation

Postby raphael75 » Mon Dec 17, 2012 5:03 am

I noticed the original post was from 2005. Are these instructions still current?

User avatar
anqush
New php-forum User
New php-forum User
Posts: 4
Joined: Tue Jul 16, 2013 10:59 am
Contact:

Re: General PHP/Apache Installation

Postby anqush » Thu Jul 18, 2013 10:48 am

http://letusdophp.blogspot.in/2013/06/installing-apache-and-php-on-windows.html

DOWNLOADING APACHE
If you’re running Windows and would like to use Apache, then download the latest stable Windows binary located within the binaries/win32 directory. Two binary versions are available: one containing additional SSL-related capabilities and one lacking these capabilities. These binaries are appropriately named to make clear which is which. I suggest choosing the non-SSL capable version for development purposes.

DOWNLOADING PHP
Download the latest stable version by clicking on the Downloads link located at the top of the PHP web site and then choosing from one of the available distributions:

Source: In very special circumstances, the Windows binary will suit your needs just fine. This distribution is archived in bzip2 and gzip formats. Keep in mind that the contents are identical; the different compression formats are just there for your convenience.

Windows zip package: If you plan to use PHP in conjunction with Apache on Windows, you should download this distribution because it’s the focus of the later installation instructions.

Windows installer: This version offers a convenient Windows installer interface for installing and configuring PHP, plus support for automatically configuring the IIS, PWS, and Xitami servers. Although you could use this version in conjunction with Apache, I have not had much luck using it, and instead suggest downloading the Windows binary package.

After selecting a distribution, choose the download mirror closest to your location (recommended).


INSTALLING APACHE AND PHP ON WINDOWS PLATFORM

Apache 2 was completely rewritten to take advantage of Windows platform-specific features unlike it's previous versions. The installation process follows:

1. Start the Apache installer by double-clicking the apache_X.X.XX-win32-x86-no_ssl.msi icon. The Xs in this file name represent the latest stable version numbers of the distributions you downloaded in the previous section.

2. The installation process begins with a welcome screen. Click Next. The license agreement is displayed next. Carefully read through the license(lol). Assuming that you agree with the license stipulations, click Next.

3. A screen containing various items pertinent to the Apache server is displayed next. Take your time and click Next.

4. On the next screen you will be asked to enter network domain, the server name, and the administrator’s email address. If you know this information, fill it in now; otherwise, just enter 'localhost' for the first two items and put in any e-mail address for the last. You can always change this information later in the httpd.conf file.

5. Choose Typical or custom(choose yourself, you are smart enough). Click Next.

6. Consider changing the destination folder to C:\apache for the sake of conveneince. Click Next.

7. Click Install to complete the installation.

8. Now moving on to PHP installation. Unzip it to c:\php, avoid choosing a path that contains spaces

9. Navigate to C:\apache\conf and open httpd.conf and Add the following three lines below the block of LoadModule entries located in the bottom of the Global Environment section:

LoadModule php_module c:/php/php5apache2_2.dll
AddType application/x-httpd-php .php
PHPIniDir "c:\php"

10. Rename the php.ini-dist file in c:\php to php.ini and save it to the C:\php directory (as of PHP 5.3.0, the INI files have been reorganized and renamed as php.ini-development and php.ini-production, so if you are running 5.3+ you should rename one of these as php.ini depending upon your situation).

11. Now navigate to Start | Settings | Control Panel | Administrative Tools | Services. Locate Apache in the list and make sure that it is started otherwise Start the Service. If it is started, highlight the label and click Restart the Service so that the changes made to the httpd.conf file take effect. Next, right-click Apache and choose Properties. Ensure that the startup type is set to Automatic.

TESTING YOUR INSTALLATION
The best way to verify your PHP installation is by attempting to execute a PHP script. Open a text editor and add the following lines to a new file:

Code: Select all

<?php
phpinfo();
?>


Save this file as phpinfo.php. If you’re running Apache, save it to the htdocs directory. If you’re running IIS, save the file to C:\inetpub\wwwroot. Now open a browser and access this file by entering the following URL: http://localhost/phpinfo.php

Please note that you cannot just open the script by navigating through your browser’s File | Open feature, because in doing so this script will not be passed through the web server and therefore will not be parsed.
If all goes well, you should see output similar to that shown in Figure.

http://4.bp.blogspot.com/-Y9V5PS_kJGI/UbdfleVbUbI/AAAAAAAAACg/sRHNP40ALOc/s1600/phpinfo%2528%2529.PNG
Figure. Output from PHP’s phpinfo() function

If you’re attempting to run this script on a web hosting provider’s server, and you receive an error message stating phpinfo() has been disabled for security reasons, you’ll need to create another test script. Try executing this one instead, which should produce some simple output:

Code: Select all

<?php
echo "A simple but effective PHP test!";
?>


If you are not seeing the appropriate output, it may be due to one or more of the following reasons:
If you manually configured Apache, changes to its configuration file do not take effect until Apache has been restarted. Therefore, be sure to restart Apache after adding the necessary PHP-specific lines to the httpd.conf file.
Invalid characters or incorrect statements will cause Apache’s restart attempt to fail. If Apache will not start, go back and review your changes.
Verify that any PHP-enabled file ends in the same PHP-specific extension as defined in the httpd.conf file. For example, if you've defined only .php as the recognizable extension, don’t try to embed PHP code in an .html file.
Make sure that you've delimited the PHP code within the file using the <?php and ?> constructs. Neglecting to do this will cause the code to output to the browser.
You've created a file named index.php and are trying unsuccessfully to call it as you would a default directory index file (done by just referencing a directory within the URL sans the specific file name you’d like to request, for instance http://www.example.com/about/ versus http://www.example.com/about/ index.php). However, Apache only recognizes index.html as the default directory index file. Therefore, you need to add index.php to Apache’s DirectoryIndex directive.


:offtopic:

johnj
php-forum Super User
php-forum Super User
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: General PHP/Apache Installation

Postby johnj » Tue Aug 27, 2013 5:31 am

For the latest about Apache Installation, please visit the Apache website.

joucheattarce
New php-forum User
New php-forum User
Posts: 1
Joined: Wed Jan 30, 2013 3:43 am

Re: General PHP/Apache Installation

Postby joucheattarce » Sun Sep 08, 2013 12:38 am

Без постинга


Return to “PHP Installation”

Who is online

Users browsing this forum: Yahoo [Bot] and 0 guests