打算做一個(gè)創(chuàng)客相關(guān)的站點(diǎn)惜姐,現(xiàn)在域名備案還沒(méi)來(lái)及做蜻牢。本文記錄一下在域名備案完成前狭郑,在虛擬機(jī)上架設(shè)wordpress的步驟罪既。
系統(tǒng)的環(huán)境
宿主機(jī)為HP probook 4441s筆記本铸题。i5 cpu+8G RAM。win7 64位琢感。虛擬機(jī)軟件為vm10丢间。
虛擬機(jī)系統(tǒng):debian7.7 dual core+1G ram+20G HDD
宿主機(jī)IP:192.168.199.103;虛擬機(jī)IP:192.168.199.137
debian系統(tǒng)安裝和配置
安裝(略)
配置
配置升級(jí)源
修改系統(tǒng)源
vim /etc/apt/sources.list
屏蔽掉
deb cdrom:[Debian GNU/Linux 7.7.0 _Wheezy_ - Official amd64 CD Binary-1 20141018-13:06]/ wheezy main
這句的下面添加四句
deb http://mirrors.163.com/debian wheezy main non-free contrib
deb-src http://mirrors.163.com/debian wheezy main non-free contrib
deb http://mirrors.163.com/debian wheezy-updates main non-free contrib
deb-src http://mirrors.163.com/debian wheezy-updates main non-free contrib
然后升級(jí)索引,升級(jí)系統(tǒng)
apt-get update apt-get upgrade
安裝工具軟件
apt-get install mlocate vim
安裝lemp環(huán)境
安裝nginx
nginx是作為webserver驹针。
apt-get install nginx
檢查系統(tǒng)進(jìn)程
ps -ef|grep nginx
安裝mysql-server
雖然perconaserver和mariadbserver大有取代mysqlserver的呼聲烘挫。但是mysql5.x還是值得信賴(lài)的。
apt-get install mysql-server mysql-devel
為了安全起見(jiàn),可以再執(zhí)行
/usr/bin/mysql_secure_installation
安裝php
安裝php5主體饮六,php5連接mysql的部分其垄, 搭配nginx的php5組件以及php5的優(yōu)化組件。其余的必須php5-xml等擴(kuò)展需要用的時(shí)候再安裝卤橄。
apt-get install php5 php5-mysql php5-fpm php5-apc
注意:默認(rèn)的php5-fpm是以sock文件方式運(yùn)行的绿满,而不是socket方式運(yùn)行。所以沒(méi)有占用9000端口
搭配nginx和php
現(xiàn)在nginx+mysqlserver+php5都已經(jīng)安裝完畢】咂耍現(xiàn)在可以配置nginx和php5了喇颁。
nginx的默認(rèn)配置文件<em>sudo vim /etc/nginx/sites-available/default</em>里面定義了一個(gè)默認(rèn)站點(diǎn)我們現(xiàn)在修改它。其中
#location ~ \.php$ {=====>注釋取消掉
# fastcgi_split_path_info ^(.+\.php)(/.+)$;=====>注釋取消掉
# # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
#
# # With php5-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# # With php5-fpm:
# fastcgi_pass unix:/var/run/php5-fpm.sock;=====>注釋取消掉
# fastcgi_index index.php;=====>注釋取消掉
# include fastcgi_params;=====>注釋取消掉
#}=====>注釋取消掉
而后重啟<strong>nginx</strong>和<strong>php-fpm</strong>
/etc/init.d/nginx restart /etc/init.d/php5-fpm restart
而后在<em>/usr/share/html</em>文件夾中建立一個(gè)info.php
<?php phpinfo(); ?>
在筆記本上訪問(wèn) <em>http://192.168.199.137/info.php</em>可以看到phpinfo函數(shù)返回的相關(guān)信息嚎货。至此nginx已經(jīng)能夠解析php頁(yè)面了橘霎。
建立wordpress站點(diǎn)
去wordpress中文站下載wp的源代碼包
cd /usr/local/src wget --no-check-certificate https://cn.wordpress.org/wordpress-4.0.1-zh_CN.tar.gz tar -xf wordpress-4.0.1-zh_CN.tar.gz
建立一個(gè)專(zhuān)門(mén)的網(wǎng)站目錄轉(zhuǎn)移過(guò)去
mkdir -p /data/www/beginmaker.com mv wordpress/* /data/www/beginmaker.com/
設(shè)置權(quán)限這樣安裝時(shí)候程序有權(quán)限在目錄中生成wp-config.php文件
chown -R www-data:www-data /data/www/beginmaker.com
為了管理方便。我們對(duì)站點(diǎn)單獨(dú)建立一個(gè)nginx配置文件<em>/etc/nginx/sites-available/beginmaker.com</em>
`
server {
listen 80; ## listen for ipv4; this line is default and implied
root /data/www/beginmaker.com;
index index.html index.htm index.php;
server_name beginmaker.com www.beginmaker.com beginmaker.cc www.beginmaker.cc;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ /index.html;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
location /doc/ {
alias /usr/share/doc/;
autoindex on;
allow 127.0.0.1;
allow ::1;
deny all;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
`
連接過(guò)去以生效
ln -sf /etc/nginx/sites-available/beginmaker.com /etc/nginx/sites-enabled/beginmaker.com
接下去修改筆記本的hosts文件殖属。將beginmaker.com的解析指向到192.168.199.137上姐叁。
接下去訪問(wèn) http://beginmaker.com/即可打開(kāi)wordpress安裝界面。
我們可以用mysql的root賬戶(hù)進(jìn)行連接洗显。也可以新建一個(gè)專(zhuān)門(mén)的賬戶(hù)
`
登錄到mysql后臺(tái)
create database if not exists beginmakerwp default charset utf8 collate utf8_general_ci;
grant all privileges on beginmakerwp.* to beginmakeruser@localhost identified by '密碼';
flush privileges;
`
安裝過(guò)程至此結(jié)束外潜。