0、准备工作
Shell
1
|
sudo apt-get update
|
1、安装并开启Nginx
Shell
1
2
3
|
sudo apt-get intsall nginx
sudo /etc/init.d/nginx start
#此时访问localhost如出现"Welcome to Nginx!"页面则表明安装成功
|
2、安装mysql(会提示设置数据库密码)
Shell
1
|
sudo apt-get install mysql-server mysql-client
|
3、安装phpmyadmin并在虚拟主机根目录下建立软链接
Shell
1
2
|
sudo apt-get install phpmyadmin
sudo ln -s /usr/share/phpmyadmin/ /var/www/heaptech.com/ #/var/www/heaptech.com 即为虚拟主机位置
|
4、安装php
Shell
Press CTRL+C to Copy, CTRL+V to Paste
1
|
sudo apt-get install php5 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-tidy php5-xmlrpc php5-sqlite php5-xsl
|
5、安装spawn-fcgi(控制php5-cgi的)
Shell
Press CTRL+C to Copy, CTRL+V to Paste
1
|
sudo apt-get install spawn-fcgi
|
6、在Nginx中配置spawn-fcgi
Shell
1
2
|
#在/etc/nginx/fastcgi_params文件最后添加"fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;"
sudo sed -i '$ i fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;' /etc/nginx/fastcgi_params
|
7、修改php-cgi的配置文件,把cgi.fix_pathinfo设置为1
Shell
Press CTRL+C to Copy, CTRL+V to Paste
1
|
sudo sed -i '/cgi.fix_pathinfo=/ c cgi.fix_pathinfo=1;' /etc/php5/cgi/php.ini
|
8、开启fastcgi并设置开机启动
Shell
Press CTRL+C to Copy, CTRL+V to Paste
1
2
|
#1)开启
sudo /usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 5 -u www-data -g www-data -f /usr/bin/php5-cgi -P /var/run/fastcgi-php.pid
|
Shell
Press CTRL+C to Copy, CTRL+V to Paste
1
2
|
#2)设置开机启动,即在/etc/rc.local中添加"/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 5 -u www-data -g www-data -f /usr/bin/php5-cgi -P /var/run/fastcgi-php.pid"
sudo sed -i '/^exit/ i /usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 5 -u www-data -g www-data -f /usr/bin/php5-cgi -P /var/run/fastcgi-php.pid' /etc/rc.local
|
9、设置Nginx中虚拟主机配置(最重要的部分)
Shell
1
2
|
#1)建立一个虚拟主机配置文件
sudo vim /etc/nginx/sites-available/heaptech.com #文件名任意
|
Shell
location / {
index index.php;
}
location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include /etc/nginx/fastcgi_params;
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
#2)添加下方到内容
server {
listen 80; #WordPress的访问端口(默认80)
server_name heaptech.com www.heaptech.com; #主机名称,绑定的域名
root /var/www/heaptech.com; #虚拟主机根目录
location / {
index index.php;
}
location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include /etc/nginx/fastcgi_params;
}
}
|
Shell
1
2
|
#3)软链接至sites-enabled文件夹
sudo ln -s /etc/nginx/sites-available/heaptech.com /etc/nginx/sites-enabled/
|
10、安装wordpress
Shell
1
2
3
4
5
6
7
|
cd /var/www/heaptech.com #虚拟主机根目录
sudo wget http://wordpress.org/latest.tar.gz
sudo tar -zxvf latest.tar.gz
sudo mv wordpress/* .
sudo chmod -R 755 wp-content/ #权限问题还有一点不是很明白,欢迎指教(怎样最安全?)
sudo cp wp-config-sample.php wp-config.php
sudo sed -i -e 's/database_name_here/数据库名称/' -e 's/username_here/数据库用户名/' -e 's/password_here/数据库密码/' -e 's/localhost/主机名称/' -e '$ i define(‘WP_POST_REVISIONS’, false);' wp-config.php #需将命令中的中文替换为对应值
|
11、Last but not least
Shell
1
2
3
4
|
sudo /etc/init.d/nginx restart
#至此,所有安装工作全部完成
#http://heaptech.com即为blog地址
#http://heaptech.com/phpmyadmin/为phpmyadmin
|
转载自:http://huxuan.org/2010/08/05/linuxubuntu-nginx-mysql-phpfastcgi-phpmyadmin-wordpress/
如果以后为了省事的话可以用这个http://lnmp.org/index.html,LNMP一键安装包,我用的是Ubuntu10.04 server,