4. PHP Environment Setup
In
order to develop and run PHP Web pages, three vital components need to be
installed on your computer system.
Web
Server - PHP will work with virtually all Web Server
software, including Microsoft's Internet Information Server (IIS) but then most
often used is freely available Apache Server. Download Apache for free here:
http://httpd.apache.org/download.cgi
Database
- PHP will work with virtually all database software, including Oracle and
Sybase but most commonly used is freely available MySQL database. Download
MySQL for free here: http://www.mysql.com/downloads/index.html
PHP
Parser - In order to process PHP script instructions, a
parser must be installed to generate HTML output that can be sent to the Web
Browser. This tutorial will guide you how to install PHP parser on your
computer.
1. 4.1. PHP
Parser Installation
This section will guide you to install and configure
PHP over the following four platforms:
· - PHP Installation on Linux or Unix with
Apache
· - PHP Installation on Mac OS X with Apache
· - PHP Installation on Windows NT/2000/XP
with IIS
· - PHP Installation on Windows NT/2000/XP
with Apache
1. 4.2. PHP
Installation on Linux or Unix with Apache
If you plan to install PHP on Linux
or any other variant of Unix, then here is the list of prerequisites:
·
The PHP source distribution
http://www.php.net/downloads.php
The latest Apache source distribution
http://httpd.apache.org/download.cgi
·
A working PHP-supported database, if you
plan to use one ( For example MySQL, Oracle etc. )
·
Any other supported software to which PHP
must connect (mail server, BCMath package, JDK, and so forth)
·
An ANSI C compiler
·
Gnu make utility - you can freely download
it at
http://www.gnu.org/software/make
Now here are the steps to install
Apache and PHP5 on your Linux or Unix machine. If your
PHP or Apache versions are different,
then please take care accordingly.
· If you haven't already done so, unzip and untar your Apache source distribution. Unless you have a reason to do otherwise, /usr/local is the standard place.
1. 4.3. PHP Installation on Mac OS X with Apache
Mac users have the choice of either a binary or a source installation. In fact, your OS X probably came with Apache and PHP preinstalled. This is likely to be quite an old build,and it probably lacks many of the less common extensions.
However, if all you want is a quick Apache + PHP + MySQL/PostgreSQL setup on your laptop, this is certainly the easiest way to fly. All you need to do is edit your Apache configuration file and turn on the Web server.
So just follow the steps given below:
·
Open the Apache config file in a text
editor as root.
· Edit the file. Uncomment the following lines:
1. 4.4. PHP
Installation on Windows NT/2000/XP with IIS
The
Windows server installation of PHP running IIS is much simpler than on Unix,
since it
involves
a precompiled binary rather than a source build.
If
you plan to install PHP over Windows, then here is the list of prerequisites:
·
A working PHP-supported Web server. Under
previous versions of PHP, IIS/PWS was the easiest choice because a module
version of PHP was available for it; but PHP now has added a much wider
selection of modules for Windows.
·
A correctly installed PHP-supported
database like MySQL or Oracle etc. (if you plan to use one)
·
The PHP Windows binary distribution
(download it atwww.php.net/downloads.php)
·
A utility to unzip files (search
http://download.cnet.com for PC file compression utilities)
Now
here are the steps to install Apache and PHP5 on your Windows machine. If your
PHP
version
is different, then please take care accordingly.
·
Extract the binary archive using your
unzip utility; C:\PHP is a common location.
·
Copy some .dll files from your PHP
directory to your systems directory (usually C:\Winnt\System32). You need
php5ts.dll for every case. You will also probably need to copy the file
corresponding to your Web server module -C:\PHP\Sapi\php5isapi.dll. It's
possible you will also need others from the dlls subfolder - but start with the
two mentioned above and add more if you need them.
·
Copy either php.ini-dist or
php.ini-recommended (preferably the latter) to your Windows directory (C:\Winnt
or C:\Winnt40), and rename it php.ini. Open this file in a text editor (for
example, Notepad). Edit this file to get configuration directives; We highly
recommend new users set error reporting to E_ALL on their development machines
at this point. For now, the most important thing is the doc_root directive
under the Paths and Directories section. make sure this matches your IIS
Inetpub folder (or wherever you plan to serve out of).
·
Stop and restart the WWW service. Go to
the Start menu -> Settings -> Control Panel -> Services. Scroll down
the list to IIS Admin Service. Select it and click Stop. After it stops, select
World Wide Web Publishing Service and click Start. Stopping and restarting the
service from within Internet Service Manager will not suffice. Since this is
Windows, you may also wish to reboot.
·
Open a text editor. Type: <?php
phpinfo(); ?>. Save this file in your Web server's document root as
info.php.
·
Start any Web browser and browse the
file.you must always use an HTTP request (http://www.testdomain.com/info.php or
http://localhost/info.php or http://127.0.0.1/info.php) rather than a filename
(/home/httpd/info.php) for the file to be parsed correctly
You should see a long
table of information about your new PHP installation message
Congratulations!
2. 4.5. PHP
Installation on WindowsNT/2000/XP with Apache
To install Apache with
PHP 5 on Windows follow the following steps. If your PHP and Apache versions
are different, then please take care accordingly.
·
Download Apache server from
www.apache.org/dist/httpd/binaries/win32. You want the current stable release
version with the no_src.msi extension. Double-click the installer file to
install; C:\Program Files is a common location. The installer will also ask you
whether you want to run Apache as a service or from the command line or DOS
prompt. We recommend you do not install as a service, as this may cause
problems with startup.
·
Extract the PHP binary archive using your
unzip utility; C:\PHP is a common location.
·
Copy some .dll files from your PHP
directory to your system directory (usually C:\Windows). You need php5ts.dll
for every case. You will also probably need to copy the file corresponding to
your Web server module -C:\PHP\Sapi\php5apache.dll. to your Apache modules
directory. It's possible that you will also need others from the dlls
subfolder, but start with the two mentioned previously and add more if you need
them.
·
Copy either php.ini-dist or
php.ini-recommended (preferably the latter) to your Windows directory, and
rename it php.ini. Open this file in a text editor (for example, Notepad). Edit
this file to get configuration directives; At this point, we highly recommend
that new users set error reporting to E_ALL on their development machines
· Tell your Apache server where you want to serve files from and what extension(s
you want to identify PHP files (.php is the standard, but you can use .html, .phtml, or whatever you want). Go to your HTTP configuration files (C:\Program Files\Apache Group\Apache\conf or whatever your path is), and open httpd.conf with a text editor. Search for the word DocumentRoot (which should appear twice) and change both paths to the directory you want to serve files out of. (The default is C:\Program Files\Apache Group\Apache\htdocs.). Add at least one PHP extension directive as shown in the first line of the following code:1. 4.6. Apache
Configuration for PHP
Apache uses httpd.conf file for global settings, and
the .htaccess file for per-directory access settings. Older versions of Apache
split up httpd.conf into three files (access.conf, httpd.conf, and srm.conf), and
some users still prefer this arrangement.
Apache server has a very powerful, but slightly
complex, configuration system of its own. Learn more about it at the Apache Web
site: www.apache.org
The following section describes settings in httpd.conf
that affect PHP directly and cannot be set elsewhere. If you have standard
installation, then httpd.conf will be found at /etc/httpd/conf:
Timeout
This value sets the default number of seconds before
any HTTP request will time out. If you set PHP's max_execution_time to longer
than this value, PHP will keep grinding away but the user may see a 404 error.
In safe mode, this value will be ignored; you must use the timeout value in
php.ini instead
Document Root
1. 4.7. PHP.INI
file Configuration
The
PHP configuration file, php.ini, is the final and most immediate way to affect
PHP's functionality. The php.ini file is read each time PHP is initialized.in
other words, whenever httpd is restarted for the module version or with each
script execution for the CGI version. If your change isn’t showing up, remember
to stop and restart httpd. If it still isn’t showing up, use phpinfo() to check
the path to php.ini.
0 Comments