安装PHP在nginx的平台上.基于ubuntu10.04的版本之上安装.安装过程看下面.
安装环境 0
在安装nginx之前必须有一个平台.下面是选择Ubuntu Lucid (10.04). 安装 nginx+php
安装Nginx 1
要先安装nginx.
sudo apt-get install nginx
修改默认的配置文件.
sudo vim /etc/nginx/sites-available/default
修改内容如下:
server {
listen 80;
server_name localhost;
access_log /var/log/nginx/localhost.access.log;
## Default location
location / {
root /var/www;
index index.php;
}
## Images and static content is treated different
location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
access_log off;
expires 30d;
root /var/www;
}
## Parse all .php file in the /var/www directory
location ~ .php$ {
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_pass backend;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www$fastcgi_script_name;
include fastcgi_params;
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_intercept_errors on;
fastcgi_ignore_client_abort off;
fastcgi_connect_timeout 60;
fastcgi_send_timeout 180;
fastcgi_read_timeout 180;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
}
## Disable viewing .htaccess & .htpassword
location ~ /\.ht {
deny all;
}
}
upstream backend {
server 127.0.0.1:9000;
}
Ok, 安装好上面的Nginx那么现在可以安装 PHP.
安装PHP 2
我们现在需要安装PHP程序.使用apt-get来安装.安装php5.3和dotdeb在ubuntu10.04的系统之上.
sudo apt-get update
安装 dotdeb.
现在我们安装 PHP (part 1):
sudo apt-get install php5-cli php5-common php5-suhosin
安装 cli 之前需要先安装 安装 PHP-FPM, 我们添加 PPA 因为他不会被支持安装.所以需要添加上去.
add-apt-repository ppa:brianmercer/php
sudo apt-get update && sudo apt-get install php5-fpm php5-cgi
如果你打算使用一个数据库或要求(mcrypt,的LDAP,SNMP的等),你可以安装它们以及具体的模块。
安装Finalizing 3
重装Nginx.c 以便我们修乞讨的配置才会生效.
sudo /etc/init.d/nginx restart
重新启动后应该没有什么大的问题.
php5-fpm安装后, 它应该可以正常工作. 如果你的php.ini 文件没有变动, 那么你重启一下 php5-fpm.
sudo /etc/init.d/php5-fpm restart
那么就可以正常运行.
测试 4
<?php phpinfo(); ?>
故障排除及最后附注 5
sudo tail /var/log/nginx/error.log
In my example config I’ve enabled the fastcgi error interception. If a serious error occurs (for instance a “cannot redeclare class xyz”), nginx can catch this page and show a “nice” error page that something went wrong. This way, there is less information given out in case something is going seriously wrong.
If you do not like this, you can turn it off.
If php5-fpm is not running, your PHP files cannot be parsed and nginx will show the user an error page.
Well, I guess we’re done and you are now able to serve PHP with your new nginx based webserver. Nginx is pretty nice and you can configure a lot. If you need rewrites, be aware that nginx does not work with .htaccess files. You will need to change your vhost settings in order for the rewrites to work.
原创文章,转载请注明: 转载自PT Ubuntu Blog