0、准备工作
1sudo apt-get update
1、安装并开启Nginx
1sudo apt-get intsall nginx
2sudo /etc/init.d/nginx start
3#此时访问localhost如出现"Welcome to Nginx!"页面则表明安装成功
2、安装mysql(会提示设置数据库密码)
1sudo apt-get install mysql-server mysql-client
3、安装phpmyadmin并在虚拟主机根目录下建立软链接
1sudo apt-get install phpmyadmin
2sudo ln -s /usr/share/phpmyadmin/ /var/www/heaptech.com/ #/var/www/heaptech.com 即为虚拟主机位置
4、安装php
1sudo 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的)
1sudo apt-get install spawn-fcgi
6、在Nginx中配置spawn-fcgi
1#在/etc/nginx/fastcgi_params文件最后添加"fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;"
2sudo sed -i '$ i fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;' /etc/nginx/fastcgi_params
7、修改php-cgi的配置文件,把cgi.fix_pathinfo设置为1
1sudo sed -i '/cgi.fix_pathinfo=/ c cgi.fix_pathinfo=1;' /etc/php5/cgi/php.ini
8、开启fastcgi并设置开机启动
1#1)开启
2sudo /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
1#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"
2sudo 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中虚拟主机配置(最重要的部分)
1#1)建立一个虚拟主机配置文件
2sudo vim /etc/nginx/sites-available/heaptech.com #文件名任意
01#2)添加下方到内容
02server {
03 listen 80; #WordPress的访问端口(默认80)
04 server_name heaptech.com www.heaptech.com; #主机名称,绑定的域名
05 root /var/www/heaptech.com; #虚拟主机根目录
06
07 location / {
08 index index.php;
09 }
10
11 location ~ \.php$ {
12 fastcgi_pass 127.0.0.1:9000;
13 fastcgi_index index.php;
14 include /etc/nginx/fastcgi_params;
15 }
16}
1#3)软链接至sites-enabled文件夹
2sudo ln -s /etc/nginx/sites-available/heaptech.com /etc/nginx/sites-enabled/
10、安装wordpress
1cd /var/www/heaptech.com #虚拟主机根目录
2sudo wget http://wordpress.org/latest.tar.gz
3sudo tar -zxvf latest.tar.gz
4sudo mv wordpress/* .
5sudo chmod -R 755 wp-content/ #权限问题还有一点不是很明白,欢迎指教(怎样最安全?)
6sudo cp wp-config-sample.php wp-config.php
7sudo 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
1sudo /etc/init.d/nginx restart
2#至此,所有安装工作全部完成
3#http://heaptech.com即为blog地址
4#http://heaptech.com/phpmyadmin/为phpmyadmin