How to Install & Configure PHP on your Computer

Before you start working with the PHP language, you must first acquire, install, and configure the PHP interpreter. PHP is available for a wide range of platforms and works in conjunction with many servers.

 

Platforms, Servers, Databases, and PHP

PHP is truly cross-platform. It runs on the Windows operating system, most versions of UNIX including Linux, and even the Macintosh. Support is provided for a range of Web servers including Apache (itself open source and cross-platform), Microsoft Internet Information Server, WebSite Pro, the iPlanet Web Server, and Microsoft's Personal Web Server. The latter is useful if you want to test your scripts offline on a Windows machine, although Apache can also be run on Windows.

 

php logo php2s Checking php installation using phpinfo() function
You can also compile PHP as a standalone application. You can then call it from the command line.


PHP is designed to integrate easily with databases. This feature is one of the factors that make the language such a good choice for building sophisticated Web applications. Many databases are directly supported, including Adabas D, InterBase, Solid, dBASE, mSQL, Sybase, Empress, MySQL, Velocis, FilePro, Oracle, UNIX dbm,
Informix, and PostgreSQL. PHP also supports ODBC.

 

Linux, Apache, and MySQL are free to download and use, and can be installed relatively easily on a PC.  You can find out more about getting Linux for your computer at <http://www.linux.org/help/beginner/distributions.html>. If you want to run Linux on a Power PC, you can find information about LinuxPPC at <http://www.linuxppc.org>.

 

MySQL, can be downloaded from <http://www.mysql.com>. There are versions for many operating systems including UNIX, Windows, and OS/2.

 

On the other hand, you can easily stick with Windows, NT, or MacOS. PHP is, after all, a cross-platform scripting language.

 

Where to get PHP

You can find PHP4 at <http://www.php.net/>. PHP4 is open source software, which means that you won't need your credit card handy when you download it.


The PHP WebSite is an excellent resource for PHP coders. The entire manual can be read online at <http://www.php.net/manual/>, complete with helpful annotations from other PHP coders. You can also download the manual in several formats.

 

Installing PHP4 for Linux and Apache

 

The process of installing PHP4 with Apache on Linux is more or less the same for any UNIX operating system. You might be able to find prebuilt versions of PHP for your system, which are simple to install. Compiling PHP, though, gives you greater control over the features built in to your binary.


Before you install you should make sure that you are logged into your system as the root user. If you are not allowed access to your system's root account, you may need to ask your system administrator to install PHP for you.


There are two ways of compiling an Apache PHP module. You can either recompile Apache, statically linking PHP into it, or you can compile PHP as a Dynamic Shared Object (DSO). If your version of Apache was compiled with DSO support, it will be capable of supporting new modules without the need for recompiling the server.

 

In order to test that Apache supports DSOs you should launch the Apache binary (httpd) with the -l argument.

 

/www/bin/httpd –l

 

You should see a list of modules. If you see

 

mod_so.c

among them, you should be able to proceed; otherwise, you may need to recompile Apache. The Apache distribution contains full instructions for this.


If you have not already done so, you will need to download the latest distribution of PHP4. Your distribution will be archived as a tar file and compressed with gzip, so you will need to unpack it:


tar -xvzf php-4.0.tar.gz


After your distribution is unpacked, you should move to the PHP4 distribution directory:


cd ../php-4.0


Within your distribution directory you will find a script called configure. This accepts arguments that will control the features that PHP will support. For this example, we will include some useful command line arguments, although you might want to specify arguments of your own.


./configure --enable-track-vars \
--with-gd \
--with-mysql \
--with-apxs=/www/bin/apxs


The path you assign to the --with-apxs argument is likely to be different on your system. It is possible that you will find apxs in the same directory as your Apache executable.


After the configure script has run, you can run the make program. You will need a C compiler on your system to run this command successfully.


make

make install

Configure Options

When we ran the configure script, we included some command-line arguments that determined the features that the PHP interpreter will include. The configure script itself gives you a list of available options. From the PHP distribution directory type the following:


./configure –help


The list produced is long, so you may want to add it to a file for reading at leisure:


./configure --help > configoptions.txt


Although the output from this command is very descriptive, we will look at a few useful options..


--enable-track-vars


This option automatically populates associative arrays with values submitted as part of GET, POST requests or provided in a cookie. It is a good idea to include this option when running configure.


--with-gd

--with-gd enables support for the GD library, which, if installed on your system, allows you to create dynamic GIF or PNG images from your scripts. You can optionally specify a path to your GD library's install directory:


--with-gd=/path/to/dir

