Chapter 2.. Configuring Your Environment (Part-1)

73 views

Chances are you’re going to rely upon an existing corporate IT infrastructure or a third-party Web hosting provider for hosting your PHP-driven Web sites, alleviating you of the need to attain a deep understanding of how to build and administrate a Web server. However, as most prefer to develop applications on a local workstation or laptop, or on a dedicated development server, you’re likely going to need to know how to at least install and configure PHP and a Web server (in this case, Apache and Microsoft IIS).
     Having at least a rudimentary understanding of this process has a second benefit as well: it provides you with the opportunity to learn more about the many features of PHP and the Web server, which might not otherwise be commonly touted. This knowledge can be useful not only in terms of helping you to evaluate whether your Web environment is suited to your vision for a particular project, but also in terms of aiding you in troubleshooting problems with installing third-party software (which may arise due to a misconfigured or hobbled PHP installation). To that end, in this chapter you’ll be guided through the process of installing PHP on both the Windows and Linux platforms. Because PHP is of little use without a Web server, along the way you’ll learn how to install and configure Apache on both Windows and Linux, and Microsoft IIS 7 on Windows.
This chapter concludes with an overview of select PHP editors and IDEs (integrated development environments), and shares some insight into what you should keep in mind when choosing a Web hosting provider.
Specifically, you’ll learn how to do the following:
     • Install Apache and PHP on the Linux platform
     • Install Apache, IIS, and PHP on the Microsoft Windows platform
     • Test your installation to ensure that all of the components are properly working and troubleshoot common pitfalls
     • Configure PHP to satisfy practically every conceivable requirement
     • Choose an appropriate PHP IDE to help you write code faster and more efficiently
     • Choose a Web hosting provider suited to your specific needs

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.

Downloading Apache
These days, Apache is packaged with all mainstream Linux distributions, meaning 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). Therefore, if this applies to you, by all means skip this section and proceed to the section “Downloading PHP.” However, if you’d like to install Apache manually, follow along with this section. Because of tremendous daily download traffic, it’s suggested you choose a download location most closely situated to your geographical location (known as a mirror). At the time of this writing, the following page offered a listing of 251 mirrors located in 52 global regions: http://www.apache.org/mirrors/.
     Navigate to this page and choose a suitable mirror by clicking the appropriate link. The resulting page will consist of a list of directories representing all projects found under the Apache Software Foundation umbrella. Enter the httpd directory. This will take you to the page that includes links to the most recent Apache releases and various related projects and utilities. The distribution is available in two formats:

Source: If your target server platform is Linux, consider downloading the source code. Although there is certainly nothing wrong with using one of the convenient binary versions, the extra time invested in learning how to compile from source will provide you with greater configuration flexibility. If your target platform is Windows and you’d like to compile from source, a separate source package intended for the Win32 platform is available for download. However, note that this chapter does not discuss the Win32 source installation process. Instead, this chapter focuses on the much more commonplace (and recommended) binary installer.

Binary: Binaries are available for a number of operating systems, among them Microsoft Windows, Sun Solaris, and OS/2. You’ll find these binaries under the binaries directory.

     So which Apache version should you download? Although Apache 2 was released more than five years ago, version 1.X remains in widespread use. In fact, it seems that the majority of shared-server ISPs have yet to migrate to version 2.X. The reluctance to upgrade doesn’t have anything to do with issues regarding version 2.X, but rather is a testament to the amazing stability and power of version 1.X. For standard use, the external differences between the two versions are practically undetectable; therefore, consider going with Apache 2 to take advantage of its enhanced stability. In fact, if you plan to run Apache on Windows for either development or deployment purposes, it is recommended that you choose version 2 because it is a complete rewrite of the previous Windows distribution and is significantly more stable than its predecessor.

