Wednesday, September 14, 2016

How to install PHP and APACHE on LINUX?
               
                Installation Prerequisites
Let’s begin the installation process by downloading the necessary software. At a minimum, this will entail downloading PHP and the appropriate web server (either Apache or IIS 7, depending on your platform and preference). If your platform requires additional downloads, that information will be Provided in the appropriate section. Enjoy the reading.
                How to Download Apache?
These days, Apache is packaged with all mainstream Linux distributions. So if you’re using one of these platforms, chances are quite good you already have it installed or can easily install it through your distribution’s packaging service (e.g., by running the apt-get command on Ubuntu).
                Downloading PHP?
Like Apache, PHP is available through all Linux distributions’ package environments nowadays,
                Downloading the Documentation?
Both the Apache and PHP projects offer truly exemplary documentation, covering practically every aspect of the respective technology in lucid detail. You can view the latest respective versions at http://httpd.apache.org and www.php.net, or download a local version to your local machine and read it there.
Downloading the Apache Manual?
Each Apache distribution comes packaged with the latest versions of the documentation in XML and HTML formats and in a variety of languages. The documentation is located in the directory docs, found in the installation root directory.
Should you need to upgrade your local version, require an alternative format such as PDF or Microsoft Compiled HTML Help (CHM) files, or want to browse it online, proceed to the following website: http://httpd.apache.org/docs-project.
Downloading the PHP Manual?
The PHP documentation is available in more than 20 languages and in a variety of formats, including a single HTML page, multiple HTML pages, and CHM files. These versions are generated from DocBook-based master files, which can be retrieved from the PHP project’s CVS server should you wish to convert to another format. The documentation is located in the directory manual in the installation directory.
                How To Install Apache and PHP on Linux Plateform?