--with-mysql


--with-mysql enables support for the MySQL database. If your system has MySQL installed in a directory other than the default location, you should specify a path:


--with-mysql=/path/to/dir

As you know, PHP provides support for other databases. some of them and the configure options you will need to use them are

 

Database  configure Option
Adabas D --with-adabas
FilePro --with-filepro
msql --with-msql
informix --with-informix
iODBC --with-iodbc
OpenLink
ODBC
--with-openlink
Oracle --with-oracle
PostgreSQL --with-pgsql
Solid --with-solid
Sybase --with-sybase
Sybase-CT --with-sybase-ct
Velocis --with-velocis
LDAP --with-ldap

Configuring Apache

After you have compiled PHP and Apache, you should check Apache's configuration file, httpd.conf, which you will find in a directory called conf in the Apache install directory. Add the following lines to this file:

 

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps


This ensures that the PHP interpreter will parse files that end with the .php extension. Any files with the .phps extension will be output as PHP source. That is, the source code will be converted to HTML and color-coded. This can be useful for debugging your scripts.


If you want to offer to your users PHP pages with extensions more familiar to them, you can choose any extension you want. You can even ensure that files with the .html extension are treated as PHP files with the following:


AddType application/x-httpd-php .html


Note that treating files with the .html extension as PHP scripts could slow down your site, because every page with this extension will be parsed by the PHP interpreter before it is served to the user.


If PHP has been preinstalled and you have no access to the Apache configuration files, you may be able to change the extensions that will determine which files will be treated as PHP executables by including an AddType directive in a file called .htaccess. After you have created this file, the directive will affect the enclosing directory, as well as any subdirectories. This technique will only work if the AllowOverride directive for the enclosing directory is set to either FileInfo or All. Although the filename .htaccess is the default for an access control file, it may have
been changed. Check the AccessFileName directive in httpd.conf to find out. Even if you don't have root access, you should be able to read the Apache configuration files.


An .htaccess file can be an excellent way of customizing your server space if you do not have access to the root account. An additional way of controlling the behavior of PHP, even as a non-root user, is the php.ini file.


php.ini


After you have compiled or installed PHP, you can still change its behavior with a file called php.ini. On UNIX systems, the default location for this file is /usr/local/lib; on a Windows system, the default location is the Windows directory. A php.ini file in the current working directory will override one in the

default location, so you can change the behavior of PHP on a per-directory basis.

 

You should find a sample php.ini file in your distribution directory, which contains factory settings. Factory settings will be used if no php.ini file is used. Directives in the php.ini file take the form of a directive and a value separated by an equals sign. Whitespace is ignored.


If PHP has been preinstalled on your system, you might want to check some of the settings in php.ini. Remember, if you are not allowed to alter this document, you can create one in your script's directory that can override the default. You can also set an environmental variable PHPRC that designates a php.ini file.


You can change your php.ini settings at any time, though if you are running PHP as an Apache module, you should restart the server for the changes to take effect.


short_open_tag


The short_open_tag directive determines whether you can begin a block of PHP code with the symbols <? and close it with ?>. If this has been disabled, you will see one of the following:


short_open_tag = Off
short_open_tag = False
short_open_tag = No
To enable the directive you can use one of the following:
short_open_tag = On
short_open_tag = True
short_open_tag = Yes

Error Reporting Directives

 

To diagnose bugs in your code, you should enable the directive that allows error messages to be written to the browser. This is on by default:

 

display_errors = On


You can also set the level of error reporting. , you should set this to the following:


error_reporting = E_ALL & ~ E_NOTICE


This will report all errors but not notices that warn about potential problems with your code. Notices can interfere with some PHP techniques. This setting is the default.

 

Variable Directives

PHP makes certain variables available to you as a result of a GET request, a POST request, or a cookie. You can influence this in the php.ini file.


The track_vars directive creates associative arrays containing elements generated as a result of an HTTP request. This is allowed by default:


track_vars = On


The register_globals directive determines whether values resulting from an HTTP request should be made available as global variables.

 

register_globals = On

 

The configuration in PHP provides flexibility of choosing the configuration according to the needs of the user. Put your email in the subscription boxand subscribe to us for more tutorials on PHP..

Share this post
  • Share to Facebook
  • Share to Twitter
  • Share to Google+
  • Share to Stumble Upon
  • Share to Evernote
  • Share to Blogger
  • Share to Email
  • Share to Yahoo Messenger
  • More...
 
Posts RSSComments RSSBack to top
© 2013 Updated Tech News Results and Reviews