天天看点

nginx php mysql 安装配置_nginx+php+mysql安装配置

centos6.0上安装:nginx-1.0.8 + mysql-5.5.15 + php-5.3.8

1.mysql-5.5.15 的安装前面介绍过了,这里省略...

2.nginx-1.0.8 安装

安装pcre,我这里用系统自带的rpm包:

rpm -qa | grep pcre

rpm -ivh /media/Packages/pcre-devel-7.8-3.1.el6.i686.rpm

安装其他依赖包 :

rpm -qa | grep zlib

rpm -vih /media/Packages/zlib-devel-1.2.3-25.el6.i686.rpm

rpm -qa | grep openssl

yum -y install openssl-devel

(注:/media/目录是centos6.0光盘挂载的目录,yum用的是centos6.0系统自带的)

安装nginx:

useradd www

tar zxvf /home/aa/nginx-1.0.8.tar.gz -C /usr/src/

cd /usr/src/nginx-1.0.8/

./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module --user=www --group=www

make

make install

2.php-5.3.8安装

安装php所需依赖包:

rpm -ivh /media/Packages/libpng-devel-1.2.44-1.el6.i686.rpm

rpm -ivh /media/Packages/libjpeg-devel-6b-46.el6.i686.rpm

rpm -ivh /media/Packages/freetype-devel-2.3.11-5.el6.i686.rpm

rpm -ivh /media/Packages/fontconfig-devel-2.8.0-3.el6.i686.rpm

yum -y install gd

yum -y install gd-devel

rpm -vih /media/Packages/libxml2-devel-2.7.6-1.el6.i686.rpm

安装php:

tar zxvf /home/aa/php-5.3.8.tar.gz -C /usr/src/

cd /usr/src/php-5.3.8/

./configure --prefix=/usr/local/php/ --with-mysql=/usr/local/mysql/ --with-png-dir --with-jpeg-dir --with-freetype-dir --with-gd --with-zlib-dir --enable-gd-native-ttf --enable-mbstring --enable-sockets --with-config-file-path=/usr/local/php/etc/ --enable-fpm --enable-fastcgi --with-openssl --with-fpm-user=www --with-fpm-group=www --with-libxml-dir

make

make test

make install

(注:编译时也可以用--with-mysqli=mysqlnd代替--with-mysql=/usr/local/mysql/ ,从而指定mysql使用mysqlnd库、使用mysqli API)

cp php.ini-development /usr/local/php/etc/php.ini

cd /usr/local/php/etc/

cp php-fpm.conf.default php-fpm.conf

3.配置nginx与php

创建网站目录,我这里把网站放在/qikangwei/目录下:

mkdir /qikangwei/

chown -R www:www /qikangwei/

创建测试页:

vim index.php

phpinfo();

?>

chown www:www index.php

修改nginx.conf配置文件:

cd /usr/local/nginx/

vim conf/nginx.conf

location / {

root   /qikangwei/;

index  index.php index.html index.htm;

}

(网站根目录设为/qikangwei/,首页设置为index.php)

location ~ \.php$ {

root           /qikangwei/;

fastcgi_pass   127.0.0.1:9000;

fastcgi_index  index.php;

fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

include        fastcgi_params;

}

(去掉这段代码前面的#,将红色标注部分修改为网站根目录)

修改 php-fpm.conf 配置文件:

cd /usr/local/php/

vim etc/php-fpm.conf

pid = run/php-fpm.pid

error_log = log/php-fpm.log

log_level = notice

rlimit_files = 1024

listen.owner = www

listen.group = www

listen.mode = 0666

user = www

group = www

pm = dynamic

pm.max_children = 50

pm.start_servers = 20

pm.min_spare_servers = 5

pm.max_spare_servers = 35

pm.max_requests = 500

(去掉这些行前面的 ;)

启动nginx:

/usr/local/nginx/sbin/nginx

(注:若要测试nginx.conf配置文件是否修改正确,输入命令/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf

修改配置文件后,重启nginx,可输入kill -HUP `cat /usr/local/nginx/logs/nginx.pid`)

启动php-fpm:

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