`

Ubuntu 11.04 安装 Nginx + PHP5 + Mysql

阅读更多

首先切换root用户,终端输入命令:

sudo su

默认root没有密码 直接输入命令就可以切换到root用户。

用这个命令 可以设置root密码:

sudo passwd root

 

1.安装 mysql

apt-get install mysql-server mysql-client

 

2.安装 nginx

apt-get install nginx

 

启动nginx命令:

/etc/init.d/nginx start

浏览器输入127.0.0.1 测试nginx是否正常运行。

 

在ubuntu11.04中nginx 默认网站目录为

/usr/share/nginx/www

 

3.安装PHP5

apt-get install php5-fpm

PHP – FPM是一个守护进程(与初始化脚本 / etc/init.d/php5-fpm )运行FastCGI服务器上的端口 9000 。

 

4.nginx配置

 

修改虚拟主机配置文件

地址: /etc/nginx/sites-available/default

 

下面DEMO为参考:

  server {

  listen 80; ## listen for ipv4; this line is default and implied

  listen [::]:80 default ipv6only=on; ## listen for ipv6

  root /usr/share/nginx/www;

  index index.php index.html index.htm;

  # Make site accessible from http://localhost/

  server_name  localhost;

  location / {

  # First attempt to serve request as file, then

  # as directory, then fall back to index.html

  try_files $uri $uri/ /index.html;

  }

  location /doc {

  root /usr/share;

  autoindex on;

  allow 127.0.0.1;

  deny all;

  }

  location /images {

  root /usr/share;

  autoindex off;

  }

  #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 /usr/share/nginx/www;

  }

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

  include fastcgi_params;

  }

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

  # concurs with nginx’s one

  #

  location ~ /\.ht {

  deny all;

  }

  }


 

然后保存文件并重新启动nginx的:

/etc/init.d/nginx restart

 

试一试php是否正常运行。

测试phpinfo()

 

剩下安装php扩展软件:

apt-get install php5-mysql php5-curl php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl

 

现在重新启动PHP-FPM:

/etc/init.d/php5-fpm restart

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics