Upgrade to Pro — share decks privately, control downloads, hide ads and more …

PHP DevEnv

Kapil Sharma
February 22, 2014

PHP DevEnv

Setup advanced PHP development environment.

Kapil Sharma

February 22, 2014
Tweet

More Decks by Kapil Sharma

Other Decks in Programming

Transcript

  1. What is development environment? 2  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 3  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 4  Linux – LAMP  Windows –

    WAMP  Mac OS – MAMP  Or any other Operating system.
  4. Database 6  MySQL  PostgreSQL  Oracle  MS

    SQL Server  Maria DB  IBM DB 2  MongoDB  Cassandra  Neo4J
  5. Setting Basic Dev Env 8  OS: you must be

    having.  Lets assume Windows or Linux.  Lets set basic PHP development environment on
  6. Basic Dev-Env on Windows 9  WAMP Server  XAMPP

     Standalone Apache, MySQL, PHP
  7. Basic Dev-Env on Windows 10  Why WAMP/XAMPP?  Easy

    one click setup.  Easy to manage Apache/PHP modules  Can switch PHP/MySQL versions (limited to available on WAMP)  Why Standalone?  More control over different versions.  Can replicate production server better.
  8. Basic Dev-Env on Windows 11  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.
  9. Apache 18 apt-get update apt-get install apache2 yast2 -i apache2

    To start with System Systemctl enable apache2.service systemctl start apache2.service
  10. MySQL 19 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
  11. PHP Modules 23 apt-get install php5-mysql php5-curl php5-gd php5- intl

    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 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
  12. You can develop and work on nearly any web application.

    But Is it sufficient? 24 So LAMP/WAMP is now up and running
  13. Example 25  Suppose you are making a site http://www.abccorp.com

     Where will you put files? X:\wamp\www\abccorp  How will you access site? http://localhost/abccorp  If you are using framework, say symfony http://localhost/abccorp/web  Would you like to use http://local.abccorp.com
  14. Virtual host on WAMP 26  Step 1: update hosts

    file  Open notepad as administrator.  Open file C:\Windows\system32\drivers \etc\hosts  Add following line at bottom 127.0.0.1 local.abccorp.com
  15. Virtual host on WAMP 27  Step 2: Update httpd.conf

     Search and uncomment # Include conf/extra/ httpd-vhosts.conf
  16. Virtual host on WAMP 28  Open file X:\WAMP\WWW\apache\apacheXXX\conf\extra\httpd-vhosts.conf 

    Add following: <VirtualHost *:80> ServerAdmin [email protected] DocumentRoot "c:\projects\abccorp" ServerName local.abccorp.com ErrorLog "logs/abccorp.log" CustomLog "logs/abccorp-access.log" common </VirtualHost>  Restart apache and access http://local.abccorp.com
  17. Virtual host on Ubuntu 29  Open /etc/hosts file in

    editor and add 127.0.0.1 local.abccorp.com  Copy /etc/apache2/sites-available/default to /etc/apache2/sites-available/local.abccorp.com  Edit newly created file and change  ServerName local.abccorp.com  <VirtualHost *:80> ServerAdmin [email protected] ServerName local.abccorp.com ServerAlias local.abccorp.com
  18. Virtual host on Ubuntu 30  Also update document root

    DocumentRoot /path/to/project/web/root  Enable site a2ensite local.abccorp.com  Reload and restart apache service apache2 reload service apache2 restart  Access site local.abccorp.com
  19. JDK or JRE 31  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 http://www.oracle.com/technetwork/java/javase/downloads/index.html • And follow instruction to install.
  20. PEAR 32  PHP Extension and Application Repository.  Lot

    of good PHP extensions/library.  Install system based dependencies by default.  Personally: Composer recommended.
  21. Composer 33  Composer is PHP Dependency Manager, which install

    project specific dependencies.  Most modern framework now use composer for downloading dependencies.  PHP-FIG effect.
  22. Installing Composer 34  Linux curl -sS https://getcomposer.org/installer | php

    mv composer.phar /usr/local/bin/composer  Windows Download installer from getcomposer.org
  23. PHP Unit 35  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.
  24. Installing PHP Unit 36  With Composer { "require-dev": {

    "phpunit/phpunit": "3.7.*" } }  With PHAR wget https://phar.phpunit.de/phpunit.phar chmod +x phpunit.phar mv phpunit.phar /usr/local/bin/phpunit phpunit –version php phpunit.phar --version
  25. Code Quality 37  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.
  26. Code Sniffer 38  Installation pear install PHP_CodeSniffer  Usage

    phpcs --standard=ZEND /path/to/code/file.php  More Info http://pear.php.net/manual/en/package.php.php- codesniffer.intro.php
  27. Virtual Machine 39  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
  28. Vagrant, Puppet/Chef 40  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.
  29. Vagrant Setup 41  Install Oracle Virtual Box Go to

    www.virtualbox.org, download installer and install Virtual Box.  Install Vagrant Go to www.vagrantup.com/downloads and download suitable installer. Install as per platform
  30. Vagrant up 42  Create new box vagrant init precise32

    http://files.vagrantup.com/precise32.box  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
  31. About Me & Question 43  Name: Kapil Sharma (I’m

    not comedian)  Twitter: @kapilsharmainfo Any Question?