nginx + php + centos 6.3

2014年2月7日 22:34:52

PHP 5.5.9 http://cn2.php.net/distributions/php-5.5.9.tar.bz2

nginx 1.5.10 http://nginx.org/download/nginx-1.5.10.tar.gz

-------------------------------------------

php:

gd 

yum -y install gd-devel

php

./configure --prefix=/usr/local/web/php --with-config-file-path=/usr/local/web/php/etc --enable-fpm --enable-mbstring --with-gd --enable-sockets --enable-mysqlnd --with-mysql=mysqlnd --with-mysqli=mysqlnd

nginx:

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

注:

1.第2行,指定网站的根目录,就是指定第5行的$document_root值(如果location层没有这条指令,那么就使用外层的root指令值)

2.第3行,将所有请求转发给守护127.0.0.1:9000的进程

3.第5行,指定转发时将请求转发给哪个文件进行处理,这里 $document_root/index.php => /home/web/html/index.php

4.第6行,附带一些其它参数一并转发

 

出现 "file not found"问题:

root 指令值最好也定义一份在server块中,这样下文中如果用到$document_root时,就会自动定义为这个值

fastcgi_param 指令值不要写死,写成 

fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

参考: http://www.nginx.cn/562.html

----------------------------------

编译安装nginx时,问题解决:

如果单独安装pcre,那么./configure时要用到 --with-pcre=/pcre/sourcecode/path (pcre的源码解压缩后的文件夹路径)

不独立安装pcre的话, 只用 yum -y install pcre pcre-devel

ps, pcre是perl的正则库, nginx rewrite 的时候要用到正则表达式

 

安装完成后,会自动在/etc/init.d下生成启动脚本,文件名字为nginx,使用时可以serviec nginx start/stop.....

----------------------------------

2014年3月2日 14:03:37

php编译时的MYSQL相关配置(如果使用mysqlnd驱动,注意配置PHP.ini指明MYSQL和PHP交流用的socket文件路径,对MYSQL来说PHP也是一个客户端,客户端和MYSQL通信都是用socket文件通信的)

[root@ddd php-5.5.9]# ./configure --help | grep mysql
  --with-mysql=DIR        Include MySQL support.  DIR is the MySQL base
                          mysqlnd the MySQL native driver will be used
  --with-mysql-sock=SOCKPATH
  --with-mysqli=FILE      Include MySQLi support.  FILE is the path
                          to mysql_config.  If no value or mysqlnd is passed
  --enable-embedded-mysqli
  --with-pdo-mysql=DIR    PDO: MySQL support. DIR is the MySQL base directory
                          If no value or mysqlnd is passed as DIR, the
  --enable-mysqlnd        Enable mysqlnd explicitly, will be done implicitly
  --disable-mysqlnd-compression-support
                          Disable support for the MySQL compressed protocol in mysqlnd
  --with-zlib-dir=DIR     mysqlnd: Set the path to libz install prefix

-----------------------------------

php-fpm

启动php-fpm后,它会自动加载php的配置文件(没有也不报错)

