Chinaunix首页 | 论坛 | 博客
  • 博客访问: 670217
  • 博文数量: 121
  • 博客积分: 1425
  • 博客等级: 中尉
  • 技术积分: 2059
  • 用 户 组: 普通用户
  • 注册时间: 2012-04-03 15:34
文章分类

全部博文(121)

文章存档

2018年(1)

2017年(2)

2016年(1)

2015年(11)

2014年(14)

2013年(47)

2012年(45)

分类: IT业界

2012-08-18 18:40:10

         LNMP:linux nginx mysql php (环境的搭建我也走了一些弯路,希望可以帮助你不要走弯路)
人家是这样说的:
    LNMP是指在linux系统下安装Nginx服务器、Mysql数据库、Php (Phpmyadmin)。
   Nginx是一个高性能的http、反向代理服务器,Nginx的特点就是轻便和高性能,非常适合低配置的VPS搭建网站服务器,Nginx相较于Apache、lighttpd具有占有内存少,稳定性高等优势,并且依靠并发能力强,丰富的模块库以及友好灵活的配置而闻名。 在Linux操作系统下,nginx使用epoll事件模型,得益于此,nginx在Linux操作系统下效率相当高。 
 
   Nginx 0.8.46 + PHP 5.2.14 (FastCGI) 可以承受3万以上的并发连接数,相当于同等环境下Apache的10倍。
 
使用Nginx处理静态请求,并将动态请求反向代理给apache,支持:SSL、Virtual Host、反向代理、ACL、URL 重写、访问日志。
 
LNAMP:linux Nginx Apache Mysql PHP ,实现负载均衡。
 
首先安装依赖包
#yum install gcc openssl-devel pcre-devel zlib-devel #安装编译安装的开发工具
怕麻烦的话也可以把这些安装上去
#yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype fretype-devel libxm12 libxm12-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel openssl openssl-devel pcre-devel
 

一、编译安装nginx-1.1.9.tar.gz

安装nginx

1.首先添加用户nginx,实现以之运行nginx服务进程:
# groupadd -r nginx
# useradd -r -g nginx -s /sbin/nologin -M nginx
下载nginx-1.1.9.tar.gz软件包,推荐下载地址为:也可以从其他网站获取。
#tar -xf nnginx-1.1.9.tar.gz--解压缩软件包
#cd nginx-1.1.9

接着开始编译和安装:
# ./configure \
--prefix=/usr \ --指定安装路径
--sbin-path=/usr/sbin/nginx \ --指定sbin安装路径
--conf-path=/etc/nginx/nginx.conf \ --指定nginx的配置文件路径
--error-log-path=/var/log/nginx/error.log \ --指定错误日志路径
--http-log-path=/var/log/nginx/access.log \ --指定访问日志路径
--pid-path=/var/run/nginx/nginx.pid \ --指定pid路径
--lock-path=/var/lock/nginx.lock \ --指定锁文件路径
--user=nginx \ --指定运行此服务的用户
--group=nginx \ --指定运行此服务的组
--with-http_ssl_module \ --编译安装上ssl模块
--with-http_flv_module \ --编译安装上flv模块
--with-http_stub_status_module \ --编译安装上status模块
--with-http_gzip_static_module \ --编译安装上static模块
--http-client-body-temp-path=/var/tmp/nginx/client/ \
--http-proxy-temp-path=/var/tmp/nginx/proxy/ \
--http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \ --启动fastcgi功能
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \
--http-scgi-temp-path=/var/tmp/nginx/scgi \
--with-pcre
# make && make install
 
