2010 年 10 月

浏览模式: 标准 | 列表 | 图文
Installing PHP 5.3, Nginx And PHP-fpm On Ubuntu/Debian

Installing PHP 5.3, Nginx And PHP-fpm On Ubuntu/Debian

Since Apache is most of the time a memory hungy process, people started to look for different ways to host their website. Apache is clearly not the only webserver available. A few good examples are lighttpd and nginx. In this tutorial I will show you how to install it on your Ubuntu server. This tutorial also applies to Debian, though. There is only a very small difference.

Ready? Let's begin shall we.

Step 0 - Preliminary Notes

In order to complete this tutorial, I assume you have installed a base system of Debian or Ubuntu. How this can be done, can be read in different tutorials. This tutorial only focusses on getting nginx+php running without much hassle.

Step 1 - Nginx

Installing nginx is the first step we have to do. This can be easily done by downloading it from the repository.

sudo apt-get install nginx

The default vhost has to be changed in order to work properly.

sudo vim /etc/nginx/sites-available/default

A nice starting point for your config is:

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;
}
k, we're done here. Now we'll install the needed files for PHP.

Step 2 - Installing PHP

Many sites rely on PHP for providing them dynamic content, whether this is a wiki, forum software, weblog or something entirely different.

If you are running Ubuntu, we first have to resolve two dependencies required for the dotdeb packages. If you are running the amd64 version, you should replace i386 with amd64.

For Debian you won't have to do this!

cd /tmp

wget http://us.archive.ubuntu.com/ubuntu/pool/main/k/krb5/libkrb53_1.6.dfsg.4~beta1-5ubuntu2_i386.deb

wget http://us.archive.ubuntu.com/ubuntu/pool/main/i/icu/libicu38_3.8-6ubuntu0.2_i386.deb

sudo dpkg -i *.deb

Again, this is only required if you're on Ubuntu.

The rest of the tutorial applies to both Ubuntu & Debian.

We'll have to add the dotdeb repository to the APT sources, so we can use their packaged PHP 5.3 and php-fpm:

sudo echo "deb http://php53.dotdeb.org stable all" >> /etc/apt/sources.list

Update apt:

sudo apt-get update

The resulting text should include dotdeb.

Now we'll install PHP (part 1):

sudo apt-get install php5-cli php5-common php5-suhosin

We have to install the cli before the rest, because this will cause problems later on.

sudo apt-get install php5-fpm php5-cgi

If you are planning to use a database or require specific modules (mcrypt, ldap, snmp etc) you can install them as well.

Ok, so now we have nginx and PHP.

One minor remark: If you are using "php short tags" (<?) you should enable them in your php.ini files (for both fpm and cli). If you do not change this, you will see your code in plain text!

Step 3 - Finalizing

Restart nginx in order to catch up with the config changes we made earlier.

sudo /etc/init.d/nginx restart

The restart should have gone without any problems.

After installing php5-fpm, it should have been started. If you did change your php.ini files, you have to restart php5-fpm.

sudo /etc/init.d/php5-fpm restart

All right. They should now both be running.

Step 4 - Testing

In order to test if the execution of PHP is working, create an index.php file in /var/www with the following content:

<?php phpinfo(); ?>

Visit your webserver and you should be able to see the generated phpinfo. If not, something went wrong.

Step 5 - Troubleshooting & Final notes

If you did not see the phpinfo, there might be something wrong. In order to track down what went wrong, you can check the nginx error log:

sudo tail /var/log/nginx/error.log

Remember, if you did change your php.ini you have to restart php5-fpm. Restarting nginx isn't' necessary.

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.

原文地址为:http://www.howtoforge.com/installing-php-5.3-nginx-and-php-fpm-on-ubuntu-debian

事实上,如果你真的按照本文所说的去安装,好象是不能成功的。好象默认nginx不在ubuntu的包里。

原文中还有三篇相关文章,如果有兴趣,可以看一下:

有些东西还是可以看看的,但如果是纯操作没有讲解,其实意义不大,终究只是知其然不知其所以然
为NeatPIC目录直读版建群

为NeatPIC目录直读版建群

虽然neatpic的功能不强大,我的时间也不是特别多。
但我还是准备为它建立一个QQ群,接受需求和发布版本。

目前我本地的版本还没有发布,基本上也就是实现了我在博客里说的一些新功能。
准备发布两种版本,一种是尽量用上PHP5的特性的。一种是面向过程的。(其实所谓用上php5特性的也差不多面向过程)