下边是将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 
 12     prefix=/usr/local/web/php #编译PHP时的--prefix
 13     exec_prefix=${prefix}
 14 
 15     php_fpm_BIN=${exec_prefix}/sbin/php-fpm
 16     php_fpm_CONF=${prefix}/etc/php-fpm.conf
 17     php_fpm_PID=${prefix}/var/run/php-fpm.pid #要和php-fpm配置文件中的一致,用来找到当前进程号,然后结束它
 18 
 19 
 20     php_opts="--fpm-config $php_fpm_CONF"
 21 
 22 
 23     wait_for_pid () {
 24         try=0
 25 
 26         while test $try -lt 35 ; do
 27 
 28             case "$1" in
 29                 'created')
 30                 if [ -f "$2" ] ; then
 31                     try=''
 32                     break
 33                 fi
 34                 ;;
 35 
 36                 'removed')
 37                 if [ ! -f "$2" ] ; then
 38                     try=''
 39                     break
 40                 fi
 41                 ;;
 42             esac
 43 
 44             echo -n .
 45             try=`expr $try + 1`
 46             sleep 1
 47 
 48         done
 49 
 50     }
 51 
 52     case "$1" in
 53         start)
 54             echo -n "Starting php-fpm "
 55 
 56             $php_fpm_BIN $php_opts
 57 
 58             if [ "$?" != 0 ] ; then
 59                 echo " failed"
 60                 exit 1
 61             fi
 62 
 63             wait_for_pid created $php_fpm_PID
 64 
 65             if [ -n "$try" ] ; then
 66                 echo " failed"
 67                 exit 1
 68             else
 69                 echo " done"
 70             fi
 71         ;;
 72 
 73         stop)
 74             echo -n "Gracefully shutting down php-fpm "
 75 
 76             if [ ! -r $php_fpm_PID ] ; then
 77                 echo "warning, no pid file found - php-fpm is not running ?"
 78                 exit 1
 79             fi
 80 
 81             kill -QUIT `cat $php_fpm_PID`
 82 
 83             wait_for_pid removed $php_fpm_PID
 84 
 85             if [ -n "$try" ] ; then
 86                 echo " failed. Use force-exit"
 87                 exit 1
 88             else
 89                 echo " done"
 90             fi
 91         ;;
 92 
 93         force-quit)
 94             echo -n "Terminating php-fpm "
 95 
 96             if [ ! -r $php_fpm_PID ] ; then
 97                 echo "warning, no pid file found - php-fpm is not running ?"
 98                 exit 1
 99             fi
100 
101             kill -TERM `cat $php_fpm_PID`
102 
103             wait_for_pid removed $php_fpm_PID
104 
105             if [ -n "$try" ] ; then
106                 echo " failed"
107                 exit 1
108             else
109                 echo " done"
110             fi
111         ;;
112 
113         restart)
114             $0 stop
115             $0 start
116         ;;
117 
118         reload)
119 
120             echo -n "Reload service php-fpm "
121 
122             if [ ! -r $php_fpm_PID ] ; then
123                 echo "warning, no pid file found - php-fpm is not running ?"
124                 exit 1
125             fi
126 
127             kill -USR2 `cat $php_fpm_PID`
128 
129             echo " done"
130         ;;
131 
132         *)
133             echo "Usage: $0 {start|stop|force-quit|restart|reload}"
134             exit 1
135         ;;
136 
137     esac

注意,

