Setting advanced PHP development environment

100 %
0 %
Information about Setting advanced PHP development environment

Published on February 22, 2014

Author: kapilsharmainfo



Slides of presentation during Pune PHP MeetUp.

Setting Advanced PHP Development Environment

What is development environment?  A set of all tools that we need to develop a solution (Web application)  Mainly we need Operating System Server Software Database Programming Language 2

LAMP  Stands for Linux-Apache-MySQL-PHP (At least in theories)  Linux – Operating System  Apache – Web server  MySQL – Database  PHP – Programming Language  This is just a general definition.  In modern app, all 4 can be changed.  So what are possible options? 3

Operating System  Linux – LAMP  Windows –WAMP  Mac OS – MAMP  Or any other Operating system. 4

Web Server Software  Apache  Nginx (Pronounced Engine X)  Lighttpd  IIS 5

Database  MySQL  PostgreSQL  Oracle  MS SQL Server  Maria DB  IBM DB 2  MongoDB  Cassandra  Neo4J 6

Programming Language 7

Setting Basic Dev Env  OS: you must be having.  Lets assume Windows or Linux.  Lets set basic PHP development environment on 8

Basic Dev-Env on Windows  WAMP Server  XAMPP  Standalone Apache, MySQL, PHP 9

Basic Dev-Env on Windows  Why WAMP/XAMPP?  Easy one click setup.  Easy to manage Apache/PHP modules  Can switch PHP/MySQL versions (limited to available on WAMP) 10  Why Standalone?  More control over different versions.  Can replicate production server better.

Basic Dev-Env on Windows  WAMP or XAMPP?  Personal preference.  WAMP is windows only, while XAMPP is cross platform.  My personal preference (if that matter) is WAMP.  Here I’m concentrating on WAMP. 11

Installing WAMP  Download installer from  Install as any windows program (Double click installer 12 )

Starting WAMP 13

Working with 14

Basic Dev-Env on Linux Which Linux? 15

Basic Dev-Env on Linux 16

Basic Dev-Env on Linux 17

Apache apt-get update apt-get install apache2 yast2 -i apache2 To start with System Systemctl enable apache2.service systemctl start apache2.service 18

MySQL apt-get install mysql-server mysql-client yast2 -i mysql mysql-client mysql-community-server To start with system systemctl enable mysql.service systemctl start mysql.service 19

MySQL mysql_install_db mysql_install_db 20

PHP apt-get install php5 libapache2-mod-php5 yast2 -i apache2-mod_php5 21

Restarting Apache sudo service apache2 restart sudo systemctl restart apache2.service 22

PHP Modules apt-get install php5-mysql php5-curl php5-gd php5intl php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl php5-cli yast2 -i php5-mysql php5-curl php5-gd php5-intl phppear php5-imagick php5-imap php5-mcrypt php5memcache php5-ming php5-ps php5-pspell php5recode php5-snmp php5-sqlite php5-tidy php5xmlrpc php5-xsl php5-cli 23

So LAMP/WAMP is now up and running You can develop and work on nearly any web application. But Is it sufficient? 24

Example  Suppose you are making a site     25 Where will you put files? X:wampwwwabccorp How will you access site? http://localhost/abccorp If you are using framework, say symfony http://localhost/abccorp/web Would you like to use

Virtual host on WAMP  Step 1: update hosts file  Open notepad as administrator.  Open file C:Windowssystem32drivers etchosts  Add following line at bottom 26

Virtual host on WAMP  Step 2: Update httpd.conf  Search and uncomment # Include conf/extra/ httpd-vhosts.conf 27

Virtual host on WAMP  Open file X:WAMPWWWapacheapacheXXXconfextrahttpd-vhosts.conf  Add following: <VirtualHost *:80> ServerAdmin DocumentRoot "c:projectsabccorp" ServerName ErrorLog "logs/abccorp.log" CustomLog "logs/abccorp-access.log" common </VirtualHost>  Restart apache and access 28

Virtual host on Ubuntu  Open /etc/hosts file in editor and add     29 Copy /etc/apache2/sites-available/default to /etc/apache2/sites-available/ Edit newly created file and change ServerName <VirtualHost *:80> ServerAdmin ServerName ServerAlias

Virtual host on Ubuntu  Also update document root DocumentRoot /path/to/project/web/root  Enable site a2ensite  Reload and restart apache service apache2 reload service apache2 restart  Access site 30

JDK or JRE  Yes, even as PHP developer, we need Java Development Kit of at least Java Runtime environment because: IDE Many Java based tools, important during SDLC. • Nearly all OS come with some JRE (Not Sun/Oracle JRE) • For best result, prefer Oracle JDK or JRE. • Download installer from • And follow instruction to install. 31

PEAR  PHP Extension and Application Repository.  Lot of good PHP extensions/library.  Install system based dependencies by default.  Personally: Composer recommended. 32

Composer  Composer is PHP Dependency Manager, which install project specific dependencies.  Most modern framework now use composer for downloading dependencies.  PHP-FIG effect. 33

Installing Composer  Linux curl -sS | php mv composer.phar /usr/local/bin/composer  Windows Download installer from 34

PHP Unit  PHP Unit is Unit testing framework/tool.  Do you need Unit Testing?  NO because: I’m genius and never make mistake. No budget (My client can afford bugs but budget cant be increased) I don’t want to learn something new (I do not care … ) • Yes, but I don’t know how to test? No issue, install it and learn it. 35

Installing PHP Unit  With Composer { "require-dev": { "phpunit/phpunit": "3.7.*" } }  With PHAR wget chmod +x phpunit.phar mv phpunit.phar /usr/local/bin/phpunit phpunit –version php phpunit.phar --version 36

Code Quality  Any fool can write a code that computer can understand. Good developers write code that humans can understand. – Martin Fowler.  Refactoring/Design Patterns/Unit Testing/OOPs.  At least start following coding conventions. Use code sniffer to force you doing that. 37

Code Sniffer  Installation pear install PHP_CodeSniffer  Usage phpcs --standard=ZEND /path/to/code/file.php  More Info 38

Virtual Machine  Virtual Machine allow to run one virtual Operating System from with in other, without dual booting.  Most popular Virtual Machines are:  Oracle Virtual Box.  VM Ware 39

Vagrant, Puppet/Chef  Vagrant is ‘Virtual Development Environment’.  Puppet and Chef are ‘Configuration Management Software’.  With proper use of Vagrant and Puppet/Chef, we can make development environment, very similar to production environment.  Ensure all developers have same development environment. 40

Vagrant Setup  Install Oracle Virtual Box Go to, download installer and install Virtual Box.  Install Vagrant Go to and download suitable installer. Install as per platform 41

Vagrant up  Create new box vagrant init precise32  Start vagrant vagrant up This command will start server.  Login to virtual machine vagrant ssh  Stop vagrant vagrant halt  Further steps Configure vagrant box with Puppet/Chef 42

About Me & Question  Name: Kapil Sharma (I’m not comedian)  Twitter: @kapilsharmainfo Any Question? 43

Add a comment

Related presentations

Presentación que realice en el Evento Nacional de Gobierno Abierto, realizado los ...

In this presentation we will describe our experience developing with a highly dyna...

Presentation to the LITA Forum 7th November 2014 Albuquerque, NM

Un recorrido por los cambios que nos generará el wearabletech en el futuro

Um paralelo entre as novidades & mercado em Wearable Computing e Tecnologias Assis...

Microsoft finally joins the smartwatch and fitness tracker game by introducing the...