1 #!/usr/bin/env bash
2 PHP_DEBUG_SO_FILE='/party/apache/php5/lib/php/extensions/xdebug.so'
3 PHP_INI_PATH='/party/apache/php5/lib/php.ini'
4 PHP_BIN='/party/apache/php5/bin/php'
5
6 XDEBUG_CONFIG='\n[xdebug]\nzend_extension = xdebug.so\nxdebug.idekey = PHPSTORM\nxdebug.remote_enable = On\nxdebug.remote_autostart = Off\nxdebug.remote_connect_back = On\n; xdebug.remote_host = you host ip\nxdebug.profiler_enable_trigger = On\nxdebug.profiler_output_dir = /tmp/php_profiler\n; xdebug.profiler_output_name = cachegrind.out.%p'
7
8 status() {
9 ${PHP_BIN} -v | grep -o "Xdebug v[0-9.]*"
10 grep --color=auto xdebug ${PHP_INI_PATH}
11 }
12
13 restart_http() {
14 kill -9 `pidof httpd`
15 test -f /etc/cron.min/softdog.sh && /etc/cron.min/softdog.sh
16 }
17
18 install() {
19 status
20
21 if [[ ! -f ${PHP_DEBUG_SO_FILE} ]]; then
22 if [[ ! -f /tmp/xdebug.so ]]; then
23 curl http://code.sangfor.org/16767/tools/raw/master/php/xdebug-2.5.5.so -o /tmp/xdebug.so
24 fi
25 echo "Cp xdebug.so to ${PHP_DEBUG_SO_FILE}"
26 mv /tmp/xdebug.so ${PHP_DEBUG_SO_FILE}
27 fi
28
29 if [[ `grep -c "\[xdebug\]" ${PHP_INI_PATH}` -eq '0' ]]; then
30 echo "Added config"
31 echo -e ${XDEBUG_CONFIG} >> ${PHP_INI_PATH}
32 fi
33
34 mkdir -p /tmp/php_profiler; chown daemon:daemon /tmp/php_profiler
35
36 echo "Restart Apache"
37 restart_http
38
39 echo "Add query string to you url ?XDEBUG_SESSION_START=PHPSTORM or XDEBUG_PROFILE=on"
40 echo "Successful installation"
41 echo "Maybe you need to see http://code.sangfor.org/16767/tools/blob/master/php/fuck_ioncube.sh"
42 }
43
44 uninstall() {
45 status
46 sed -i '/xdebug/d' ${PHP_INI_PATH}
47 echo "Uninstall successfully"
48
49 echo "Restart Apache"
50 restart_http
51 }
52
53 case "$1" in
54 status) status ;;
55 install) install ;;
56 uninstall) uninstall ;;
57 *)
58 echo "Usage: $(basename -- "$0") {install|uninstall|status}" >&2
59 exit 3
60 ;;
61 esac
62
63 exit $?