当然还是采用模版和楥存,也会生成缩略图,方便展示。
同时代码仍然采用开源方式发布,也没有什么授权不授权的。
不管你是商用也好非商用也好,都无所谓了。保留一个版权,留下本站一个链接就行,其他无所谓

QQ群号:4278705,加入时需要暗号:neatstudio
防止茶农进驻。。

委琐记

委琐记

一大早上班,QQ群里就不停的在弹#小月月#,很是吃惊,仿佛感觉自己好象错过了什么,然而上天总还是眷顾我的,又有不少人在群里友情发出了小月月故事的网址,于是我也本着不愿独享的心情,将它公布到了我的微博上,但毕竟微博收藏的人不多,不如我的勃客收藏的量大,于是乎。。。

在这里我还是公布一下。。要知道,这可是传说中的脱水版,不要忍受猫扑天涯那种无尽回复的楼层,直接看的就是精华所在。原文名称是:国庆悲情游拜月教主小月月脱水版合集,链接地址为:http://game.zol.com.cn/198/1986010.html,一般建议是在肚子饿的时候看。当然如果看过那些什么 蓬蓬头啦,两女一杯之类的毫无反应的,可以直接观看,不会对你们的生理造成很大的伤害,否则,建议你们还是先冷静下来再观看,以免发生不测。

顺便,看的时候可以手里拿罐啤酒,看完后,你会发现,啤酒已经冰镇完毕。

最后,上一个验证码。。好意外的验证码,到现在我也只碰过这么一次哦:

1a5a51923b95df99c979ca61bb0bf23e

运气还是不错的

用谷歌浏览器来当手机模拟器

用谷歌浏览器来当手机模拟器

张宴在自己的博客里写着用《用谷歌浏览器来当手机模拟器》,看完后发现是模拟了User-Agent,这个其实在很早以前大家就都玩过类似的功能,只是,我们没有系统的拿出来说而已。

果然,光会用是没用的,还得会写会说。比如当QQ微博刚出来的时候,大家就在考虑怎么着能够发图片,于是乎opera模拟user-agent出来了,Firefox等的模拟也出来了。但这种技巧也就仅仅流传在微博上,而没有上升到文字的高度,可是,张宴他集中出来了。

---start

  很多网站都通过User-Agent来判断浏览器类型,如果是3G手机,显示手机页面内容,如果是普通浏览器,显示普通网页内容。

谷歌Chrome浏览器,可以很方便地用来当3G手机模拟器。在Windows的【开始】-->【运行】中输入以下命令,启动谷歌浏览器,即可模拟相应手机的浏览器去访问3G手机网页:

谷歌Android:

chrome.exe --user-agent="Mozilla/5.0 (Linux; U; Android 2.2; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1"
苹果iPhone:
chrome.exe --user-agent="Mozilla/5.0 (iPad; U; CPU OS 3_2_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B500 Safari/531.21.10"
诺基亚N97:
chrome.exe --user-agent="Mozilla/5.0 (SymbianOS/9.4; Series60/5.0 NokiaN97-1/20.0.019; Profile/MIDP-2.1 Configuration/CLDC-1.1) AppleWebKit/525 (KHTML, like Gecko) BrowserNG/7.1.18124"

试一试,分别用Android、iPhone、诺基亚访问http://www.163.com/、http://blog.s135.com/、http://www.google.com.hk/、http://3g.qq.com、http://t.sina.cn这些3G手机网页,看看有什么不同。

更多款手机的User-Agent:http://www.zytrax.com/tech/web/mobile_ids.html

----EOF--

以上功能对于我们firefox用户来说就没辙了,但并不是不可以使用,比如我们有一个很强大的addon,那就是:Nightly Tester Tools。这个工具可是非常强大哦,想更改啥都可,以前写过两篇介绍性的博客,其中一篇为介绍,一篇为应用

1、UserAgent分析

2、google notebook。。。

Zend Studio 8.0 Beta 2: Virtualize Your PHP Development with VMware Workstation Integration

这是我收到的zendstudio发的邮件,我并非是为了宣传那个coupon code,而是被这个标题所吸引。。那就是现在的标题。
看内容吧(list one才是重点):

We've just launched the Beta 2 release of Zend Studio 8.0! This release adds exciting new capabilities to the industry-leading PHP IDE:

• Run and debug your PHP application in a virtual, production-like environment right from the Zend Studio interface with new VMware Workstation integration
• Develop your JavaScript code faster with Content Assist support for jQuery, Dojo, ExtJs, and Prototype
• Debug JavaScript front-end code and PHP back-end code in a single, unified debugging session, through a new set of integrated Ajax tools
• Develop projects over a remote server transparently with revamped remote system support
• Navigate through and edit your source code more quickly and smoothly thanks to enhancements throughout the interface

To celebrate this exciting new beta release, Zend is offering a 25% discount* on online purchases of Zend Studio 7.2 made before October 31st! Take this opportunity to start using the top-ranking PHP IDE (as scored by InfoWorld) at a great price, and your license will include a free upgrade to Zend Studio 8 once it's officially released.

Download Zend Studio 8.0 Beta

* Use coupon code CELEBRATE during checkout

Happy PHPing,
Zend - the PHP Company

失而复得的外套

失而复得的外套

超市购物。老婆带着小孩子去玩,我在和朋友谈点事情,忽然电话过来说是衣服不见了,可能是掉地上被人捡了吧?正好小孩要睡觉,于是乎,带到咖啡厅睡了一会,醒来后去超市问了一下营业员,还真的捡到了,经过一些手续拿到了衣服(过程有点复杂,回家用电脑再详细描述)
......
衣服是在超市丢掉的。然后睡醒后去找,事情就这样发生了。。。。
先到总服务台咨询一下,服务台告诉我没这么快建议我们去收银台旁边的服务台咨询一下。进了超市后,到了小朋友玩的时间最长的那个地方问了一下所在区域的服务员,好象是一个领班,帮忙问了一下,然后好几个服务员说是看到了衣服,并说了衣服存放的位置,然后发现衣服又不见了。再问其他的营业员,说,仿佛是给那些卖衣服的柜台去了(以为是别人在卖衣服的柜台拿了衣服,但临时没有购买随便扔在其他位置了)。
那位领班又去卖衣服的柜台帮忙问了一下,等了好久才回来,同时把衣服拿回来了,说是原来卖衣服的人也换班了,问了好几个人,再打电话给那位下班的同事才确认衣服的。
于是一件衣服失而复得。感谢超市的领班和服务员们。谢谢了。通过这件事也让我感觉到家乡的这种气氛变得好很多,放在几年前,80%就不见了。。

自 WAP 发表

happy birthday to myself

happy birthday to myself

a怎么着今天也算是自己的阴历生日,又正好在长假期间,约上三五好友过来吃饭喝酒。其实挺开心的。一转眼三十多了。人生三分之一已经过去了。

自 WAP 发表
经常打不开WEB?

经常打不开WEB?

最近单位的服务器好象经常出点事,苦于没有运维啊。灰常痛苦。
症状如下,先是网通的朋友说打不开,后来能打开,然后在公司里全部能够打开,河北人民告诉我,电信3G能打开,网通不行,南方的人民告诉我打得开。然而,唯一让人郁闷的是老板打不开。。。

不知道什么原因,然后因为服务器是做了LVS负载均衡,理论上应该没事,web服务器中php的进程也很正常。两台WEB服务器的nginx配置文件检查了一下,没发现啥问题,后来用tail /xxx/xxx/xxx.log看了一下,居然报配置文件出错,打开文件一看,居然有一行被注释的内容断行了,造成部分内容没有被注释,引起了错误,于是删除并重启nginx。

再后来就正常了,可是到晚上,又突然有人说出现502错误了,象这种情况,大多数是php-cgi进程要么超时,要么数量不够要么。。。苦于没有运维,我唯一能做的就是重启了一下WEB(一些配置文件都不在家,否则可以尝试只重启nginx和php-cgi)。

有人问过我为什么不升级到php5.3,说实话,我真的很想升啊。可惜用的代码中,有部分关键代码占用了5.3的关键字(好象以前在博客里说过,函数名居然叫namespace。于是,我傻眼了)

ThinkInLamp群中的hm说5.3自带的fastcgi好象不太稳定,反正我也没法升级,就随便看着喽(想着他们居然有时间有精力看nginx等的源码,心里就觉得非常佩服)

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

越往后越发现自己的能力欠缺,比如说开发都要了解linux的常规操作,但事实上,常规操作都会了,但一些更深层次的不深入也不行啊。不再深入一点,就无法真正从底层上进行性能调优等(纯PHP代码的调优,终究是有限度的)