Ubuntu 9.04 Server 搭建Nginx+PHP5+MySQL完美We..
时间:2010-07-19 来源:garyybl
Nginx (发音:"engine x") 是一个高性能的HTTP和反向代理服务器,也是一个 IMAP/POP3/SMTP 代理服务器。Nginx是由Igor Sysoev为俄罗斯访问量第二的Rambler.ru站点开发的,它已经在该站点运行超过两年半了。Igor将源代码以类BSD许可证的形式发布。尽管还是测试版,但是,Nginx已经因为它的稳定性、丰富的功能集、示例配置文件和低系统资源的消耗而闻名了。
本文将和大家一起在Ubuntu 9.04 Server上快速搭建支持Nginx、PHP 5、MySQL的最佳Web服务器。文中使用的一些基础配置信息如下:
实际应用中,改为自己的相应配置即可。
另外,文本使用的多数命令均需要root权限,所以,开始之前最好用 sudo su 命令进入root权限。否则,每个命令前要用sudo。
1. 安装MySQL 5.0
Ubuntu/Debain中安装MySQL是比较方便的,只需要下面的一条命令就OK了,
New password for the MySQL "root" user: <-- yourrootsqlpassword
Repeat password for the MySQL "root" user: <-- yourrootsqlpassword
2. 安装Nginx
Nginx软件包在Ubuntu 9.04 软件包源中是有的,使用下面的命令安装它,
3. 安装PHP5
为了获得更好的性能,这里安装PHP5使用FastCGI模式,Ubuntu 9.04提供了FastCGI-enabled PHP5软件包,这样,所有安装都变得相当快捷。下面的命令安装了一组PHP5及PHP5相关模块的软件包,其中包括了FastCGI、php5-mysql、imagick、pear、加密相关模块等:
vi /etc/php5/cgi/php.ini
首先,安装lighttpd服务器,
Starting web server: lighttpd 2009-04-30 15:51:50: (network.c.300) can't bind to port: 80 Address already in use failed!
这是因为nginx启动后占用了80端口,不用管它,因为本来就不打算启动lighttpd的,下面把lighttpd从开机启动列表中删除:
下面的命令将启动一个监听9000端口、启动用户和组为www-data的PHP FastCGI守护进程:
vi /etc/rc.local
nginx服务器的配置文件位于 /etc/nginx/nginx.conf,使用编辑器打开它
首先,修改下面两个参数,
vi /var/www/nginx-default/info.php
本文将和大家一起在Ubuntu 9.04 Server上快速搭建支持Nginx、PHP 5、MySQL的最佳Web服务器。文中使用的一些基础配置信息如下:
- hostname:server1.example.com
- IP地址:192.168.0.100
实际应用中,改为自己的相应配置即可。
另外,文本使用的多数命令均需要root权限,所以,开始之前最好用 sudo su 命令进入root权限。否则,每个命令前要用sudo。
1. 安装MySQL 5.0
Ubuntu/Debain中安装MySQL是比较方便的,只需要下面的一条命令就OK了,
- aptitude install mysql-server mysql-client
New password for the MySQL "root" user: <-- yourrootsqlpassword
Repeat password for the MySQL "root" user: <-- yourrootsqlpassword
2. 安装Nginx
Nginx软件包在Ubuntu 9.04 软件包源中是有的,使用下面的命令安装它,
- aptitude install nginx
- /etc/init.d/nginx start
3. 安装PHP5
为了获得更好的性能,这里安装PHP5使用FastCGI模式,Ubuntu 9.04提供了FastCGI-enabled PHP5软件包,这样,所有安装都变得相当快捷。下面的命令安装了一组PHP5及PHP5相关模块的软件包,其中包括了FastCGI、php5-mysql、imagick、pear、加密相关模块等:
- aptitude 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
vi /etc/php5/cgi/php.ini
- ...
- cgi.fix_pathinfo = 1
首先,安装lighttpd服务器,
- aptitude install lighttpd
Starting web server: lighttpd 2009-04-30 15:51:50: (network.c.300) can't bind to port: 80 Address already in use failed!
这是因为nginx启动后占用了80端口,不用管它,因为本来就不打算启动lighttpd的,下面把lighttpd从开机启动列表中删除:
- update-rc.d -f lighttpd remove
下面的命令将启动一个监听9000端口、启动用户和组为www-data的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
- /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
nginx服务器的配置文件位于 /etc/nginx/nginx.conf,使用编辑器打开它
- vi /etc/nginx/nginx.conf
- http://wiki.codemongers.com/NginxFullExample
- http://wiki.codemongers.com/NginxFullExample2
首先,修改下面两个参数,
- ...
- worker_processes 5;
- keepalive_timeout 2;
- ...
- server {
- listen 80;
- server_name _;
-
- access_log /var/log/nginx/localhost.access.log;
-
- location / {
- root /var/www/nginx-default;
- 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/nginx-default;
- }
-
- # 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/nginx-default$fastcgi_script_name;
- include fastcgi_params;
- }
-
- # deny access to .htaccess files, if Apache's document root
- # concurs with nginx's one
- #
- location ~ /\.ht {
- deny all;
- }
- }
- /etc/init.d/nginx restart
vi /var/www/nginx-default/info.php
- <?php
- phpinfo();
- ?>
相关阅读 更多 +
排行榜 更多 +