nginx+PHP+ mysql

环境说明: /0.5.33 + 5.2.4-2  +   5.0.51a

1. 安装Nginx.PHP和Mysql

  1. sudo apt-get install nginx
  2. sudo apt-get install php-pear php5-cli php5-common php5-xcache php5-cgi php5-mysql php5-gd
  3. sudo apt-get install mysql-server mysql-client

2. 从lighttpd中取得spawn-fcgi

  1. cd /home/hacder/
  2. sudo apt-get install lighttpd
  3. sudo cp /usr/bin/spawn-fcgi ./
  4. sudo apt-get remove lighttpd
  5. sudo mv spawn-fcgi /usr/bin/

如果发现不能安装,可以通过:

  1. sudo apt-get install lighttpd –fix-missing

或者更新一下安装源:

  1. apt-get update

3. 添加php-cgi启动脚本:

  1. vi /etc/init.d/php5-cgi

输入:

  1. #! /bin/sh
  2. DESC=php5-cgi
  3. NAME=php5-cgi
  4. case “$1″ in
  5. start)
  6. echo -n “Starting $DESC: “
  7. /usr/bin/spawn-fcgi -a 127.0.0.1 -p 2222 -u www-data -f /usr/bin/php5-cgi -C 100
  8. ;;
  9. stop)
  10. echo -n “Stopping $DESC: “
  11. pkill php5-cgi
  12. ;;
  13. *)
  14. N=/etc/init.d/$NAME
  15. echo “Usage: $N {start|stop}” >&2
  16. exit 1
  17. ;;
  18. esac
  19. exit 0

更改脚本权限为可以执行:

  1. chmod +x /etc/init.d/php5-cgi

启动php5-cgi:

  1. /etc/init.d/php5-cgi start

查看是否启动:

  1. ps -ef |grep php

4. 配置nginx:

  1. vi /etc/nginx/nginx.conf

修改内容为:

  1. user www-data;
  2. worker_processes  16;
  3. error_log  /var/log/nginx/error.log;
  4. pid        /var/run/nginx.pid;
  5. events {
  6. worker_connections  3060;
  7. }
  8. http {
  9. include       /etc/nginx/mime.types;
  10. default_type  application/octet-stream;
  11. #access_log /var/log/nginx/access.log;
  12. access_log  off;
  13. sendfile        on;
  14. #tcp_nopush     on;
  15. #keepalive_timeout  0;
  16. keepalive_timeout  65;
  17. tcp_nodelay        on;
  18. gzip  on;
  19. include /etc/nginx/sites-enabled/*;
  20. }

添加站点配置文件:

  1. vi /etc/nginx/sites-enabled/hacder.com
  1. server {
  2. server_name hacder.com;
  3. listen 80;
  4. #    access_log /var/log/nginx/hacder.com.access.log;
  5. gzip on;
  6. gzip_comp_level 9;
  7. client_max_body_size 10m;
  8. index index.html index.php;
  9. root /data/www/hacder.com;
  10. location ~ .*\.php$ {
  11. include /etc/nginx/fastcgi.conf;
  12. fastcgi_hide_header X-Powered-By;
  13. #        fastcgi_pass unix:/dev/shm/fcgi_php5.socket;
  14. fastcgi_pass 127.0.0.1:2222;
  15. fastcgi_index index.php;
  16. fastcgi_param SCRIPT_FILENAME /data/www/hacder.com$fastcgi_script_name;
  17. }
  18. location ~ .+\.[gif|jpg|jpeg|png|ico|rar] {
  19. expires 1M;
  20. }
  21. }

启动nginx:

  1. /etc/init.d/nginx start

6 . 配置mysql

默认的msyql数据文件保存位置是: /var/lib/msyql/
一般这个分区不会太大,也为了统一管理,我们需要更改msyql的位置:

  1. vi /etc/msyql/my.cnf

修改为:

  1. datadir         = /data/mysql

如果修改位置后,不能如常启动mysql的话,有可能是ubuntu的问题.这个问题我已经遇到两三次了,这个是找到的解决方案:

  1. sudo touch /etc/apparmor.d/disable/usr.sbin.mysqld
  2. sudo /etc/init.d/apparmor restart
  3. sudo /etc/init.d/mysql restart

稍微优化一下msyql:

  1. #
  2. # * Fine Tuning
  3. #
  4. key_buffer              = 2048M
  5. table_cache             = 2048
  6. max_connections         = 300
  7. tmp_table_size          = 512M
  8. max_heap_table_size     = 512M
  9. myisam_sort_buffer_size = 128M
  10. sort_buffer_size        = 1M
  11. record_buffer           = 16M
  12. read_buffer_size        = 1M
  13. read_rnd_buffer_size    = 8M
  14. query_cache_size        = 1024M
  15. thread_concurrency      = 8
  16. wait_timeout            = 60
  17. join_buffer_size        = 16M
  18. #open_files_limit        = 1024
  19. max_allowed_packet      = 16M
  20. thread_cache_size       = 64
  21. thread_stack            = 128K
  22. #max_connections        = 100
  23. #table_cache            = 64
  24. #thread_concurrency     = 10

启动msyql:

  1. /etc/init.d/msyql start

看来最近老是心神不定,以后还是得多加注意!做如何事情前都要多加考虑…
原创文章如转载,请注明:转载自 Hacder’s Lab [ http://www.hacder.cn ]

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

本文链接地址: http://www.ptubuntu.com/2008/11/500.html

Share

发表评论

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

*

您可以使用这些 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!