Ubuntu 9.04/9.10安装Nginx+Mysql+Php

安装平台基于 Ubuntu 9.04/9.10.使用 apt-get 简单安装.在安装之前你要准备好源.还有安装库 g++ vim ssh links 因为你要用到这些功具.

1、 Install Tools

#apt-get install g++ vim links ssh

2 安装 MySQL 5.0

#apt-get install mysql-server mysql-client

在安装这个过程中会提示让你输入MYSQL数据库的密码:

New password for the MySQL “root” user: <– yourrootsqlpassword 你的MYSQL密码

Repeat password for the MySQL “root” user: <– yourrootsqlpassword 你的MYSQL密码

3 安装 Nginx

#apt-get install nginx

启动nginx:

#/etc/init.d/nginx start

在你的浏览器输入 http://localhost

若看到 Welcome to nginx!,说明你已安装上了nginx了.接下来我们要来配置它.设置启动系统时会自动启动它.

root@ubuntu:~# update-rc.d nginx defaults    ------设置开机自启

System startup links for /etc/init.d/nginx already exist.

4、安装 PHP5

root@Ubuntu:~# 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

接下来要配置 php.ini 这个文件,在做一些配置文件之前最好你要做一个备份.

root@Ubuntu:~# cd /etc/php5/cgi/

root@Ubuntu:/etc/php5/cgi# ls

conf.d php.ini

root@Ubuntu:/etc/php5/cgi# cp php.ini php.ini.bak     (进行备份)

root@Ubuntu:/etc/php5/cgi# vi php.ini

php.ini 这个文件里添加下一行, 配置文件里面因该有此项,但是是被注释掉的,把前面的分号去掉,并且将值改为1

cgi.fix_pathinfo = 1

5,安装lighttpd

root@Ubuntu:# apt-get install lighttpd

安装完接下来要移除它的自动启动程序让它不自动启动.

root@Ubuntu:# update-rc.d -f lighttpd remove        -------不让其开机自启

Removing any system startup links for /etc/init.d/lighttpd …

/etc/rc0.d/K09lighttpd

/etc/rc1.d/K09lighttpd

/etc/rc2.d/S91lighttpd

/etc/rc3.d/S91lighttpd

/etc/rc4.d/S91lighttpd

/etc/rc5.d/S91lighttpd

/etc/rc6.d/K09lighttpd

开启 PHP FastCGI 设置听的端口9000上运行的本地用户和 www-data, 运行下面程序:

root@ubuntu:~# /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    -----------(重要的一步!)

spawn-fcgi.c.197: child spawned successfully: PID: 16273

修改 rc.local 这个文件.先备份一个.

root@Ubuntu:~# cp /etc/rc.local /etc/rc.local.bak

root@Ubuntu:~# 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

6 、配置Nginx(需要配置两个文件)

root@Ubuntu:/etc/nginx# cp nginx.conf nginx.conf.bak

root@Ubuntu:/etc/nginx# vi nginx.conf

修改如下

[...]

worker_processes 5;

[...]

keepalive_timeout 2;

[...]

说明:worker_processes指明了nginx要开启的进程数

配置sites-available/default

root@Ubuntu:/etc/nginx/sites-available# cp default default.bak

root@Ubuntu:/etc/nginx/sites-available# vi default

下面这个就是配置文档,斜体是添加修改:

root@Ubuntu:/etc/nginx/sites-available# vi default

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

# You may add here your

# server {

# …

# }

# statements for each of your virtual hosts

server {

listen 80;

server_name 192.168.2.13 localhost;                             # (这个可以不改,默认为 localhost)

access_log /var/log/nginx/localhost.access.log;

location / {

root /var/www/nginx-default;                                             #(你的根目录)

index index.php index.html index.htm;                            #(添加 PHP 的主页支持)

}

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;

}                                                                                          #(添加 PHP 的脚本支持)

#

#location ~ \.php$ {

#fastcgi_pass 127.0.0.1:9000;

#fastcgi_index index.php;

#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;

#includefastcgi_params;

#}

# deny access to .htaccess files, if Apache’s document root

# concurs with nginx’s one

#

#location ~ /\.ht {

#deny all;

#}

}

# another virtual host using mix of IP-, name-, and port-based configuration

#

#server {

#listen 8000;

#listen somename:8080;

#server_name somename alias another.alias;

#location / {

#root html;

#index index.html index.htm;

#}

#}

# HTTPS server

#

#server {

#listen 443;

#server_name localhost;

#ssl on;

#ssl_certificate cert.pem;

#ssl_certificate_key cert.key;

#ssl_session_timeout 5m;

#ssl_protocols SSLv2 SSLv3 TLSv1;

#ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;

#ssl_prefer_server_ciphers on;

#location / {

#root html;

#index index.html index.htm;

#}

#}

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

创建一个 info.php 页面.

#vi /var/www/nginx-default/info.php

<?php phpinfo(); ?>

重启nginx

root@Ubuntu:/etc/nginx/sites-available# /etc/init.d/nginx restart

root@Ubuntu:/var/www/nginx-default# /etc/init.d/lighttpd stop

这 lighttp 要关了.要不然会网页显示会给跑到这里来.因为nginx & ligttpd 两个同时打开也会发生冲突的.而这里我们只是用到 lighttp 的插件所以没有必要开启.

打开链接:http://localhost/info.php 若显示有 PHP 信息页:

PHP Version 5.2.10-2ubuntu6.4


System Linux gw-laptop 2.6.31-17-generic #54-Ubuntu SMP Thu Dec 10 16:20:31 UTC 2009 i686
Build Date Jan 6 2010 22:34:27
Server API CGI/FastCGI
.............................(还有很多)
则安装正常!
---------------------------------------------------------------------------------------------------

你可能感兴趣的:(ubuntu)