Setting advanced PHP development environment

download Setting advanced PHP development environment

If you can't read please download the document

Transcript of Setting advanced PHP development environment

Setting Advanced PHP Development Environment

Setting AdvancedPHP Development Environment

What is development environment?2A set of all tools that we need to develop a solution (Web application)

Mainly we needOperating SystemServer SoftwareDatabaseProgramming Language

2

LAMP3Stands for Linux-Apache-MySQL-PHP(At least in theories)Linux Operating SystemApache Web serverMySQL DatabasePHP Programming LanguageThis is just a general definition.In modern app, all 4 can be changed.So what are possible options?

Operating System4Linux LAMPWindows WAMPMac OS MAMPOr any other Operating system.

Web Server Software5Apache

Nginx (Pronounced Engine X)

Lighttpd

IIS

Database6MySQLPostgreSQLOracleMS SQL ServerMaria DBIBM DB 2MongoDBCassandraNeo4J

Programming Language7

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

Basic Dev-Env on Windows 9WAMP Server

XAMPP

Standalone Apache, MySQL, PHP

Basic Dev-Env on Windows 10Why WAMP/XAMPP?Easy one click setup.Easy to manage Apache/PHP modulesCan switch PHP/MySQL versions (limited to available on WAMP)

Why Standalone?More control over different versions.Can replicate production server better.

Basic Dev-Env on Windows 11WAMP or XAMPP?Personal preference.WAMP is windows only, while XAMPP is cross platform.

My personal preference (if that matter) is WAMP.Here Im concentrating on WAMP.

Installing WAMP12Download installer from http://www.wampserver.com/en/

Install as any windows program(Double click installer )

Starting WAMP13

Working with14

Basic Dev-Env on Linux15Which Linux?

16

Basic Dev-Env on Linux

17Basic Dev-Env on Linux

Apache18

apt-get update

apt-get install apache2yast2 -i apache2

To start with SystemSystemctl enable apache2.servicesystemctl start apache2.service

MySQL19

apt-get install mysql-server mysql-clientyast2 -i mysql mysql-client mysql-community-serverTo start with systemsystemctl enable mysql.servicesystemctl start mysql.service

MySQL20

mysql_install_db

mysql_install_db

PHP21

apt-get install php5 libapache2-mod-php5

yast2 -i apache2-mod_php5

Restarting Apache22

sudo service apache2 restart

sudo systemctl restart apache2.service

PHP Modules23apt-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-cliyast2 -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

You can develop and work on nearly any web application.

ButIs it sufficient?24So LAMP/WAMP is now up and running

Example25Suppose you are making a site http://www.abccorp.comWhere will you put files? X:\wamp\www\abccorpHow will you access site? http://localhost/abccorpIf you are using framework, say symfony http://localhost/abccorp/webWould you like to use http://local.abccorp.com

Virtual host on WAMP26Step 1: update hosts fileOpen notepad as administrator.Open file C:\Windows\system32\drivers \etc\hostsAdd following line at bottom127.0.0.1 local.abccorp.com

Virtual host on WAMP27Step 2: Update httpd.confSearch and uncomment# Include conf/extra/ httpd-vhosts.conf

Virtual host on WAMP28Open file X:\WAMP\WWW\apache\apacheXXX\conf\extra\httpd-vhosts.confAdd following:

ServerAdmin [email protected] DocumentRoot "c:\projects\abccorp" ServerName local.abccorp.com ErrorLog "logs/abccorp.log" CustomLog "logs/abccorp-access.log" common

Restart apache and access http://local.abccorp.com

Virtual host on Ubuntu29Open /etc/hosts file in editor and add127.0.0.1 local.abccorp.comCopy /etc/apache2/sites-available/default to /etc/apache2/sites-available/local.abccorp.comEdit newly created file and changeServerName local.abccorp.com

ServerAdmin [email protected] ServerName local.abccorp.com ServerAlias local.abccorp.com

Virtual host on Ubuntu30Also update document rootDocumentRoot /path/to/project/web/rootEnable sitea2ensite local.abccorp.comReload and restart apacheservice apache2 reloadservice apache2 restartAccess site local.abccorp.com

JDK or JRE31Yes, even as PHP developer, we need Java Development Kit of at least Java Runtime environment because:IDEMany 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 fromhttp://www.oracle.com/technetwork/java/javase/downloads/index.htmlAnd follow instruction to install.

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

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

Installing Composer34Linux curl -sS https://getcomposer.org/installer | php mv composer.phar /usr/local/bin/composer

Windows Download installer from getcomposer.org

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

Installing PHP Unit36With 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

Code Quality37Any 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.

Code Sniffer38Installationpear install PHP_CodeSniffer

Usagephpcs--standard=ZEND/path/to/code/file.php

More Infohttp://pear.php.net/manual/en/package.php.php-codesniffer.intro.php

Virtual Machine39Virtual 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

Vagrant, Puppet/Chef40Vagrant 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.

Vagrant Setup41Install Oracle Virtual BoxGo to www.virtualbox.org, download installer and install Virtual Box.Install VagrantGo to www.vagrantup.com/downloads and download suitable installer.Install as per platform

Vagrant up42Create new boxvagrant init precise32 http://files.vagrantup.com/precise32.boxStart vagrantvagrant up This command will start server.Login to virtual machinevagrant sshStop vagrantvagrant haltFurther stepsConfigure vagrant box with Puppet/Chef

About Me & Question43Name: Kapil Sharma (Im not comedian)Twitter: @kapilsharmainfo

Any Question?