2.为nginx提供SysV init脚本:
vim /etc/rc.d/init.d/nginx,内容如下:
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# config: /etc/sysconfig/nginx
# pidfile: /var/run/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/etc/nginx/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
make_dirs() {
# make required directories
user=`nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
options=`$nginx -V 2>&1 | grep 'configure arguments:'`
for opt in $options; do
if [ `echo $opt | grep '.*-temp-path'` ]; then
value=`echo $opt | cut -d "=" -f 2`
if [ ! -d "$value" ]; then
# echo "creating" $value
mkdir -p $value && chown -R $user $value
fi
fi
done
}
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
make_dirs
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
configtest || return $?
stop
sleep 1
start
}
reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac
而后为此脚本赋予执行权限:
# chmod +x /etc/rc.d/init.d/nginx
 
添加至服务管理列表,并让其开机自动启动:
# chkconfig --add nginx
# chkconfig nginx on
 
而后就可以启动服务并测试了:
# service nginx start
在浏览器中输入服务主机的IP地址或者网址,如果安装成功则会显示如下图所示的默认网页信息:
 
也可以这样配置一个站点
 
3.vim /etc/nginx/nginx.conf启用如下选项
 
 
 
4.vim /etc/nginx/fastcgi_params,将其内容更改为如下内容:
 

fastcgi_param GATEWAY_INTERFACE CGI/1.1;

fastcgi_param SERVER_SOFTWARE nginx;

fastcgi_param QUERY_STRING $query_string;

fastcgi_param REQUEST_METHOD $request_method;

fastcgi_param CONTENT_TYPE $content_type;

fastcgi_param CONTENT_LENGTH $content_length;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

fastcgi_param SCRIPT_NAME $fastcgi_script_name;

fastcgi_param REQUEST_URI $request_uri;

fastcgi_param DOCUMENT_URI $document_uri;

fastcgi_param DOCUMENT_ROOT $document_root;

fastcgi_param SERVER_PROTOCOL $server_protocol;

fastcgi_param REMOTE_ADDR $remote_addr;

fastcgi_param REMOTE_PORT $remote_port;

fastcgi_param SERVER_ADDR $server_addr;

fastcgi_param SERVER_PORT $server_port;

fastcgi_param SERVER_NAME $server_name;

 

而后重新载入nginx的配置文件:

# service nginx reload

 

netstat -tnlp #查看80端口此时是否有进程在用,若有下面需要关闭此占用80端口的进程

service httpd stop #80端口此时正在使用,则关闭httpd服务,以为httpdnginx服务同

时占用80端口会出冲突

service nginx start #开启nginx服务

5.查看nginx 配置文件,定义nginx虚拟主机

# /etc/ngxin/nginx.conf #nginx服务配置文件位置

这里可以添加nginx里面的虚拟主机:

server {

listen 8080;  #这个你可以自己定义

server_name IP:8080; #ip的话 也可以写个域名在这

root /www/myweb; #这个是你的站点存放路径

index index.php index.html;

 

location ~\.php$ {

root /www/myweb; #网页文件的目录

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;

include fastcgi_params;

}

 

测试一下 这个目录

#mkdir -pv /www/myweb

#cd /www/myweb

# vim index.html

hello welcome to zhangzhengxing #编辑器里面写的东西

#service nginx restart

 

二、编译安装mysql

1.下载mysql源码包

# mysql-5.5.20-linux2.6-i686.tar.gz 编译mysql之前我们需要去mysql官网查找最新版本的mysql源码包,可以根据自己的实际需要选择对应的源码包!

 

2.添加mysql系统用户和组

# groupadd -r mysql #添加mysql

# useradd -g mysql -r -s /sbin/nologin -M mysql #添加mysql用户

# id mysql 查看mysqlid信息

 

3.解压mysql源码包

# tar xvf mysql-5.5.20-linux2.6-i686.tar.gz -C /usr/local 解压在/usr/local

# cd /usr/local/

#ln -sv mysql-5.5.20-linux2.6-i686 mysql创建软连接

# chown -R mysql:mysql /mydata/data #改变存储mysql数据的目录属主属组为mysql

# cd /mysql --> chown -R mysql:mysql . #mysql属组属主改为mysql

#rpm -q mysql-server #初始化mysql之前确认系统上没有安装mysql-server rpm包,否则会冲突

 

# scripts/mysql_install_db --user=mysql --datadir=/mydata/data #用脚本初始化mysql

#chown -R root . # mysql 中的属主重新改为root,为了使mysql执行时添加安全保证。

 

4.mysql提供主配置文件

# cd /usr/local/mysql

# cp support-files/my-large.cnf /etc/my.cnf

# mysql提供主配置文件:

并修改此文件中thread_concurrency的值为你的CPU个数乘以2,比如这里使用如下行:

thread_concurrency = 2

另外还需要添加如下行指定mysql数据文件的存放位置:

datadir = /mydata/data

 

5.mysql提供sysv服务脚本

# cd /usr/local/mysql

# cp support-files/mysql.server /etc/rc.d/init.d/mysqld

# mysql提供sysv服务脚本:

添加至服务列表:

# chkconfig --add mysqld

# chkconfig --level 2345 mysqld on #添加了这个这几个运行级别都可以启动

而后就可以启动服务测试使用了。

# ls /mydata/data 里面有mysql的日志文件

 

6.优化mysql服务

#为了使用mysql的安装符合系统使用规范,并将其开发组件导出给系统使用,这里还需要进行如下步骤:

# ln -sv /usr/local/mysql/include /usr/include/mysql

#mysql创建头文件链接

# vim /etc/ld.so.conf.d/mysql.conf

/usr/local/mysql/lib

# ldconfig -v 重新加载一下 -v显示过程

 

7.mysql提供帮助文件

编辑/etc/man.config,添加如下行即可:

MANPATH /usr/local/mysql/man  #找到MANPATH 就可以添加了

 

8.修改mysql环境变量

修改PATH环境变量,让系统可以直接使用mysql的相关命令。具体实现过程这里不再给出。

# vim /etc/profile 添加下面一句:

export PATH=$PATH:/usr/local/apache/bin:/usr/local/mysql/bin

# source /etc/profile 重读配置文件

#service mysqld start

 

三、编译安装php

1解决依赖关系:

请配置好yum源(可以是本地系统光盘)后执行如下命令:

# yum -y groupinstall "X Software Development"

# yum -y groupinstall "Development Tools" #安装好开发组包工具

# yum -y groupinstall "Development Libraries"# 安装编译时依赖的库文件

如果想让编译的php支持mcryptmcryptmhash扩展和libevent,此处还需要下载如下几个rpm包并安装:

mcrypt-2.6.8-1.el5.i386.rpm

libmcrypt-2.5.7-5.el5.i386.rpm

libmcrypt-devel-2.5.7-5.el5.i386.rpm

mhash-0.9.2-6.el5.i386.rpm

mhash-devel-0.9.2-6.el5.i386.rpm

libevent-2.0.17-2.i386.rpm

libevent-devel-2.0.17-2.i386.rpm

最好使用升级的方式安装上面的rpm包,命令格式如下:

# rpm -Uvh *.rpm --nodeps #--nodeps 忽略依赖关系并升级安装

#rpm -Uvh  mcrypt-2.6.8-1.el5.i386.rpm libmcrypt-2.5.7-5.el5.i386.rpm  libmcrypt-devel-2.5.7-5.el5.i386.rpm mhash-0.9.2-6.el5.i386.rpm  mhash-devel-0.9.2-6.el5.i386.rpm event-2.0.17-2.i386.rpm libevent-devel-2.0.17-2.i386.rpm --nodeps

也可以这样来安装

wget
wget

wget

wget

wget

wget

wget

wget

wget

wget ftp://ftp.imagemagick.org/pub/ImageMagick/ImageMagick.tar.gz

wget

 

编译安装php所需的支持库

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

tar zxvf libiconv-1.13.1.tar.gz

cd libiconv-1.13.1/

./configure --prefix=/usr/local

make

make install

cd ../

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

tar zxvf libmcrypt-2.5.8.tar.gz 

cd libmcrypt-2.5.8/

./configure

make

make install

/sbin/ldconfig

cd libltdl/

./configure --enable-ltdl-install

make

make install

cd ../../

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

tar zxvf mhash-0.9.9.9.tar.gz

cd mhash-0.9.9.9/

./configure

make

make install

cd ../

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la

ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so

ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4

ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8

ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a

ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la

ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so

ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2

ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1

ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

tar zxvf mcrypt-2.6.8.tar.gz

cd mcrypt-2.6.8/

/sbin/ldconfig

./configure

make

make install

cd ../

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

编译安装PHP(FastCGI模式)

 cd php目录

./configure --prefix=/usr/local/php

 --with-config-file-path=/usr/local/php/etc

  --with-mysql=/usr/local/mysql

  --with-mysqli=/usr/local/mysql/bin/mysql_config 

  --with-iconv-dir=/usr/local 

  --with-freetype-dir 

  --with-jpeg-dir 

  --with-png-dir 

  --with-zlib 

  --with-libxml-dir=/usr 

  --enable-xml 

  --disable-rpath 

  --enable-discard-path 

  --enable-safe-mode

  --enable-bcmath 

  --enable-shmop 

  --enable-sysvsem 

  --enable-inline-optimization

  --with-curl --with-curlwrappers 

  --enable-mbregex 

  --enable-fastcgi 

  --enable-fpm 

  --enable-force-cgi-redirect 

  --enable-mbstring --with-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

make ZEND_EXTRA_LIBS='-liconv'

make install

cp php.ini-dist /usr/local/php/etc/php.ini 或者cp php.ini-production /usr/local/php/etc/php.ini

cd ../

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

编译安装PHP5扩展模块

》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》

tar zxvf memcache-2.2.5.tgz

cd memcache-2.2.5/

/usr/local/php/bin/phpize

./configure --with-php-config=/usr/local/php/bin/php-config

make

make install

cd ../

》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》

tar jxvf eaccelerator-0.9.6.1.tar.bz2

cd eaccelerator-0.9.6.1/

/usr/local/php/bin/phpize

./configure --enable-eaccelerator=shared \

 --with-php-config=/usr/local/php/bin/php-config

make

make install

cd ../

》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》

tar zxvf PDO_MYSQL-1.0.2.tgz

cd PDO_MYSQL-1.0.2/

/usr/local/php/bin/phpize

./configure --with-php-config=/usr/local/php/bin/php-config \

 --with-pdo-mysql=/usr/local/mysql

make

make install

cd ../

》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》

tar zxvf ImageMagick.tar.gz

cd ImageMagick-6.5.1-2/

./configure

make

make install

cd ../

》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》

tar zxvf imagick-2.3.0.tgz

cd imagick-2.3.0/

/usr/local/php/bin/phpize

./configure --with-php-config=/usr/local/php/bin/php-config

make

make install

cd ../

》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》

修改php.ini文件

手工修改:
查找/usr/local/php/etc/php.ini中的extension_dir = "./"
修改为
extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/"

增加以下几行
extension = "memcache.so"
extension = "pdo_mysql.so"
extension = "imagick.so"

再查找output_buffering = Off 修改为 On

再查找 ;cgi.fix_pathinfo=0 去掉“;”号,防止Nginx文件类型错误解析漏洞。

》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》

配置eAccelerator加速PHP:

mkdir -p /usr/local/eaccelerator_cache

vi /usr/local/php/etc/php.ini

跳到配置文件的最末尾,加上以下配置信息:

[eaccelerator]
zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so"
eaccelerator.shm_size="64"
eaccelerator.cache_dir="/usr/local/eaccelerator_cache"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="3600"
eaccelerator.shm_prune_period="3600"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"

》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》

创建php-fpm配置文件(php-fpm是为PHP打的一个FastCGI管理补丁,可以平滑变更php.ini配置而无需重启php-cgi):
在/usr/local/php/etc/目录中创建php-fpm.conf文件:

rm -f /usr/local/php/etc/php-fpm.conf

vim /usr/local/php/etc/php-fpm.conf

................................................................

输入以下内容



All relative paths in this config are relative to php's install prefix


Pid file
/usr/local/php/logs/php-fpm.pid
Error log file
/usr/local/php/logs/php-fpm.log
Log level
notice
When this amount of php processes exited with SIGSEGV or SIGBUS ...
10
... in a less than this interval of time, a graceful restart will be initiated.
Useful to work around accidental curruptions in accelerator's shared memory.
1m
Time limit on waiting child's reaction on signals from master
5s
Set to 'no' to debug fpm
yes



Name of pool. Used in logs and stats.
default
Address to accept fastcgi requests on.
Valid syntax is 'ip.ad.re.ss:port' or just 'port' or '/path/to/unix/socket'
127.0.0.1:9000

Set listen(2) backlog
-1
Set permissions for unix socket, if one used.
In Linux read/write permissions must be set in order to allow connections from web server.
Many BSD-derrived systems allow connections regardless of permissions.


0666

Additional php.ini defines, specific to this pool of workers.

/usr/sbin/sendmail -t -i
0

Unix user of processes
www
Unix group of processes
www
Process manager settings

Sets style of controling worker process count.
Valid values are 'static' and 'apache-like'
static
Sets the limit on the number of simultaneous requests that will be served.
Equivalent to Apache MaxClients directive.
Equivalent to PHP_FCGI_CHILDREN environment in original php.fcgi
Used with any pm_style.
128
Settings group for 'apache-like' pm style

Sets the number of server processes created on startup.
Used only when 'apache-like' pm_style is selected
20
Sets the desired minimum number of idle server processes.
Used only when 'apache-like' pm_style is selected
5
Sets the desired maximum number of idle server processes.
Used only when 'apache-like' pm_style is selected
35

The timeout (in seconds) for serving a single request after which the worker process will be terminated
Should be used when 'max_execution_time' ini option does not stop script execution for some reason
'0s' means 'off'
0s
The timeout (in seconds) for serving of single request after which a php backtrace will be dumped to slow.log file
'0s' means 'off'
0s
The log file for slow requests
logs/slow.log
Set open file desc rlimit
65535
Set max core size rlimit
0
Chroot to this directory at the start, absolute path

Chdir to this directory at the start, absolute path

Redirect workers' stdout and stderr into main error log.
If not set, they will be redirected to /dev/null, according to FastCGI specs
yes
How much requests each process should execute before respawn.
Useful to work around memory leaks in 3rd party libraries.
For endless request processing please specify 0
Equivalent to PHP_FCGI_MAX_REQUESTS
1024
Comma separated list of ipv4 addresses of FastCGI clients that allowed to connect.
Equivalent to FCGI_WEB_SERVER_ADDRS environment in original php.fcgi (5.2.2+)
Makes sense only with AF_INET listening socket.
127.0.0.1
Pass environment variables like LD_LIBRARY_PATH
All $VARIABLEs are taken from current environment

$HOSTNAME
/usr/local/bin:/usr/bin:/bin
/tmp
/tmp
/tmp
$OSTYPE
$MACHTYPE
2



................................................................

》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》

启动php-cgi进程,监听127.0.0.1的9000端口,进程数为128(如果服务器内存小于3GB,可以只开启64个进程),用户为www:

ulimit -SHn 65535

/usr/local/php/sbin/php-fpm start

注意:如果要重启,可以使用 reload 命令

》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》

2、下载编译php源码包

首先下载php-5.3.6 源码包至本地目录,可根据需要下载对应的源码包。

# tar xf php-5.3.6.tar.bz2

# ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --enable-fpm --enable-sockets --enable-sysvshm --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-libxml-dir=/usr --enable-xml --with-mhash --with-mcrypt --with-config-file-path=/etc/php --with-config-file-scan-dir=/etc/php --with-bz2 --with-curl

说明:如果前面第1步解决依赖关系时安装mcrypt相关的两个rpm包,此./configure命令还可以带上—with-mcrypt选项以让php支持mycrpt扩展

# make && make install #编译之后可以执行make, 这里肯能会花费一会时间,根据你的cpu性能决定你编译的时间长短,请稍等!

 

3.php提供配置文件:

# cp php.ini-production /etc/php/php.ini #复制生成的配置文件并且自己重命名为php.ini

 

4.为php-fpm提供sysv 脚本

php-fpm提供Sysv init脚本,并将其添加至服务列表:

# cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm

# chmod +x /etc/rc.d/init.d/php-fpm #添加执行权限

# chkconfig --add php-fpm #php-fpm添加至服务中

# chkconfig --level 2345 php-fpm on

 

5.启动fastcgi

php-fpm提供配置文件:

# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

 

6.编辑php-fpm的配置文件:

# vim /usr/local/php/etc/php-fpm.conf

配置pm.的相关选项为你所需要的值,并启用pid文件(如下最后一行):

pm.max_children = 50

pm.start_servers = 5

pm.min_spare_servers = 2 #定义最少空闲的server个数

pm.max_spare_servers = 8 #定义最多空闲的server 个数

pid = /var/run/php-fpm.pid #此行尤为重要服务需要的pid 文件

 

 

7.启动php-fpm

# service php-fpm start

使用如下命令来验正(如果此命令输出有中几个php-fpm进程就说明启动成功了):

# ps aux | grep php-fpm


整合nginx和php5

vim /etc/nginx/fastcgi_params 将其内容更改为如下内容:

fastcgi_param GATEWAY_INTERFACE CGI/1.1;

fastcgi_param SERVER_SOFTWARE nginx;

fastcgi_param QUERY_STRING $query_string;

fastcgi_param REQUEST_METHOD $request_method;

fastcgi_param CONTENT_TYPE $content_type;

fastcgi_param CONTENT_LENGTH $content_length;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

fastcgi_param SCRIPT_NAME $fastcgi_script_name;

fastcgi_param REQUEST_URI $request_uri;

fastcgi_param DOCUMENT_URI $document_uri;

fastcgi_param DOCUMENT_ROOT $document_root;

fastcgi_param SERVER_PROTOCOL $server_protocol;

fastcgi_param REMOTE_ADDR $remote_addr;

fastcgi_param REMOTE_PORT $remote_port;

fastcgi_param SERVER_ADDR $server_addr;

fastcgi_param SERVER_PORT $server_port;

fastcgi_param SERVER_NAME $server_name;


在/usr/html新建info.php的测试页面,测试php是否能正常工作:

# cat > /usr/html/index.php << EOF


phpinfo();

?>

接着就可以通过浏览器访问此测试页面了


安装xcache,为php加速

1、下载源码包并编译安装

# tar xf xcache-1.3.2.tar.gz

# cd xcache-1.3.2

# /usr/local/php/bin/phpize

# ./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config

# make

# make install

 

安装结束时,会出现类似如下行:

Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/

2、编辑php.ini,整合php和xcache:

 

首先将xcache提供的样例配置导入php.ini

# cat xcache.ini >> /usr/local/php/lib/php.ini

 

说明:xcache.ini文件在xcache的源码目录中。

 

接下来编辑/usr/local/php/lib/php.ini,找到zend_extension开头的行,修改为如下行:

zend_extension = /usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/xcache.so

 

注意:如果php.ini文件中有多条zend_extension指令行,要确保此新增的行排在第一位。


3、重新启动php-fpm

# service php-fpm restart


可以帮助到你那是最好的(LNMP完成)


 

 

阅读(4744) | 评论(0) | 转发(0) |
0

上一篇:sed 学习01

下一篇:用u盘做开机的钥匙

给主人留下些什么吧!~~