Set Up PHP Development Environment

Notes of Set up PHP development environment

  1. Install Eclipse PDT;
  2. Install PEAR and PECL on Mac OS X, php.ini locate in /etc on Yosemite;
  3. Install Xdebug through PEAR/PECL;
    Addition configure for Yosemite

    • sudo cp /etc/php.ini.default /etc/php.ini
    • add “zend_extension=/usr/lib/php/extensions/no-debug-non-zts-20121212/xdebug.so” to php.ini
  4. Debugging Local PHP Files (PHP CLI Application)

    • Create a PHP project;
    • Create a PHP file;
    • Set a breakpoint in PHP file;
    • Save file;
    • Create a new debug configuration;
      • Eclipse > Preference… > PHP Executables > Add (Executable path: which php)
      • Run > Debug Configurations > Select PHP CLI Application > New
  5. Debugging PHP Web Applications (PHP Web Application)

    • Create a PHP project;
    • Create a PHP file;
    • Create a new debug configuration;
      • Run > Debug Configurations > Select PHP Web Application > New
  6. Test with PHPUnit

    • Run > External Tools > External Tools Configurations… > Program > New [Main] Location:/usr/local/bin/phpunit Working Directory:${workspace_loc:/Backend/tests} Apply > Run Reference
  7. Integrate MakeGood (failure)

    • Installing Prerequisite Software
      • PHP 5.5.27 (cli)
      • xdebug-2.3.2
      • eclipse mars(4.5.0)
      • PDT(3.5.0)
      • PHPUnit (4.8.6)
    • Installing MakeGood Help -> Install New Software… -> Add… -> http://eclipse.piece-framework.com/

    • Selecting a Testing Framework

    • Resolving the Dependencies to the Testing Framework

        * Defining User Libraries
            Eclipse -> Preferences... > PHP -> PHP Libraries > New... > OK
            Add External folder... > [Verifying the include path](http://pear.php.net/manual/en/installation.checking.php)
        * Adding User Libraries to the Project
      

      fail with PHPUnit_Framework_TestCase class is not available. Fix…, I doubt that MakeGood doesn’t support eclipse mars.

    *Testing Framework Specific Configuration
    PHPUnit

     * Open the properties for the project.
     * Select MakeGood.
     * Select PHPUnit.
     * Specify the XML Configuration File. [eg](http://beagile.biz/a-simple-phpunit-xml-configuration-example/)
    

    Reference

Throw java.lang.NullPointerException when create a new debug configuration

Solution: Add a PHP Executable, Eclipse > Preference… > PHP Executables > Add (Executable path: which php)

Wait for XDebug session

Solution:Debugging PHP Web Applications时卡在这里,原因是XDebug remote debug没配置好,参考了Remote DebuggingDebugging using XDebug,发现phpinfo()输出的内容并没有XDebug。于是来开始配置php.ini,参考的How to set default php.ini to be used, OSX Yosemite

1
2
3
4
5
6
7
8
9
10
11
12
13
14
sudo cp /etc/php.ini.default /etc/php.ini

// Add follow content to php.ini
[XDebug]
zend_extension=/usr/lib/php/extensions/no-debug-non-zts-20121212/xdebug.so
xdebug.remote_enable=On
xdebug.remote_handler=dbgp
xdebug.remote_host=helloworld.local
xdebug.remote_port=9000
;xdebug.remote_connect_back=1
xdebug.remote_mode="req"
xdebug.remote_log="/var/log/xdebug.log"

sudo apachectl restart

/private/tmp/pear/install/xdebug/xdebug.c:25:10: fatal error: ‘php.h’ file not found

Solution:

1
$ xcode-select --install

Reference:http://stackoverflow.com/questions/19531262/cant-phpize-or-configure-an-extension-in-os-x-10-9-mavericks

Tcpdump 和 Wireshark 使用笔记

Tcpdump 和 Wireshark 是两个常用的抓包工具,一个是命令行工具;一个图形界面工具,可以按自己的喜好选择。图形界面的 Wireshark 个人感觉使用更简单,但从打开到抓包花费的时间要比使用 Tcpdump 要多,有的场景也不能使用 Wireshark,例如在 Android 真机上抓包。由于使用它们时核心是一样的,就是按照包过滤语法(pcap-filter(7))来指定表达式,因此可以先使用 Wireshark 上手,之后熟练起来后在不能用 Wirehshark 的场景便可以使用 Tcpdump。

Wireshark

1.Capture HTTP traffic on your server

1
2
3
4
5
6
Capture > Capture Filters... > New > OK
Capture > Options... > Capture Filter(Set to appropriate filter) > Start

host www.baidu.com

curl -d "name=test&page=1" http://www.baidu.com
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
POST / HTTP/1.1
User-Agent: curl/7.37.1
Host: www.baidu.com
Accept: */*
Content-Length: 16
Content-Type: application/x-www-form-urlencoded

name=test&page=1


HTTP/1.1 302 Moved Temporarily
Date: Tue, 15 Sep 2015 00:56:03 GMT
Content-Type: text/html
Content-Length: 215
Connection: Keep-Alive
Location: http://www.baidu.com/search/error.html
Server: BWS/1.1
X-UA-Compatible: IE=Edge,chrome=1
BDPAGETYPE: 3
Set-Cookie: BDSVRTM=0; path=/

<html>
<head><title>302 Found</title></head>
<body bgcolor="white">
<center><h1>302 Found</h1></center>
<hr><center>pr-nginx_1-0-245_BRANCH Branch
Time : Thu Sep 10 11:36:26 CST 2015</center>
</body>
</html>

Tcpdump

1.指定 Host 和 Port 抓包

在开发过程中,我们可能想查看客户端和服务器的详细交互,这时我们通过指定 Host 和 Port 抓包来得到详细的 HTTP 交互。例如现在是在我的本地开发环境,服务器的端口是8080,可以用以下命令:

1
$sudo tcpdump -A -i lo0 '(src localhost and dst port 8080) or (dst localhost and src port 8080)'

Reference:

Linux 使用笔记(二)

1.Rails Error: ImageMagick/GraphicsMagick is not installed

1
2
brew install graphicsmagick
brew install ImageMagick

Reference:http://stackoverflow.com/questions/29377651/rails-error-imagemagick-graphicsmagick-is-not-installed

2.Transfer file via scp (or sftp) between two Mac

Via scp:
1.Enable Enable SSH System Preferences > Sharing > enable the “Remote Login” feature

2.type scp command

1
scp VirtualBox-5.0.4-102546-OSX.dmg dongmeiliang@192.168.1.255:/Users/dongmeiliang/Documents/
继续阅读