安装nginx并配置php环境
2013-06-18 22:03
477 查看
环境:
Linux ubuntu 3.2.0-23-generic-pae
Ubuntu下安装nginx+php+FastCGI
1. 安装nginx
使用命令安装:
#sudo apt-get install nginx
Nginx的启动和停止:
/etc/init.d/nginx start/stop/restart
Service nginx start/stop
2. 修改nginx的配置
#vi /etc/nginx/sites-availavle/default
内容修改如下:
server {
listen 80;
server_name localhost;
root /var/www;
index index.php index.html index.htm;
access_log /var/log/nginx/localhost.access.log;
location / {
root /var/www;
index index.php index.html index.htm;
}
location /doc {
root /usr/share;
autoindex on;
allow 127.0.0.1;
deny all;
}
#location /images {
#root /usr/share;
#autoindex on;
#}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
#proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
配置完成,重新启动nginx
测试:
在/var/www下编辑index.html文件:
Vi index.html
加入如下内容:
Hello world!!!
保存,关闭
然后再浏览器中输入http://localhost/index.html,如果能够访问,则配置成功
3. 安装php环境
PHP5通过FastCGI在nginx下运行。ubuntu提供一个FastCGI-enabled PHP5 安装包,可以这样安装。
apt-get install php5-cgi php5-mysql php5-curl php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-mhash php5-ming php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl
打开 /etc/php5/cgi/php.ini 配置文件,修改cgi.fix_pathinfo=1
4. 安装FastCGI
Ubuntu没有独立的FastCGI安装包,所以用lighttpd里面的spawn-fcgi,运行下面命令:
#apt-get install lighttpd
安装完成时会出现lighttpd无法启动的错误,因为nginx占用了80端口。运行
#update-rc.d -f lighttpd remove
使lighttpd开机不启动。
我们安装lighttpd只需要其中的/usr/bin/spawn-fcgi,来运行FastCGI进程。运行
spawn-fcgi --help 查看它的命令。
以用户www-data在本机localhost的9000端口下运行一个PHP FastCGI进程,输入以下命 令:
#/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u www-data -g www-data -f /usr/bin/php5-cgi -P /var/run/fastcgi-php.pid
加入开机运行,以免每次开机运行此命令:
#vi /etc/rc.local
在最后一行加入下面语句(在exit前面):
/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u www-data -g www-data -f /usr/bin/php5-cgi -P /var/run/fastcgi-php.pid
5. 测试
在/var/www中添加index.php文件
Vi index.php
加入如下内容:
<?php
phpinfo();
?>
在访问php文件前,确保spawn-fcgi已经运行。
在浏览器中输入:http://localhost/index.php ,出现如下界面表示成功:
6.
Linux ubuntu 3.2.0-23-generic-pae
Ubuntu下安装nginx+php+FastCGI
1. 安装nginx
使用命令安装:
#sudo apt-get install nginx
Nginx的启动和停止:
/etc/init.d/nginx start/stop/restart
Service nginx start/stop
2. 修改nginx的配置
#vi /etc/nginx/sites-availavle/default
内容修改如下:
server {
listen 80;
server_name localhost;
root /var/www;
index index.php index.html index.htm;
access_log /var/log/nginx/localhost.access.log;
location / {
root /var/www;
index index.php index.html index.htm;
}
location /doc {
root /usr/share;
autoindex on;
allow 127.0.0.1;
deny all;
}
#location /images {
#root /usr/share;
#autoindex on;
#}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
#proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
配置完成,重新启动nginx
测试:
在/var/www下编辑index.html文件:
Vi index.html
加入如下内容:
Hello world!!!
保存,关闭
然后再浏览器中输入http://localhost/index.html,如果能够访问,则配置成功
3. 安装php环境
PHP5通过FastCGI在nginx下运行。ubuntu提供一个FastCGI-enabled PHP5 安装包,可以这样安装。
apt-get install php5-cgi php5-mysql php5-curl php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-mhash php5-ming php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl
打开 /etc/php5/cgi/php.ini 配置文件,修改cgi.fix_pathinfo=1
4. 安装FastCGI
Ubuntu没有独立的FastCGI安装包,所以用lighttpd里面的spawn-fcgi,运行下面命令:
#apt-get install lighttpd
安装完成时会出现lighttpd无法启动的错误,因为nginx占用了80端口。运行
#update-rc.d -f lighttpd remove
使lighttpd开机不启动。
我们安装lighttpd只需要其中的/usr/bin/spawn-fcgi,来运行FastCGI进程。运行
spawn-fcgi --help 查看它的命令。
以用户www-data在本机localhost的9000端口下运行一个PHP FastCGI进程,输入以下命 令:
#/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u www-data -g www-data -f /usr/bin/php5-cgi -P /var/run/fastcgi-php.pid
加入开机运行,以免每次开机运行此命令:
#vi /etc/rc.local
在最后一行加入下面语句(在exit前面):
/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u www-data -g www-data -f /usr/bin/php5-cgi -P /var/run/fastcgi-php.pid
5. 测试
在/var/www中添加index.php文件
Vi index.php
加入如下内容:
<?php
phpinfo();
?>
在访问php文件前,确保spawn-fcgi已经运行。
在浏览器中输入:http://localhost/index.php ,出现如下界面表示成功:
6.
相关文章推荐
- [PHP] Mac下homebrew安装及php.mysql.nginx环境安装及配置
- 阿里云CENTOS系统安装PHP+MYSQL+NGINX环境配置
- CentOS 7 安装php5.6,Nginx,Memcached环境及配置
- Linux下从零开始安装配置Nginx服务器+PHP开发环境
- win平台安装配置Nginx+php+mysql 环境
- Nginx学习以及PHP+Nginx的环境安装与配置
- CentOS6.3上安装与配置nginx+php+mysql环境
- amazon aws ec云Linux ami上安装配置Nginx+PHP+MySQL环境
- 5、CentOS 6.5系统安装配置Nginx-1.2.7+PHP-5.3.22环境
- win平台安装配置Nginx+php+mysql 环境
- Linux下安装php环境并且配置Nginx支持php-fpm模块
- PHP环境搭建(8)----nginx安装与配置
- Linux下安装php环境并且配置Nginx支持php-fpm模块
- Windows 下 Nginx + PHP + MySQL 开发环境安装与配置
- Linux下安装配置nginx+php+mysql环境
- mac下 home-brew安装及php,nginx环境安装及配置
- Gentoo 下安装与配置Nginx+ MySQL + PHP (fastcgi) 环境步骤分享
- Linux下安装php环境并且配置Nginx支持php-fpm模块
- 详解Linux下安装php环境并且配置Nginx支持php-fpm模块
- Linux下安装php环境并且配置Nginx支持php-fpm模块[www]