Tuesday, 19 November 2013

PHP 5 Configuration

As a developer so far  I have dealt with two web servers using PHP 5 on it that I would give you directives on how to setup the machine for running of your web applications. There are two web servers which I know Apache web server and Information Internet Services(IIS) web server.

Using Apache
You can start decide to start on whatever software to start installing either server or parser and Database Software preferably MySQL then configure afterwards.
  • Download right package of the web server and PHP 5 parser, that is, Apache 2(or version above) which may come in form of different packages, i.e., WAMP(Windows Apache MySQL), XAMPP(Cross-platform Apache MySQL PHP Perl) which eases your work to download in single packages. For now, we'll use AMP(Apache MySQL PHP) which you will install each in a single package, i.e., download Apache 2(or above version), PHP 5(or above version) which should be an archive(.zip, or .tar file) and MySQL 5(or above version).
  • Install Apache Server into your system and then you are supposed to see your web server at the taskbar up and running but its not yet configured for PHP. Still you can go to 'http://localhost/' on your browser you should see that it will display a default 'index.html' page.Its OK.
  • Install PHP 5 package by extracting the package contents into your root directory, that is, C:\ and then copy file 'php-ini-development' or 'php-ini-dist' to a folder named backup on your desktop. You'll need it if anything compromise on your environment happens in future.
  • Install MySQL package which should be an executable file package and choose standard configuration where prompted. Enter your new password and I would advise you to save the password somewhere safe if you forget easily because you don't want future distress from failure to connecting to database. Don't change any other options just leave them the way they are. Don't forget to select option of 'Add to your bin directory to your Path'.
  • Move to PHP 5 directory and you remember the 'php-ini-dist' file rename it to 'php.ini' file and open it with your text editor to configure. Find 'doc_root = ' in the file and change by adding the directory to "C:\Program Files\Apache Software Foundation\Apache2.2\htdocs" directory which is the default on Apache server or you may search on 'httpd' file on 'conf' directory that resides on web server root directory and search value for 'DocumentRoot ' so after it should be like this, 'doc_root = C:\Program Files\Apache Software Foundation\Apache2.2\htdocs'. Find 'extension_dir = '  and remove ';' if it has one and change it to by adding 'C:\<PHP 5 installation>\ext' at the end of '= ' should be like this, 'extension_dir = C:\PHP5\ext'. Find ';extension=' and uncomment by removing the ';' at the start of it for the following 'php_mysqli.dll', 'php_gd2.dll' only those which will allow you to connect to the database and the graphics library. Also uncomment 'session.save_path = "C:\Windows\Temp"' and change it if it has no or different value directory given.
  • Finally before we done with PHP 5 configuration add the PHP 5 directory to your PATH. If you don't know refer to my post on java configuration on this blog.
  • Go to Apache web server directory and move to conf directory you will copy the 'httpd' file to backup folder you backed up the 'php-ini-dist' file. You will need it if your web server gets compromised in future. Open 'httpd' file in text editor find '<IfModule dir_module>'  and add between the tags  after the 'index.html' add 'index.php' which must have a space between them. The 'index.php' file might be any of your wish, e.g., test.php or any other php file which we'll be the default php file. After the changes it should be like this, 'DirectoryIndex index.html index.php'.  
  • Finally add module to handle PHP applications, that is, add the following lines at the end of the file.
 LoadModule php5_module "C:\PHP\php5apache<version>.dll"
AddType application/x-httpd-php .php
PHPIniDir "C:\PHP"

Using IIS
  •  First you will need PHP 5 and MySQL 5 installed but you do not need it configured.
  • Hold Ctrl Key and punch R to get Run dialog window type in 'inetmgr' to get IIS manager window.
  • On IIS Manager, and then move to the server level.
  • Double-click Handler Mappings.
  • In the Actions pane, click Add Module Mapping.
  • In the Add Module Mapping dialog box, specify the configuration settings as follows:
    • Request path: *.php
    • Module: FastCgiModule
    • Executable: C:\[Path to your PHP installation]\php-cgi.exe
    • Name: PHPviaFastCGI
  • Click OK.
  • In the dialog box that asks you to confirm that you want to create a FastCGI application for the executable, click Yes.
  • To verify that the handler mapping works correctly, create a Phpinfo.php file in the C:\inetpub\wwwroot folder that contains the following:
    <?php phpinfo(); ?>
  • Open a Web browser, and then navigate to http://localhost/phpinfo.php. If everything was set up correctly, you will see the standard PHP information page.


No comments:

Post a comment