Linux下php+mysql+nginx編譯搭建(三)

來源:互聯網
上載者:User
之前一直都是一鍵搭建的web伺服器,但是一鍵搭建的環境相對來說都是比較老的。如果要用比較新的環境,特別是正式伺服器,就必須自己手動編譯搭建了(以下搭建基於linux centos6.5 32位伺服器)。

三、安裝php
進入安裝目錄:

          
 
  1. cd /opt

下載並解壓:

          
 
  1. Wget http://am1.php.net/get/php-5.4.34.tar.gz/from/this/mirror
  2. tar -zxf php-5.4.34.tar.gz

進入目錄編譯:

          
 
  1. cd php-5.4.34
  2. ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql --with-mysqli=/usr/bin/mysql_config --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt=/usr/local/mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap --with-pear --enable-pdo --with-pdo-mysql --with-gettext --enable-exif --enable-wddx --enable-calendar --enable-ftp --enable-dba --enable-sysvmsg --enable-sysvshm --enable-debug --enable-maintainer-zts --enable-embed --with-pcre-regex --enable-gd-jis-conv --with-fpm-user=www --with-fpm-group=www --enable-sockets

報錯:configure: error: mcrypt.h not found. Please reinstall libmcrypt.
在http://sourceforge.net/projects/mcrypt/files/下載libmcrypt和mcrypt編譯(其中編譯mcrypt需要mhash的支援,所以編譯完libmcrypt後需要下載mhash,編譯完mhash後才編譯mcrypt)

          
 
  1. wget http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz/download
  2. tar -zxvf libmcrypt-2.5.8.tar.gz
  3. cd libmcrypt-2.5.8
  4. ./configure
  5. Make && Make install
  6. Wget http://sourceforge.net/projects/mhash/files/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz/download
  7. tar -zxvf mhash-0.9.9.9.tar.gz
  8. cd mhash-0.9.9.9.tar.gz
  9. ./configure
  10. Make && Make install
  11. wget http://sourceforge.net/projects/mcrypt/files/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz/download
  12. tar -zxvf mcrypt-2.6.8.tar.gz
  13. cd mcrypt-2.6.8
  14. ./configure
  15. Make && Make install

此時再編譯(命令不copy了),報錯:mysql_config not found
執行:find / -name mysql_config
發現/opt/mysql-5.5.30/scripts/mysql_config
於是:cp /opt/mysql-5.5.30/scripts/mysql_config /usr/bin/mysql_config
再次編譯,通過。

          
 
  1. make && make install

由於php5.4已經整合了php-fpm,所以我們不需要再額外下載php-fpm。
直接運行:

          
 
  1. /usr/local/php/sbin/php-fpm

報錯:ERROR: failed to open configuration file '/usr/local/php/etc/php-fpm.conf': No such file or directory (2)

          
 
  1. Cp /usr/local/etc/php-fpm.conf.default /usr/local/etc/php-fpm.conf

解決。ps aux | grep php 查看,已經啟動。

此時建立一個php檔案訪問,是不是還不支援?哈[壞笑]。
修改nginx.conf

          
 
  1. location ~ \.php$ {
  2. root html;
  3. fastcgi_pass 127.0.0.1:9000;
  4. fastcgi_index index.php;
  5. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  6. include fastcgi_params;
  7. }

重啟nginx,至此,所有完結。

然後是不是又有點淡淡的憂傷?覺得/usr/local/php/sbin/php-fpm太長?習慣了/etc/init.d/php-fpm start?
Vim /etc/init.d/php-fpm

          
 
  1. #! /bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides: php-fpm
  4. # Required-Start: $remote_fs $network
  5. # Required-Stop: $remote_fs $network
  6. # Default-Start: 2 3 4 5
  7. # Default-Stop: 0 1 6
  8. # Short-Description: starts php-fpm
  9. # Description: starts the PHP FastCGI Process Manager daemon
  10. ### END INIT INFO
  11. prefix=/usr/local/php
  12. exec_prefix=${prefix}
  13. php_fpm_BIN=${exec_prefix}/sbin/php-fpm
  14. php_fpm_CONF=${prefix}/etc/php-fpm.conf
  15. php_fpm_PID=${prefix}/var/run/php-fpm.pid
  16. php_opts="--fpm-config $php_fpm_CONF --pid $php_fpm_PID"
  17. wait_for_pid () {
  18. try=0
  19. while test $try -lt 35 ; do
  20. case "$1" in
  21. 'created')
  22. if [ -f "$2" ] ; then
  23. try=''
  24. break
  25. fi
  26. ;;
  27. 'removed')
  28. if [ ! -f "$2" ] ; then
  29. try=''
  30. break
  31. fi
  32. ;;
  33. esac
  34. echo -n .
  35. try=`expr $try + 1`
  36. sleep 1
  37. done
  38. }
  39. case "$1" in
  40. start)
  41. echo -n "Starting php-fpm "
  42. $php_fpm_BIN --daemonize $php_opts
  43. if [ "$?" != 0 ] ; then
  44. echo " failed"
  45. exit 1
  46. fi
  47. wait_for_pid created $php_fpm_PID
  48. if [ -n "$try" ] ; then
  49. echo " failed"
  50. exit 1
  51. else
  52. echo " done"
  53. fi
  54. ;;
  55. stop)
  56. echo -n "Gracefully shutting down php-fpm "
  57. if [ ! -r $php_fpm_PID ] ; then
  58. echo "warning, no pid file found - php-fpm is not running ?"
  59. exit 1
  60. fi
  61. kill -QUIT `cat $php_fpm_PID`
  62. wait_for_pid removed $php_fpm_PID
  63. if [ -n "$try" ] ; then
  64. echo " failed. Use force-quit"
  65. exit 1
  66. else
  67. echo " done"
  68. fi
  69. ;;
  70. force-quit)
  71. echo -n "Terminating php-fpm "
  72. if [ ! -r $php_fpm_PID ] ; then
  73. echo "warning, no pid file found - php-fpm is not running ?"
  74. exit 1
  75. fi
  76. kill -TERM `cat $php_fpm_PID`
  77. wait_for_pid removed $php_fpm_PID
  78. if [ -n "$try" ] ; then
  79. echo " failed"
  80. exit 1
  81. else
  82. echo " done"
  83. fi
  84. ;;
  85. restart)
  86. $0 stop
  87. $0 start
  88. ;;
  89. reload)
  90. echo -n "Reload service php-fpm "
  91. if [ ! -r $php_fpm_PID ] ; then
  92. echo "warning, no pid file found - php-fpm is not running ?"
  93. exit 1
  94. fi
  95. kill -USR2 `cat $php_fpm_PID`
  96. echo " done"
  97. ;;
  98. *)
  99. echo "Usage: $0 {start|stop|force-quit|restart|reload}"
  100. exit 1
  101. ;;
  102. esac

儲存,添加x許可權。

如需開機啟動:chkconfig php-fpm on


更多請支援:http://www.webyang.net/Html/web/article_129.html

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.