1.第一行和第二行之间不要有空行,否则会提示错误(有的话,行首要用#注释)

[root@AY1402041644126082e5Z sbin]# ./php-fpmd start
-bash: ./php-fpmd: /bin/sh^M: bad interpreter: No such file or directory

2.修改第12行到17行的相应文件路径使之和配置文件的配置相对应

3.如果启动时端口被占用: netstat -apn | grep 9000 找到它,用killall kill -9 结束进程,再重新启动

4.php安装的所有路径中没有php.ini也照样可以执行php_info();当然,获取有些需要的配置时会出警告(如时区,mysql的socket路径等),所以PHP.ini和php-fpm.conf是相互配合的,缺一不可

5. 另一个bash(mac可用)

  1 #!/bin/sh
  2 #=======================================================================================
  3 # php-fpm - this script start and stop the php-fpm daemon
  4 #
  5 # chkconfig 35 on
  6 # description: php-fpm is a FastCGI web server.
  7 # processname: php-fpm
  8 # config: /usr/local/php/etc/php-fpm.conf
  9 # pidfile: /var/run/php-fpm.pid
 10 #=======================================================================================
 11 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
 12     
 13 BINFILE="/usr/sbin/php-fpm"
 14 CFGFILE="/etc/php-fpm.conf"
 15 PIDFILE="/var/run/php-fpm.pid"
 16 LOCKFILE="/var/lock/php-fpm.lock"
 17 INIFILE="/etc/php.ini"
 18     
 19 RETVAL=0
 20     
 21 start() {
 22     [[ -x $BINFILE ]] || exit 5
 23     [[ -f $CFGFILE ]] || exit 6
 24        
 25     $BINFILE -t >/dev/null 2>&1
 26        
 27     if [[ $? -ne 0 ]]; then
 28         echo "The php-fpm configure has error."
 29         return 1
 30     fi
 31        
 32     echo "Starting php-fpm......"
 33     sudo $BINFILE -c ${INIFILE} -y $CFGFILE -g ${PIDFILE}
 34     RETVAL=$?
 35     echo "ok~"
 36     [[ $RETVAL -eq 0 ]] && touch $LOCKFILE
 37        
 38     return $RETVAL
 39 }
 40     
 41 stop() {
 42     echo "Shutting down php-fpm......"
 43        
 44     if [[ -f $PIDFILE ]]; then
 45         kill -3 `cat ${PIDFILE}`
 46     else
 47         kill -3 `ps aux | grep php-fpm | awk '/master/{print $2}'`
 48     fi
 49        
 50     RETVAL=$?
 51     echo "ok~"
 52     [[ $RETVAL -eq 0 ]] && sudo rm -f $LOCKFILE $PIDFILE
 53        
 54     return $RETVAL
 55 }
 56     
 57 restart() {
 58     stop
 59     sleep 1
 60 
 61     start
 62     sleep 1
 63        
 64     RETVAL=$?  
 65     return $RETVAL
 66 }
 67     
 68 reload() {
 69     echo -n $"Reloading php-fpm......"
 70        
 71     if [[ -f $PIDFILE ]]; then
 72         kill -USR2 `cat ${PIDFILE}`
 73     else
 74         kill -USR2 `ps aux | grep php-fpm | awk '/master/{print $2}'`
 75     fi
 76        
 77     RETVAL=$?
 78     echo "ok~"
 79        
 80     return $RETVAL
 81 }
 82     
 83 case "$1" in
 84 start)
 85     start
 86     ;;
 87        
 88 stop)
 89     stop
 90     ;;
 91        
 92 restart)
 93     restart
 94     ;;
 95        
 96 reload)
 97     reload
 98     ;;
 99        
100 *)
101     echo "Usage: service php-fpm {start|stop|restart|reload}"
102     RETVAL=1
103 esac
104     
105 exit $RETVAL
View Code

 2016年4月18日 09:46:55 星期一

PHP7默认安装的模块: (在./configure时, 只配置--prefix=xxx参数, 其它--with, --enable都不写的情况下)

Core
ctype
date
dom
fileinfo
filter
hash
iconv
json
libxml
pcre
PDO
pdo_sqlite
Phar
posix
Reflection
session
SimpleXML
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter

 

2019-8-23 10:42:59 星期五

php 7.3.8 编译参数

因为需要使用php自动生成一些分享图片, 所以安装了图片相关的库

yum install -y libwebp libwebp-devel

 

./configure  --prefix=/usr/local/web/php-7.3.8 --enable-fpm --with-fpm-user=nginx --with-fpm-group=webserver --with-config-file-path=/usr/local/web/php-7.3.8/etc --enable-mbstring --enable-bcmath --enable-mysqlnd --enable-calendar --enable-sockets --enable-exif --with-mysqli=mysqlnd --with-curl --with-libxml-dir --with-openssl --with-zlib --with-bz2 --with-gd --with-webp-dir --with-jpeg-dir --with-png-dir --with-freetype-dir

 安装时,可能会提示内存不够, 通过给Linux创建swap交换空间来解决

dd if=/dev/zero of=/swap bs=1024 count=2048000
mkswap /swap
swapon /swap

参考:

https://www.cnblogs.com/jikexianfeng/p/6103500.html
https://www.cnblogs.com/luoahong/articles/9131870.html

https://blog.csdn.net/wulantian/article/details/36184943

posted @ 2014-02-07 22:44  myD  阅读(845)  评论(0编辑  收藏  举报