Contents
1. Scope of the document 3
2. Introduction 3
3. Purpose of this document 3
4. Working Environment/PC Configuration 3
5. Operating system 3
6. IDE 3
7. Folder structures 4
8. Development Environment 5
8.1. Web Server - Apache 5
8.1.1. Installation: 5
8.1.2. Configurations: 5
8.2. Database - MySQL 5
8.2.1. Installation: 6
8.3. PHP 6
8.3.1. Installing PHP 6
8.3.2. Configurations 6
8.3.2.1. Configuring Apache 6
8.3.2.2. Configuration PHP 7
1. Scope of the document
Since the document contains the PC configurations and environments, this is intended to read carefully and follow the standards written in the document by all the PHP programmers .
2. Introduction
There are no particular standards specified by PHP language itself yet, the code in PHP can be written in any way just to achieve the goal or just to get the desired output because PHP itself is a quite flexible language. So not only a company but a single programmer can have a coding standard of his/her own.
But being a company and working in a team, we have to have a certain standard for environment and PC configurations which will make easier to open PC, find files by other peoples when required.
3. Purpose of this document
The purpose of defining the standards is to make the common coding in the department so that the code written by one programmer can be easily understand and later altered by another. It is also supposed that maintaining the coding standard will increase the quality too.
4. Working Environment/PC Configuration
To maintain a common working environment, we will have the common configurations in the personal computers. For PHP development, we need an IDE, Web server, Database and PHP package itself. Besides some exceptional cases, it is strongly recommended to use the latest version of the software though we may need to change/alter the configurations as per the requirement of a particular project.
5. Operating system
It is not restriction for the Operating System. Planning is to have Ubuntu (Linux) as a development operating system so that there are no platform dependent issues find when deploying the code in the production server because 99% of PHP deployment servers are Linux servers. But Windows XP, Windows 7 with properly configured Apache, PHP & MySQL are acceptable. For setting the Apache, PHP and MySQL see below.
6. IDE
Among many IDEs dedicated to PHP, the latest version of NetBeans is recommended. Netbeans is completely free. For now NetBeans is available in version 7.x. download it from http://netbeans.org/downloads/index.html. We may need to use DreamWeaver in some cases so it is free to use other IDEs too but for core PHP coding, it is recommended to use Netbeans. We are also planning to integrate xDebug with NetBeans so that we can debug through it.
7. Folder structures
All the project files, database data path and web server installation should be outside of C drive of your computer. It is recommended that you should have a folder called ‘etc’ in the D drive having the following folders inside:
- apache – Apache installation must be inside this folder.
- mysql – MySql Installation should go here.
- mysql/databases – MySQL data folder.
- php – PHP installation.
- docs – all project related document files i.e. PDDs, other raw files, etc. Create project name’s folder inside it.
- www – Apache document root. Create folder for each projects.
- mail – Outlook mail folder.
- chat – Chat history of MSN messenger must be saved inside this folder.
Note: Project folder name inside d:/etc/www folder should not contain capital letters, numbers, and special characters.
8. Development Environment
Currently we are using different AMP installer packages like WAMP & XAMPP but now onwards it is strictly recommended to use individual package installations for web server (Apache), database (MySQL) and PHP. We install them individually; everyone will be able to configure Apache, MySQL and PHP themselves.
8.1. Web Server - Apache
Though PHP can be run under IIS or other web servers, but Apache is the commonly used and available in most servers. So the latest version of Apache is recommended. It must be installed with installer not from the package of WAMP/XAMPP.
Download at: http://httpd.apache.org/download.cgi
Download the widows MSI installer
“Win32 Binary including OpenSSL 0.9.8o (MSI Installer): httpd-2.2.17-win32-x86-openssl-0.9.8o.msi”.
As mentioned earlier, the apache must be installed under d:/etc/apache folder but be careful to change the configurations in d:/etc/apache/httpd.conf accordingly.
8.1.1. Installation:
Installation of Apache is quite easy like other windows application installations. Just double click the MSI installer file and follow the instructions in the installation wizard.
8.1.2. Configurations:
Enabling/disabling some of the features is the main configuration in Apache. Mainly we need to enable some of the modules to be loaded accordingly to the requirements. But the rewrite module is recommended to enable. To enable it just uncomment (by removing the # from beginning of the line) the following line:
#LoadModule rewrite_module modules/mod_rewrite.so
To
LoadModule rewrite_module modules/mod_rewrite.so
More configurations will be required to be done once we install PHP later.
8.2. Database - MySQL
MySQL 5.1 or later community server version is recommended. (MySQL Community Server is a freely downloadable version of the world's most popular open source database that is supported by an active community of open source developers and enthusiasts.)
Download at: http://dev.mysql.com/downloads/mysql/
While installing MySQL, select the data path to other than C drive. Selecting different path for the MySQL data path, you have to choose the custom installation.
As per our folder structure mentioned above, MySQL has to be installed in d:/etc/mysql and the data folder has to be selected as d:/etc/mysql/databases. MySQL will create one folder ‘data’ inside it.
8.2.1. Installation:
Installation of MySQL is not that complicated. Just double click the MSI installer file and follow the instructions in the installation wizard. Do not forget to continue the configuration wizard at the end of installation.
It is strongly recommended that use the same password and do not leave the root password as blank. And it is suggested to use the password as ‘hwb’.
Example:
Mysql_connect(“localhost”, “root”, “hwb”) or die(“Error in connecting MySQL Server.” . mysql_error());
8.3. PHP
PHP 5.3.x is recommended. Since we are using PHP with Apache 2, we should use the VC6 versions of Thread Safe PHP. So download the latest recommended ZIP version from the download page so that we can just extract it and configure and use which is easy.
Note: But PHP’s latest versions are only available in VC9 that means the PHP compiled with Visual Studio C++ 2008 (VC9).So if anyone wants the latest version of PHP then it has to be installed with the Apache compiled with VC9 as well which can be downloaded from http://www.apachelounge.com. The installation tutorial is here http://www.apachelounge.com/viewtopic.php?t=2394
8.3.1. Installing PHP
1. Download the recommended ZIP from download page http://windows.php.net/download/
2. Unzip the files in a folder and rename it to ‘php’.
3. Copy the folder directly to the C drive of your windows.
That’s all for installation.
8.3.2. Configurations
Configuration of PHP is all done in a file called php.ini which should be located inside the ‘php’ folder which you just have put inside your C drive. By default there won’t the file with that name. There are two configuration files for development and production purpose. Since we use PHP for development in local systems, just rename the ‘php.ini-development’ to ‘php.ini’. To make PHP working properly we need to configure Apache to recognize where the PHP.
8.3.2.1. Configuring Apache
1. Open the Apache’s configuration file httpd.conf from d:/etc/apache/conf/httpd.conf with your favorite text editor.
2. Copy the following lines somewhere in the httpd.conf file.
LoadModule php5_module "d:/etc/php/php5apache2_2.dll"
AddType application/x-httpd-php .php
PHPIniDir "d:/etc/php"
3. Change your document. Document root should be somewhere outside of your C drive. Find the following line:
DocumentRoot "d:/etc/apache/htdocs"
And change it to:
DocumentRoot "d:/etc/www"
Find this line:
And change it to
4. Find the following line under
AllowOverride None
And change it to
AllowOverride All
5. Add the directory index file (normally index.php) in the following area:
DirectoryIndex index.php index.html
These are the only basic configurations in Apache configuration file. Rest are configured when they are needed.
8.3.2.2. Configuration PHP
Configuring PHP is normally meant to change the default settings or default behavior. Apart from changing the default settings, we need to do few things before we run PHP properly.
- Open the file php.ini in your favorite text editor.
- Set the extension directory. PHP by default has extension libraries (DLL Files) inside php/ext. So set it as follows:
extension_dir = "d:/etc/php/ext"
- Now enable required extensions by uncommenting (remove the semicolon ‘;’ from beginning of the line). Following extensions are recommended to enable at first side.
extension=php_curl.dll
extension=php_fileinfo.dll
extension=php_gd2.dll
extension=php_gettext.dll
extension=php_mbstring.dll
extension=php_mysql.dll
extension=php_mysqli.dll
extension=php_pdo_mysql.dll
extension=php_soap.dll
extension=php_sockets.dll
extension=php_xmlrpc.dll
Enabling other extensions is on demand. That means when you need then enable it.
- Set the default timezone as our locality so that testing of date/time will be as per our city.
date.timezone =Asia/Katmandu
- Set the mail configurations as below under [mail function]
SMTP = 192.168.192.1
smtp_port = 25
sendmail_from = info@hwbnepal.com
- Error reporting:
display_errors = On
error_reporting = E_ALL | E_STRICT
That’s all what you need to configure the PHP to run within Apache.
Now add the PHP path to system variables in windows environment so that it can be accessible from anywhere in the sytem.
- Right click on My Computer and choose Properties.
- Click Advanced tab.
- Click on the Environment Variables button.
- Double click the Path under System variables.
- And add the path d:\etc\php at the end of the Variable value field.
- Click OK button to save it.
- Now restart the windows OS once.
Author Sundar ban
Date March 14 2012
Description This document describes the standards for setting of working PC, development environment for the PHP .