This section guides you through the process of building Apache and PHP from source, targeting the Linux platform. You need a respectable ANSI-C compiler and build system, two items that are available through all of the major distributions’ package managers. In addition, PHP requires both Flex (http://flex.sourceforge.net) and Bison (www.gnu.org/software/bison/bison.html), while Apache requires at least Perl version 5.003. Finally, you’ll need root access to the target server to complete the build process.
For the sake of convenience, before beginning the installation process, consider moving both packages to a common location such as /usr/src/. The installation process follows:
1.  Unzip and untar Apache and PHP. In the following code, represents the latest stable version numbers of the distributions you downloaded in the
Previous section:
%>gunzip httpd-2_X_XX.tar.gz
%>tar xvf httpd-2_X_XX.tar
%>gunzip php-XX.tar.gz
%>tar xvf php-XX.tar
2.  Configure and build Apache. At a minimum, you’ll want to pass the option --enable-so, which tells Apache to enable the ability to load shared modules:
%>cd httpd-2_X_XX
%>./configure --enable-so [other options]
%>make
3.  Install Apache (which you will need to do as the system super user):
%>make install
4.  Configure, build, and install PHP (see the “Configuring PHP at Build Time on
Linux” section for information regarding modifying installation defaults and
incorporating third-party extensions into PHP). In the following steps,
APACHE_INSTALL_DIR is a placeholder for the path to Apache’s installed location,
for instance /usr/local/apache2:
%>cd ../php-X_XX
%>./configure --with-apxs2=APACHE_INSTALL_DIR/bin/apxs [other options]
%>make
%>make install
5.  PHP comes bundled with a configuration file that controls many aspects of PHP’s behaviour. This file is known as php.ini, but it was originally named php.ini-dist. You need to copy this file to its appropriate location and rename it php.ini. The later section “Configuring PHP” examines php.ini’s purpose and contents in detail. Note that you can place this configuration file anywhere you please, but if you choose a nondefaultlocation, you also need to configure PHP using the --with-config-file-path option. Also note that there is another default configuration file at your disposal, php.ini-recommended. This file sets various nonstandard settings and is intended to better secure and optimize your installation, although this configuration may not be fully compatible with some of the legacy applications. Consider using this file in lieu of php.ini-dist. To use this file, execute the following command:
%>cp php.ini-recommended /usr/local/lib/php.ini
6.  Open Apache’s configuration file, known as httpd.conf, and verify that the
following lines exist. (The httpd.conffile is located at
APACHE_INSTALL_DIR/conf/httpd.conf.) If they don’t exist, go ahead and add them. Consider adding each alongside the other LoadModuleand AddType
entries, respectively:
LoadModule php5_module modules/libphp5.so
AddType application/x-httpd-php .php
Believe it or not, that’s it. Restart the Apache server with the following command:
%>/usr/local/apache/bin/apachectl restart
The Way ToTest 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:
<?php
phpinfo();
?>
Save this file as phpinfo.php. If you’re running Apache, save it to the htdocs directory. If you’re
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 next Figure. 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:
<?php
echo "A simple but effective PHP test!";
?>





If you encountered no noticeable errors during the build process but 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.conffile.
•  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 inthe same PHP-specific extension as defined in the httpd.conffile. For example, if you’ve defined only .phpas the recognizable extension, don’t try to embed PHP code in an .htmlfile.
•  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 Directory Index directive.

Configuring Way For PHP?

Although the base PHP installation is sufficient for most beginning users, chances are you’ll soon want to make adjustments to the default configuration settings and possibly experiment with some of the third-party extensions that are not built into the distribution by default. In this section you’ll learn how to tweak PHP’s behaviour and features to your specific needs.

Configuring PHP at Build Time on Linux

Building PHP as described earlier in the chapter is sufficient for getting started; however, you should keep in mind the many other build-time options that are at your disposal. You can view a complete list of configuration flags (there are more than 200) by executing the following:
%>./configure --help
To make adjustments to the build process, you just need to add one or more of these arguments to PHP’s configure command, including a value assignment if necessary. For example, suppose you want to enable PHP’s FTP functionality, a feature not enabled by default. Just modify the configuration step of the PHP build process like so:
%>./configure --with-apxs2=/usr/local/apache/bin/apxs --enable-ftp
As another example, suppose you want to enable PHP’s Bzip2 extension. Just reconfigure PHP like so:
%>./configure --with-apxs2=/usr/local/apache/bin/apxs \
>--with-bz2=[INSTALL-DIR]
One common point of confusion among beginners is to assume that simply including additional flags will automatically make this functionality available via PHP. This is not necessarily the case. Keep in mind that you also need to install the software that is ultimately responsible for enabling the extension support. In the case of the bzip2 example, you need the Java Development Kit (JDK).

Run-Time Configuration
It’s possible to change PHP’s behavior at run time on both Windows and Linux through the php.ini file. This file contains myriad configuration directives that collectively control the behavior of each product. The remainder of this chapter focuses on PHP’s most commonly used configuration directives, introducing the purpose, scope, and default value of each.

Managing PHP’s Configuration Directives
Before you delve into the specifics of each directive, this section demonstrates the various ways in which these directives can be manipulated, including through the php.ini file, Apache’s httpd.conf and .htaccessfiles, and directly through a PHP script.
The php.ini File

The PHP distribution comes with two configuration templates, php.ini-dist and php.ini-recommended (as of PHP 5.3.0 these have been renamed to php.ini-development and php.ini-production, respectively). You’ll want to rename one of these files to php.ini tweaking your installation because there are well over 200 distinct configuration parameters in this file. Although the default values go a long way toward helping you to quickly deploy PHP, you’ll probably want to make additional adjustments to PHP’s behaviour, so you’ll need to learn a bit more about php.ini and its many configuration parameters. The upcoming blog about “PHP’s Configuration Directives” presents a comprehensive introduction to many of these parameters, explaining the purpose, scope, and range of each. 

No comments:

Post a Comment