آموزش نصب و کانفیگ php-fpm در دایرکت ادمین directadmin

آموزش نصب و کانفیگ php-fpm در دایرکت ادمین directadmin

گروه آموزشی مجموعه تدبیر

 After tried to patch it so many times, I decided to upgrade to PHP 5.3.5 and it works correctly now.

Also, when compile PHP-FPM, you will get 2 PHP files. One is “php” which is for CLI mode and “php-fpm” which is PHP-FPM. “php-cgi” file won’t be compiled until you removed “–enable-fpm” from configuration. That means… if you want to have the rest of Virtualhosts to run with mod_fcgid (php-cgi) with PHP 5.2, you can still do that. Just make sure to upgrade directly to PHP 5.3 and PHP-FPM at the same time. Always have “–enable-fpm” in configuration file for PHP to compile. That way, “php-cgi” will not compile in PHP version 5.3. So, all websites run with mod_fcgid that still use “php-cgi” file still run in PHP 5.2.

In case you need all of them to run in PHP 5.3. You need to compile PHP twice, one with “–enable-fpm” and one without it.

1. Enable PHP-FPM and compile PHP.

1.1 Copy “configure.php5” for custom compile

  1. mkdir p /usr/local/directadmin/custombuild/custom/suphp
  2. cp /usr/local/directadmin/custombuild/configure/suphp/configure.php5 /usr/local/directadmin/custombuild/custom/suphp

1.2 Edit configure.php5

  1. nano w /usr/local/directadmin/custombuild/custom/suphp/configure.php5

add “–enable-fpm” into the file. After edit, the “configure.php5” will look like below :

  1. #!/bin/sh
  2. “./configure”
  3. “–prefix=/usr/local/php5”
  4. “–enable-force-cgi-redirect”
  5. “–enable-fastcgi”
  6. “–with-config-file-path=/usr/local/etc/php5/cgi”
  7. “–with-curl=/usr/local/lib”
  8. “–with-gd”
  9. “–with-gettext”
  10. “–with-jpeg-dir=/usr/local/lib”
  11. “–with-freetype-dir=/usr/local/lib”
  12. “–with-kerberos”
  13. “–with-mcrypt”
  14. “–with-mhash”
  15. “–with-mysql=/usr”
  16. “–with-mysqli=/usr/bin/mysql_config”
  17. “–with-pcre-regex=/usr/local”
  18. “–with-pdo-mysql=/usr”
  19. “–with-pear=/usr/local/lib/php”
  20. “–with-png-dir=/usr/local/lib”
  21. “–with-zlib”
  22. “–with-zlib-dir=/usr/local/lib”
  23. “–with-openssl”
  24. “–with-iconv=/usr/local”
  25. “–enable-bcmath”
  26. “–enable-calendar”
  27. “–enable-exif”
  28. “–enable-ftp”
  29. “–enable-gd-native-ttf”
  30. “–enable-magic-quotes”
  31. “–enable-soap”
  32. “–enable-sockets”
  33. “–enable-mbstring”
  34. “–enable-zip”
  35. “–enable-wddx”
  36. “–enable-fpm”

1.3 Compile PHP

  1. cd /usr/local/directadmin/custombuild
  2. ./build php n

Note : If you get error while compile, you may need to run ” .build clean ” and then try to compile again.

1.4 After compiled, you will see where PHP-FPM file located as below :

  1. …..
  2. MakeComplete
  3. Copying php.ini..
  4. /usr/local/etc/php5/cgi/php.ini already exists, skipping.
  5. Installing php
  6. Installing PHP SAPI module: fpm
  7. Installing PHP CLI binary:/usr/local/php5/bin/
  8. Installing PHP CLI man page:/usr/local/php5/man/man1/
  9. Installing PHP FPM binary:/usr/local/php5/sbin/
  10. Installing PHP FPM config:/usr/local/php5/etc/
  11. Installing PHP FPM man page:/usr/local/php5/man/man8/
  12. Installing build environment:/usr/local/php5/lib/php/build/
  13. Installing header files:/usr/local/php5/include/php/
  14. Installing helper programs:/usr/local/php5/bin/
  15. program: phpize
  16. program: phpconfig
  17. Installing man pages:/usr/local/php5/man/man1/
  18. page: phpize.1
  19. page: phpconfig.1
  20. Installing PEAR environment:/usr/local/lib/php/
  21. …..

2. Now, Create Init script file

2.1 Copy file from source

  1. cp /usr/local/directadmin/custombuild/php5.3.5/sapi/fpm/init.d.phpfpm.in/etc/init.d/phpfpm
  2. chmod 755/etc/init.d/phpfpm

2.2 Edit php.fpm init script file as below:

  1. nano w /etc/init.d/phpfpm

Edit php.fpm file FROM :

  1. …..
  2. prefix=@prefix@
  3. exec_prefix=@exec_prefix@
  4.  
  5. php_fpm_BIN=@sbindir@/phpfpm
  6. php_fpm_CONF=@sysconfdir@/phpfpm.conf
  7. php_fpm_PID=@localstatedir@/run/phpfpm.pid
  8.  
  9.  
  10. php_opts=“–fpm-config $php_fpm_CONF”
  11. …..

TO :

  1. …..
  2. prefix=/usr/local/php5
  3. exec_prefix=${prefix}
  4.  
  5. php_fpm_BIN=/usr/local/php5/sbin/phpfpm
  6. php_fpm_CONF=/usr/local/php5/etc/phpfpm.conf
  7. php_fpm_PID=/var/run/phpfpm.pid
  8.  
  9.  
  10. php_opts=“–fpm-config $php_fpm_CONF”
  11. …..
  12.  

You may need to run command below to have PHP-FPM run automatically when start up (After reboot or turn on the machine) :

  1. /sbin/chkconfig phpfpm on

2.3 Edit PHP-FPM configuration file to match your need. My example below is just to make it work but you can adjust to whatever you like :

  1. nano w /usr/local/php5/etc/phpfpm.conf

Below is my “php-fpm.conf” configuration :

  1. [global]
  2. pid =/var/run/phpfpm.pid
  3. error_log =/var/log/phpfpm.log
  4. [admin]
  5. listen =/fcgi/admin/public_html/admin.sock
  6. listen.owner = $pool
  7. listen.group= $pool
  8. listen.mode =0666
  9. user = $pool
  10. group= $pool
  11. pm =dynamic
  12. pm.max_children =50
  13. pm.start_servers =3
  14. pm.min_spare_servers =3
  15. pm.max_spare_servers =10
  16. php_admin_value[open_basedir]=/home/$pool/:/tmp:/var/tmp:/var/www/html

Note 1 : $pool is variable which will replaced by the data from the bracket. Here, that is “admin”.
Note 2 : php_admin_value[open_basedir] is not require but suggested. Also, without “/var/www/html”, you won’t be access your webmail or anything through domain name. However, you can still access webmail or anything through IP Address.

2.4 Try to start / stop / restart PHP-FPM

  1. service phpfpm start
  2. service phpfpm stop
  3. service phpfpm restart

Note :

1. To have PHP-FPM compiled and configured in this tutorial doesn’t mean you already using it. It just means you already have PHP-FPM ready to use. You need to check my tutorial [HOW-TO] DirectAdmin – Run Apache with “mod_fcgid on PHP 5.2 / 5.3” and “mod_fastcgi + PHP-FPM on 5.3” on the same server that will be post soon