环境说明: nginx/0.5.33 +PHP 5.2.4-2 + mysql 5.0.51a
1. 安装Nginx.PHP和Mysql
- sudo apt-get install nginx
- sudo apt-get install php-pear php5-cli php5-common php5-xcache php5-cgi php5-mysql php5-gd
- sudo apt-get install mysql-server mysql-client
2. 从lighttpd中取得spawn-fcgi
- cd /home/hacder/
- sudo apt-get install lighttpd
- sudo cp /usr/bin/spawn-fcgi ./
- sudo apt-get remove lighttpd
- sudo mv spawn-fcgi /usr/bin/
如果发现不能安装,可以通过:
- sudo apt-get install lighttpd –fix-missing
或者更新一下安装源:
- apt-get update
3. 添加php-cgi启动脚本:
- vi /etc/init.d/php5-cgi
输入:
- #! /bin/sh
- DESC=php5-cgi
- NAME=php5-cgi
- case “$1″ in
- start)
- echo -n “Starting $DESC: “
- /usr/bin/spawn-fcgi -a 127.0.0.1 -p 2222 -u www-data -f /usr/bin/php5-cgi -C 100
- ;;
- stop)
- echo -n “Stopping $DESC: “
- pkill php5-cgi
- ;;
- *)
- N=/etc/init.d/$NAME
- echo “Usage: $N {start|stop}” >&2
- exit 1
- ;;
- esac
- exit 0
更改脚本权限为可以执行:
- chmod +x /etc/init.d/php5-cgi
启动php5-cgi:
- /etc/init.d/php5-cgi start
查看是否启动:
- ps -ef |grep php
4. 配置nginx:
- vi /etc/nginx/nginx.conf
修改内容为:
- user www-data;
- worker_processes 16;
- error_log /var/log/nginx/error.log;
- pid /var/run/nginx.pid;
- events {
- worker_connections 3060;
- }
- http {
- include /etc/nginx/mime.types;
- default_type application/octet-stream;
- #access_log /var/log/nginx/access.log;
- access_log off;
- sendfile on;
- #tcp_nopush on;
- #keepalive_timeout 0;
- keepalive_timeout 65;
- tcp_nodelay on;
- gzip on;
- include /etc/nginx/sites-enabled/*;
- }
添加站点配置文件:
- vi /etc/nginx/sites-enabled/hacder.com
- server {
- server_name hacder.com;
- listen 80;
- # access_log /var/log/nginx/hacder.com.access.log;
- gzip on;
- gzip_comp_level 9;
- client_max_body_size 10m;
- index index.html index.php;
- root /data/www/hacder.com;
- location ~ .*\.php$ {
- include /etc/nginx/fastcgi.conf;
- fastcgi_hide_header X-Powered-By;
- # fastcgi_pass unix:/dev/shm/fcgi_php5.socket;
- fastcgi_pass 127.0.0.1:2222;
- fastcgi_index index.php;
- fastcgi_param SCRIPT_FILENAME /data/www/hacder.com$fastcgi_script_name;
- }
- location ~ .+\.[gif|jpg|jpeg|png|ico|rar] {
- expires 1M;
- }
- }
启动nginx:
- /etc/init.d/nginx start
6 . 配置mysql
默认的msyql数据文件保存位置是: /var/lib/msyql/
一般这个分区不会太大,也为了统一管理,我们需要更改msyql的位置:
- vi /etc/msyql/my.cnf
修改为:
- datadir = /data/mysql
如果修改位置后,不能如常启动mysql的话,有可能是ubuntu的问题.这个问题我已经遇到两三次了,这个是找到的解决方案:
- sudo touch /etc/apparmor.d/disable/usr.sbin.mysqld
- sudo /etc/init.d/apparmor restart
- sudo /etc/init.d/mysql restart
稍微优化一下msyql:
- #
- # * Fine Tuning
- #
- key_buffer = 2048M
- table_cache = 2048
- max_connections = 300
- tmp_table_size = 512M
- max_heap_table_size = 512M
- myisam_sort_buffer_size = 128M
- sort_buffer_size = 1M
- record_buffer = 16M
- read_buffer_size = 1M
- read_rnd_buffer_size = 8M
- query_cache_size = 1024M
- thread_concurrency = 8
- wait_timeout = 60
- join_buffer_size = 16M
- #open_files_limit = 1024
- max_allowed_packet = 16M
- thread_cache_size = 64
- thread_stack = 128K
- #max_connections = 100
- #table_cache = 64
- #thread_concurrency = 10
启动msyql:
- /etc/init.d/msyql start
看来最近老是心神不定,以后还是得多加注意!做如何事情前都要多加考虑…
原创文章如转载,请注明:转载自 Hacder’s Lab [ http://www.hacder.cn ]
原创文章,转载请注明: 转载自PT Ubuntu Blog