ubuntu9.04 install nginx+mysql+php+phpmyadmin

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

下面这个就是我配置成功图.

nginx04

1 Install Tools

#apt-get install g++ vim links ssh

2 安装 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 安装

#apt-get install nginx
启动nginx:
#/etc/init.d/nginx start

在IE浏览器输入你的IP地址:://myip

root@ptubuntu:~# links ls.ptubuntu.com

nginx01

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

root@ptubuntu:~# update-rc.d nginx defaults

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

4 安装 5

root@ptubuntu:~# 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@ptubuntu:~# cd /etc/php5/cgi/
root@ptubuntu:/etc/php5/cgi# ls

conf.d  php.ini
root@ptubuntu:/etc/php5/cgi# cp php.ini php.ini.bak
root@ptubuntu:/etc/php5/cgi# vi php.ini

在php.ini这个文件里添加下一行

cgi.fix_pathinfo = 1

安装lighttpd

root@ptubuntu:# apt-get install lighttpd

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

root@ptubuntu:# 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@ptubuntu:# /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: 29470

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

root@ptubuntu:~# cp /etc/rc.local .
root@ptubuntu:~# 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

5 配置Nginx

root@ptubuntu:/etc/nginx# cp nginx.conf nginx.conf.bak
root@ptubuntu:/etc/nginx# vi nginx.conf
修改如下
[...]
worker_processes  5;
[...]
keepalive_timeout  2;
[...]

配置sites-available/default

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

下面这个就是我的配置文档,红色是添加修改:

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


# You may add here your
# server {
#    …
# }
# statements for each of your virtual hosts

server {
listen   80;
server_name  ls.ptubuntu.com localhost;

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;
}

#
#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@ptubuntu:/etc/nginx/sites-available# /etc/init.d/nginx restart
root@ptubuntu:/var/www/nginx-default# /etc/init.d/lighttpd stop
这lighttp 要关了.要不然会网页显示会给跑到这里来.因为nginx & ligttpd两个同时打开也会发生冲突的.而这里我们只是用到lighttp的插件所以没有必要开启.

安装成功后的示图如下:

nginx03

接下来要安装的是支持PHP mysql

root@ptubuntu:/usr/local/src# wget http://nchc.dl.sourceforge.net/sourceforge/phpmyadmin/phpMyAdmin-2.11.9.5-all-languages.tar.bz2
root@ptubuntu:/usr/local/src#
cp phpMyAdmin-2.11.9.5-all-languages.tar.bz2 /var/www/nginx-default/
root@ptubuntu:/usr/local/src#cd /var/www/nginx-default/
root@ptubuntu:/usr/local/src#tar xvf phpMyAdmin-2.11.9.5-all-languages.tar.bz2
root@ptubuntu:/usr/local/src#mv phpMyAdmin-2.11.9.5-all-languages phpmyadmin
root@ptubuntu:/usr/local/src#cd phpmyadmin/

接着修改配置文档.

root@ptubuntu:/usr/local/src#cp config.sample.inc.php config.inc.php

*/
$cfg['blowfish_secret'] = ‘ptubuntu’; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */    ptubuntu  改为你的mysql密码

/*
其他地方也就不用改了就可以使用了.

phpmyadmin

参考外文:http://www.howtoforge.com/installing-nginx-with-php5-and-mysql-support-on--8.10

原创文章,转载请注明: 转载自PT Ubuntu Blog

本文链接地址: http://www.ptubuntu.com/2009/04/2157.html

Share

{ 发表评论? }

  1. 会律博客

    一直都看到你研究LINUX,难道你是所谓的工程师?

  2. 111

    你这是8.04的配置还是9.04?
    2009年4月9日发表文章时9.04出来了么?

  3. 111

    哦.我说呢!!!我是个新手我想问一下,我现在用的9.04 server 按你说的这个咋架不起来呢~~~在PHP配置这一步出了问题
    “配置sites-available/default” 这一步我用VIM打开了default文件,也改过来了“但是退出保存时不对.用”:WQ”命没用!!保存不了解也退不出去!请问这是什么原因呢!!

    很感谢你能提供这样的文章,现在像这样关于NGINX的相关文章太少了,网上一堆一堆的都是IT搬运工!

  4. 111

    呵呵弄的差不多了“最后问一下“设置多个目录在哪个里设呀“像这样!
    1.com /var/www/web1
    2.com /var/www/web2
    3.com /var/www/web3

  5. 生活没借口

    is.ptubuntu.com/info.php 就打开下载了怎么回事。。。。。。

  6. ptubuntu

    @生活没借口:
    打错了吧.是
    ls不是is
    ls.ptubuntu.com/info.php
    如果你打开就会下载那说明你PHP没有配置正确哦.还有一个你要设置默认可以读取index.php这个要添加看清下面这个添加的.
    配置sites-available/default

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

    下面这个就是我的配置文档,红色是添加修改:

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

    # You may add here your
    # server {
    # …
    # }
    # statements for each of your virtual hosts

    server {
    listen 80;
    server_name ls.ptubuntu.com localhost;

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

    location / {
    root /var/www/nginx-default;
    index index.php index.html index.htm;

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>


Verify Code   If you cannot see the CheckCode image,please refresh the page again!