PHP 安装&配置

  • 安装
    编译安装前的准备
    提示:默认的php安装后gd不支持jpg,只支持gif、png、bmp。所以首先要安装gd库
    
    wget http://www.boutell.com/gd/http/gd-2.0.33.tar.gz
    tar zxvf gd-2.0.33.tar.gz
    cd gd-2.0.33
    ./configure --prefix=/usr/local/webserver/gd2/
    make && make install
    
    wget http://www.php.net/get/php-5.3.26.tar.gz/from/us2.php.net/mirror
    tar zxvf php-5.3.26.tar.gz
    cd php-5.3.26
    ./configure --prefix=/usr/local/webserver/php --enable-fpm --with-mysql=/usr/local/webserver/mysql \
    --with-mysqli=/usr/local/webserver/mysql/bin/mysql_config --with-config-file-path=/usr/local/webserver/php  \
    --with-openssl --enable-mbstring --with-zlib --enable-xml --with-gd=/usr/local/webserver/gd2/ --with-jpeg-dir  \
    --enable-bcmath --with-mcrypt --with-iconv --enable-pcntl --enable-shmop --enable-simplexml --enable-ftp
    make && make install
    
    cp php.ini-development /usr/local/webserver/php/php.ini
    
    
  • 配置
    1. php(php.ini)
        将  ;date.timezone =
        改为 date.timezone = prc
      
    2. php+nginx(nginx.conf)
        user  www www;
        worker_processes  1;
        events {
            worker_connections  1024;
        }
          http {
          include       mime.types;
          default_type  application/octet-stream;
          sendfile        on;
          keepalive_timeout  65;
          server {
              listen       80;
              server_name  192.168.65.144;
      
              #Prohibited under the data directory php file is accessed
              location ~ ^/(.*)/data/.*\.(php)?$
              {
                  return 404;
              }
      
              #Prohibited under the public directory php file is accessed
              location ~ ^/(.*)/public/.*\.(php)?$
              {
                  return 404;
              }
      
              #Prohibited under the themes directory php file is accessed
              location ~ ^/(.*)/themes/.*\.(php)?$
              {
                  return 404;
              }
      
              #Prohibited under the wap_themes directory php file is accessed
              location ~ ^/(.*)/wap_themes/.*\.(php)?$
              {
                  return 404;
              }
      
      
              #配置站点伪静态(此处配置好之后,需要在ecstore/config/config.php中修改“define('WITH_REWRITE',true);”)
              if ($request_uri ~ (.+?\.php)(|/.*)$ ){
                  break;                                                                                                                                  
              }
              if (!-e $request_filename) {
                  rewrite ^/(.*)$ /index.php/$1 last;
              }
      
      
              location / {
                  root   /data/www;
                  index  index.php index.html index.htm;
              }
              error_page   500 502 503 504  /50x.html;
              location = /50x.html {
                  root   html;
              }
              location ~ \.php {
                  root /data/www;
                  include        fastcgi_params;
                  set $real_script_name $fastcgi_script_name;
                  
                  #设置pathinfo
      
                  set $path_info "";
                  set $real_script_name $fastcgi_script_name;
                  if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
                      set $real_script_name $1;
                      set $path_info $2;
                  }
                  fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
      
                  fastcgi_param SCRIPT_NAME $real_script_name;
                  fastcgi_param PATH_INFO $path_info;
                  fastcgi_pass   127.0.0.1:9000;
                  fastcgi_index  index.php;
              }
          }
      
      
      }
      
    3. php+pathinfo(php.ini)
      enable_dl = On
      cgi.force_redirect = 0
      cgi.fix_pathinfo=1
      fastcgi.impersonate = 1
      cgi.rfc2616_headers = 1
      allow_url_fopen = On
      
  • 配置php-fpm启动脚本
    1. 编写脚本(vi /etc/init.d/php-fpm )
      #! /bin/sh
      
      ### BEGIN INIT INFO
      # Provides:          php-fpm
      # Required-Start:    $remote_fs $network
      # Required-Stop:     $remote_fs $network
      # Default-Start:     2 3 4 5
      # Default-Stop:      0 1 6
      # Short-Description: starts php-fpm
      # Description:       starts the PHP FastCGI Process Manager daemon
      ### END INIT INFO
      
      prefix=/usr/local/webserver/php
      
      php_fpm_BIN=${prefix}/sbin/php-fpm
      php_fpm_CONF=${prefix}/etc/php-fpm.conf
      php_fpm_PID=${prefix}/var/run/php-fpm.pid
      
      
      php_opts="--fpm-config $php_fpm_CONF"
      php_pid="--pid $php_fpm_PID"
      
      wait_for_pid () {
              try=0
      
              while test $try -lt 35 ; do
      
                      case "$1" in
                              'created')
                              if [ -f "$2" ] ; then
                                      try=''
                                      break
                              fi
                              ;;
      
                              'removed')
                              if [ ! -f "$2" ] ; then
                                      try=''
                                      break
                              fi
                              ;;
                      esac
      
                      echo -n .
                      try=`expr $try + 1`
                      sleep 1
      
              done
      
      }
      
      case "$1" in
              start)
                      echo -n "Starting php-fpm "
      
                      $php_fpm_BIN $php_opts $php_pid
      
                      if [ "$?" != 0 ] ; then
                              echo " failed"
                              exit 1
                      fi
      
                      wait_for_pid created $php_fpm_PID
      
                      if [ -n "$try" ] ; then
                              echo " failed"
                              exit 1
                      else
                              echo " done"
                      fi
              ;;
      
              stop)
                      echo -n "Gracefully shutting down php-fpm "
      
                      if [ ! -r $php_fpm_PID ] ; then
                              echo "warning, no pid file found - php-fpm is not running ?"
                              exit 1
                      fi
      
                      kill -QUIT `cat $php_fpm_PID`
      
                      wait_for_pid removed $php_fpm_PID
      
                      if [ -n "$try" ] ; then
                              echo " failed. Use force-exit"
                              exit 1
                      else
                              echo " done"
                      fi
                            ;;
      
              force-quit)
                      echo -n "Terminating php-fpm "
      
                      if [ ! -r $php_fpm_PID ] ; then
                              echo "warning, no pid file found - php-fpm is not running ?"
                              exit 1
                      fi
      
                      kill -TERM `cat $php_fpm_PID`
      
                      wait_for_pid removed $php_fpm_PID
      
                      if [ -n "$try" ] ; then
                              echo " failed"
                              exit 1
                      else
                              echo " done"
                      fi
              ;;
      
              restart)
                      $0 stop
                      $0 start
              ;;
      
              reload)
      
                      echo -n "Reload service php-fpm "
      
                      if [ ! -r $php_fpm_PID ] ; then
                              echo "warning, no pid file found - php-fpm is not running ?"
                              exit 1
                      fi
      
                      kill -USR2 `cat $php_fpm_PID`
      
                      echo " done"
              ;;
      
              *)
                      echo "Usage: $0 {start|stop|force-quit|restart|reload}"
                      exit 1
              ;;
      
      esac
      
    2. 赋予脚本执行权限
        cd /usr/local/webserver/php/etc && cp php-fpm.conf.default php-fpm.conf
        chmod +x /etc/init.d/php-fpm
      
    3. 设置开机启动
        /sbin/chkconfig php-fpm on
      
    4. 使用以下命令对php操作
        service php-fpm start
        service php-fpm stop
        service php-fpm restart
      
  • 检查php+nginx是否配置成功

    在nginx.conf文件中我配置了我的php工作目录/www,在此目录下建立文件phpinfo.php,然后运行查看内容。文件内容如下:

    <?php
    phpinfo();
    
    运行后的内容如下:
  • 解密工具
    1. 下载ZendGuardLoader-php-5.3-linux-glibc23-x86_64.tar.gz
    2. 安装
        tar zxvf ZendGuardLoader-php-5.3-linux-glibc23-x86_64.tar.gz
        cd ZendGuardLoader-php-5.3-linux-glibc23-x86_64/
        cp php-5.3.x/ZendGuardLoader.so /usr/local/webserver/php/ext/
      
    3. 配置
        打开php.ini,加入以下代码:
      
      [Zend Guard]
      ;/usr/local/webserver/php/ext/ZendGuardLoader.so  这个是你当时指定的zend的目录
      zend_extension=/usr/local/webserver/php/ext/ZendGuardLoader.so
      zend_loader.enable=1
      zend_loader.disable_licensing=0
      zend_loader.obfuscation_level_support=3
      zend_loader.license_path=
      
    4. 重启nginx 和 php-fpm,打开phpinfo查看如下图所示,证明配置成功:
提示:zend Guard 在ecstore非ego版时,可以不用安装

內容目录

上一个主题

NGINX 安装&配置

下一个主题

Ecstore部署安装

快速搜索

输入相关的模块,术语,类或者函数名称进行搜索