Downloading PHP
Although PHP comes bundled with most Linux distributions nowadays, you should download the latest stable version from the PHP Web site. To decrease download time, choose from the approximately 100 mirrors residing in more than 50 countries, a list of which is available here: http://www.php.net/mirrors.php. Once you’ve chosen the closest mirror, navigate to the downloads page and choose one of the available distributions:

Source: If Linux is your target server platform, or if you plan to compile from source for the Windows platform, choose this distribution format. Building from source on Windows isn’t recommended and isn’t discussed in this book. Unless your situation warrants very special circumstances, the prebuilt Windows binary will suit your needs just fine. This distribution is compressed in Bzip2 and Gzip formats. Keep in mind that the contents are identical; the different compression formats are just there for your convenience.

Windows zip package: If you plan to use PHP in conjunction with Apache on Windows, you should download this distribution because it’s the focus of the
later installation instructions.

Windows installer: This version offers a convenient Windows installer interface for installing and configuring PHP, and support for automatically configuring the IIS, PWS, and Xitami servers. Although you could use this version in conjunction with Apache, it is not recommended. Instead, use the Windows zip package version. Further, if you’re interested in configuring PHP to run with IIS, see the later section titled “Installing IIS and PHP on Windows.” A recent collaboration between Microsoft and PHP product and services leader Zend Technologies Ltd. has resulted in a greatly improved process that is covered in that section.
If you are interested in playing with the very latest PHP development snapshots, you can download both source and binary versions at http://snaps.php.net/. Keep in mind that some of the versions made available via this Web site are not intended
for use with live Web sites.

Obtaining 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 online via http://httpd.apache.org/ and http://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 nine languages (Brazilian Portuguese, Chinese, Dutch, English, German, Japanese, Russian, Spanish, and Turkish). 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 Web site: 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.
Should you need to upgrade your local version or retrieve an alternative format, navigate to the following page and click the appropriate link:    http://www.php.net/ docs.php.

Installing Apache and PHP on Linux
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 commonplace on the vast majority of distributions available today. In addition, PHP requires both Flex  http://flex.sourceforge.net/) and Bison (http://www.gnu.org/software/bison/bison.html), while Apache requires at least Perl version 5.003. If you’ve downloaded PHP 6, you’ll also need to install the International Components for Unicode (ICU) package version 3.4 (http://icu.sourceforge.net/), although this may very well be bundled with PHP in the future. Again, all of these items are prevalent on most, if not all, modern Linux platforms.
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—/usr/src/, for example. The installation process follows:
1. Unzip and untar Apache and PHP. In the following code, the X 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:
%>make install
4. Configure, build, and install PHP (see the section “Configuring PHP at Build Time on Linux” 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 behavior. 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 nondefault location, 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.conf file is located at PACHE_INSTALL_DIR/conf/ httpd.conf.) If they don’t exist, go ahead and add them. Consider adding each alongside the other LoadModule and AddType entries, respectively:
LoadModule php6_module modules/libphp6.so
AddType application/x-httpd-php .php
Because at the time of publication PHP 6 wasn’t yet official, you should use the latest stable version of PHP 5 if you’re planning on running any production applications.
In the case of PHP 5, the lines will look like this:
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/apache2/bin/apachectl restart
Now proceed to the section “Testing Your Installation.”

Installing Apache and PHP on Windows
Whereas previous Windows-based versions of Apache weren’t optimized for the Windows platform, Apache 2 was completely rewritten to take advantage of Windows platform-specific features. Even if you don’t plan to deploy your application on Windows, it nonetheless makes for a great localized testing environment for those users who prefer it over other platforms. The installation process follows:

