Pages

Mar 16, 2010

Intalling PHP (Part 4)


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.
The default settings should be adequate for most of the examples in this book,
although you can read about some amendments you might like to make in Hour 22,
"Debugging."
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 . 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
You can read more about PHP open and close tags in Hour 3, "A First Script."


0 comments: