Mark Wilson I am the creator of TopXML. I am available for international and local (Australia) contracts. I am a Solution Architect/Business Analyst. I have worked in IT in several countries (NZ, Australia, South Africa, UK) building and training teams for government and very large non-governmental organizations. I am ex-Microsoft Consulting Services. I wrote the first book on Microsoft XML published in 2000 called XML Programming with VB and ASP. Most recently I have been building tools for the SEO industry. Ask me for a 37 point SEO health-checkup for your website.
First posted :
03/24/2008
Times viewed :
563
How to install PHP in different environment
Creating and running PHG Web
applications in a satisfactory way implies that you are running (or have access
to) a web server upon which server PHP is (can be) installed, and that the
installation ha been tested and runs properly. It also implies that the PHP has
been (or can be) configured to support needs of your PHP programs. There are a
couple scenarios under which these requirements can be achieved.
You are running a desktop or server machine,
operating system, and web server compatible with PHP and PHP has been
installed and configured.
You are running a desktop or server machine
connected to the internet, with access to web hosting account supported by
a web server with which PHP has been installed and configured.
Installing PHP5
with Linux and Apache
The combination of Linux,
Apache, MySQL, and PHP is probably the most common
production environment for running PHP web servers. This combination of
open-source software has been referred to by the acronym LAMP. If you run the
same combination of software, you can benefit from the experiences of many
other peoples who have used these setup.
Setting up Apache for PHP
To install apache, use RPMs or download and compile the source code. But apache
probably comes with your Linux distribution, and may already be properly
installed.
If you are using linux visually (running KDE, for example) click the httpd service to see whether it is running. If it is not,
start it, and then open your browser and enter http://localhost,
you should see a main web page.
If Apache is not already
installed and running, you can use these commands for installing it from the
terminal
lynx http://httpd.apache.org/download.cgi
gzip –d
httpd-2_0_NN.tar.gz
tar –d httpd-2_0_NN.tar
./configure –prefix=PREFIX
make
make install
vi PREFIX/conf/httpd.conf
PREFIX/bin/apachectl start
You must replace the NN with
minor version number, and PREFIX with the correct path in which you’d like to
install Apache( the default is /usr/local/apache2).
Configuring Apache to run PHP5
If PHP5 is installed as a DSO( as the example installation was), you need to check the
Apache configuration file(named httpd.conf) to make
sure it has several entries. In the Fedora installation you can find the httpd.conf file in the /etc/httpd/conf
folder. Open any text editor and let’s modify the httpd.conf
file.
First ensure that PHP is enabled on your
Apache server. Look for a lot of lines that begin with the word LoadModule. Among them you should find a line
like this
If there is not such a line,
you need to add one; or if the path is wrong, you need to correct it. Find out
whether the PHP compiled put your libphp5.so file. Open Konqueror
and choose Tools->Find File. My installation put the libphp5.so file in
/usr/lib/httpd/modules
You need this information to
tell Apache how to run PHP scripts. In the Apache configuration file httpd.conf, add the LoadModule
instruction to load PHP5, put it after any of other LoadModule
lines, using the path you just obtained:
Now that Apache know how to
load PHP5, you need to activate PHP5 in Apache. There is a section further down
the file consisting of lots of lines beginning with AddModule.
If you find a ClearModulesList line in the file, you
add the following line to the file. Although it does not matter whether you put
it, it makes sense to loacet it near other AddModule lines for easy access in the future.
AddModule mod_php5.c
The AddModule
line is not required unless you have ClearModuleList
line.
Finally, you tell apache how
to recognize a php program by its extension. Further
down the document are some directives that begin AddType.
To the end of these, add the following line
AddType application/x-httpd-php .php
This tells apache that all
files that ending with .php is PHP programs. No you are done so save the file
and restart your web server.
Install the
Apache2 Web server on Windows
The software to install is
available for download from http://www.apache.org/
What you want is their HTTP
Server project at http://httpd.apache.org/. Install the current version of
Apache web server. The current version available as of December’2004 is 2.0.52.
The default installation directory would be C:\Program Files\Apache
Group\Apache2.
To control Apache manually,
follow this chain:
Programs -> Apache HTTP
Server -> Control Apache Server
The choices for Windows 9x
include Start Apache In Console whereas choices for
Windows >= 2k usually include Start, Stop and Restart.
For Windows >= 2k, it's
likely that the Apache service will start automatically after its installation
and restart whenever you reboot the computer. For Windows 9x you have to control
it manually.
Configuring Apache
I want to make my default
web server directory would be c:\topxml_demo. So you first create the
directory. All of the Apache configuration settings are defined in the file httpd.conf in the conf subdirectory of Apache:
C:\Program Files\Apache
Group\Apache2\conf
From the programs menu you
can edit this file as follows:
Apache HTTP Server ->
Configure Apache Server -> Edit httpd.conf
(I would recommend making
.conf files one of Textpad's associated files). Edit httpd.conf and make the following changes:
Set up the mapping of the
URL http://localhost/default to C:\ topxml_demo. Go
to the end of the file and add the line:
Alias /default/ "C:/topxml_demo /"
Allow ExecCGIpriviledges as default. Search for this section.
# First, we configure the
"default" to be a very restrictive...
<Directory />
Options FollowSymLinks
AllowOverride
None
</Directory>
Change the
"Options" line to this:
Options FollowSymLinksExecCGI Indexes
Uncomment the line:
AddHandlercgi-script .cgi
Add the line
DirectoryIndex index.html index.html.varindex.cgi
To test your web server
create a test.htm file and put it in the c:\topxml_demo directory and enter the
following URL in your web browser.
I now assume that you have
already configured your Apache web server and also created your default
directory as per instructions give in the above section.
Download PHP binary or zip
installation file from http://php.net. The best
way to install is to use zip file. Unzip your PHP zip installation file into
c:\php4 or c:\php5 depending upon whether you are going to install php4 or
php5.
Go into c:\php4 or c:\php5
and copy the file php4ts.dll (this is PHP4 version) or php5ts.dll (This is PHP5
version) into the following folder:
System
Folder
Windows 98, ME, XP
c:\windows\system32
Windows 2000
c:\winnt\system32
Copy php.ini-dist to php.ini
and then make the following edits to php.ini:
Look for the magic_quotes_gpc setting ("gpc"
means for GET/POST/Cookie values).
magic_quotes_gpc = On
and turn it off by rewriting
magic_quotes_gpc = Off
Create a folder by the name "tmp" within
the "c:/php" folder. Then look for the line in the
session section:
session.save_path = /tmp and set it to the directory you just created: session.save_path = c:/php/tmp
After making these
modifications to php.ini, copy this file into the following folder:
System
Folder
Windows 98, ME, XP
c:\windows
Windows 2000
c:\winnt
Now edit the Apache2
configuration file httpd.conf in two places (you can choose this from the Apache2
menu).
Find the line DirectoryIndex which defines the root file within a directory
and add index.php to the line, making it