1. Start the Apache installer by double-clicking the apache_X.X.XX-win32-x86- no_ssl.msi icon. The Xs in this file name represent the latest stable version numbers of the distributions you downloaded in the previous section.
2. The installation process begins with a welcome screen. Take a moment to read the screen and then click Next.
3. The license agreement is displayed next. Carefully read through the license. Assuming that you agree with the license stipulations, click Next.
4. A screen containing various items pertinent to the Apache server is displayed next. Take a moment to read through this information and then click Next.
5. You will be prompted for various items pertinent to the server’s operation, including the network domain, the server name, and the administrator’s e-mail address. If you know this information, fill it in now; otherwise, just enter localhost for the first two items and put in any e-mail address for the last. You can always change this information later in the httpd.conf file. You’ll also be prompted as to whether Apache should run as a service for all users or only for the current user. If you want Apache to automatically start with the operating system, which is recommended, then choose to install Apache as a service for all users. When you’re finished, click Next.
6. You are prompted for a Setup Type: Typical or Custom. Unless there is a specific reason you don’t want the Apache documentation installed, choose Typical and click Next. Otherwise, choose Custom, click Next, and on the next screen, uncheck the Apache Documentation option.
7. You’re prompted for the Destination folder. By default, this is C:\Program Files\Apache Group. Consider changing this to C:\, which will create an installation
directory C:\apache2\. Regardless of what you choose, keep in mind that the latter is used here for the sake of convention. Click Next.
8. Click Install to complete the installation. That’s it for Apache. Next you’ll install PHP.

9. Unzip the PHP package, placing the contents into C:\php6\. You’re free to choose any installation directory you please, but avoid choosing a path that contains spaces. Regardless, the installation directory C:\php6\ will be used throughout this chapter for consistency.
10. Navigate to C:\apache2\conf and open httpd.conf for editing.
11. Add the following three lines to the httpd.conf file. Consider adding them directly below the block of LoadModule entries located in the bottom of the
Global Environment section:
LoadModule php6_module c:/php6/php6apache2.dll
AddType application/x-httpd-php .php
PHPIniDir “c:\php6″
Because at the time of publication PHP 6 wasn’t yet official, you should use the latest stable version of PHP 5 if you’re planning on running any production applications. To do so, you’ll need to make some minor changes to the previous lines, as follows:
LoadModule php5_module c:/php5/php5apache2.dll
AddType application/x-httpd-php .php
PHPIniDir “c:\php5″

12. Rename the php.ini-dist file to php.ini and save it to the C:\php6 directory. The php.ini file contains hundreds of directives that are responsible for tweaking PHP’s behavior. 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 nondefault location, 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.
13. If you’re using Windows NT, 2000, XP, or Vista, navigate to Start ➤ Settings ➤Control Panel ➤ Administrative Tools ➤ Services. If you’re running Windows 98, see the instructions provided at the conclusion of the next step.
14. Locate Apache in the list and make sure that it is started. If it is not started, highlight the label and click Start the Service, located to the left of the label. If it is started, highlight the label and click Restart the Service, so that the changes made to the httpd.conf file take effect. Next, right-click Apache and choose Properties. Ensure that the startup type is set to Automatic. If you’re still using Windows 95/98, you need to start Apache manually via the shortcut provided on the start menu.



« Chapter 1.. Introducing PHP Chapter 2.. Configuring Your Environment (Part-2) »
Posted on Saturday, February 7th, 2009 at 1:32 pm under PHP and MySQL - From Beginning to Professional | RSS 2.0 Feed

One Response to “Chapter 2.. Configuring Your Environment (Part-1)”

  1. INDEX - PHP & MySQL Says:

    [...] C# 2..Configuring Your Environment (Part-1) (Installation Prerequisites,Downloading Apache,Downloading PHP ,Installing Apache and PHP on Windows,Installing Apache and PHP on Linux,) « C# Day 1- Basics (part 7) Chapter 1 - Introducing PHP » Posted on Friday, February 6th, 2009 at 5:19 pm under INDEX | RSS 2.0 Feed Post Comment [...]


Post Comment

You must be logged in to post a comment.



ComputerEducationWorld.com All Rights Reserved © RSS | CBSE | Education Boards Of India | What is My IP?