VPS+LNMP+WordPress 博客搭建

内容纲要

前言

突发奇想,注册个域名www.iostream.io,以此搭建一个自己的博客网站;本文讲解利用VPS,LMMP和WordPress搭建博客的过程。

域名注册及VPS

VPS购买

  搭建博客或者网站,最好是512M内存,10GBSSD以上配置,同时KVM架构(超售少,安装加速框架方便)更好。出于性价比考虑本文购买的是搬瓦工$19.9的VPS(这个是OpenVZ架构),使用优惠码有5%优惠。配置如下图所示。


域名注册

  域名注册可以到GoDaddy或namecheap等网站注册,本文在namecheap注册www.iostream.io域名,一个本人认为还比较极客的名字:iostream为C++中的IO(输入输出流),同时.io后缀也代表输入输出,以io开头也表示输入输出。www.iostream.io正反都是io,意义也是io,本人很喜爱。注册域名之后,绑定VPS的IP地址以及设置域名重定向。


安装LNMP

  LNMP一键安装包是一个用Linux Shell编写的可以为CentOS/RadHat/Fedora、Debian/Ubuntu/Raspbian/Deepin VPS或独立主机安装LNMP(Nginx/MySQL/PHP)、LNMPA(Nginx/MySQL/PHP/Apache)、LAMP(Apache/MySQL/PHP)生产环境的Shell程序。同时提供一些实用的辅助工具如:虚拟主机管理、FTP用户管理、Nginx、MySQL/MariaDB、PHP的升级、常用缓存组件Redis、Xcache等的安装、重置MySQL root密码、502自动重启、日志切割、SSH防护DenyHosts/Fail2Ban、备份等许多实用脚本。Nginx相当的稳定、功能丰富、安装配置简单、低系统资源……

1 执行LNMP Shell脚本

wget -c http://soft.vpser.net/lnmp/lnmp1.3-full.tar.gz && tar zxf lnmp1.3-full.tar.gz && cd lnmp1.3-full && ./install.sh lnmp

按照LNMP官网执行安装过程,等待一杯咖啡时间。

2 安装FTP

由于WordPress通过FTP安装插件及主题,所以本文安装pureftpd FTP服务。

进入LNMP下载目录,执行pureftpd.sh。

root@iostream:~/download/lnmp1.3-full# ls
ChangeLog  License  addons.sh  conf  include  init.d  install.sh  lnmp.conf  php5.2.17.sh  pureftpd.sh  readme  src  tools  uninstall.sh  upgrade.sh
root@iostream:~/download/lnmp1.3-full# ./pureftpd.sh

3 虚拟主机

lnmp 命令如下

+-------------------------------------------+
|    Manager for LNMP, Written by Licess    |
+-------------------------------------------+
|              http://lnmp.org              |
+-------------------------------------------+
Usage: lnmp {start|stop|reload|restart|kill|status}
Usage: lnmp {nginx|mysql|mariadb|php-fpm|pureftpd} {start|stop|reload|restart|kill|status}
Usage: lnmp vhost {add|list|del}
Usage: lnmp database {add|list|edit|del}
Usage: lnmp ftp {add|list|edit|del}

添加虚拟主机

root@iostream:~# lnmp vhost add
+-------------------------------------------+
|    Manager for LNMP, Written by Licess    |
+-------------------------------------------+
|              http://lnmp.org              |
+-------------------------------------------+

输入域名;本文以www.iostream.io为例

Please enter domain(example: www.lnmp.org): www.iostream.io
======================================
 Your domain: www.iostream.io
======================================
Do you want to add more domain name? (y/n) n

设定网站,回车默认

Please enter the directory for the domain: www.iostream.io
(Default directory: /home/wwwroot/www.iostream.io):
Virtual Host Directory: /home/wwwroot/www.iostream.io

是否允许重写(伪静态)?伪静态可以使URL更加简洁也利于SEO,如程序支持并且需要设置伪静态的话,如启用输入 y ,不启用输入 n回车。如果启用设置,输入名称启用相关伪静态配置文件。

===========================
Allow Rewrite rule? (y/n)
===========================
y
Please enter the rewrite of programme:
wordpress,discuz,typecho,sablog,dabr rewrite was exist.
(Default rewrite: other):wordpress
===========================
You choose rewrite=wordpress
===========================
===========================

启用日志;默认日志目录 /home/wwwlogs/

Allow access_log? (y/n)
===========================
y
Enter access log name(Default access log file:www.iostream.io.log):
You access log filename: www.iostream.io.log

创建数据库,需要验证数据库root密码,前面安装LNMP的时候设置的。

======================================================
Create database and MySQL user with same name (y/n)
======================================================
y
Enter current root password of Database (Password will not shown):

OK, MySQL root password correct.

创建网站的数据库用户名和数据库密码

Enter database name: hello
Your will create a database and MySQL user with same name: hello
Please enter password for mysql user hello: 123456
Your password: 123456

创建ftp账户与密码

======================================================
Create ftp account (y/n)
======================================================
y
Enter ftp account name: hello
Enter password for ftp account hello: 123456

Press any key to start create virtul host...

创建成功会提示添加的域名、目录、伪静态、日志、数据库、FTP等相关信息

================================================
Virtualhost infomation:
Your domain: www.iostream.io
Home Directory: /home/wwwroot/www.iostream.io
Rewrite: wordpress
Enable log: yes
Database username: hello
Database userpassword: 123456
Database Name: hello
FTP account name: hello
FTP account password: 123456
================================================

安装WordPress

下载并解压wordpress

wget http://wordpress.org/latest.tar.gz
tar -xzvf latest.tar.gz

移动wordpress下所有文件到网站根目录/home/wwwroot/www.iostream.io/

root@iostream:~/download/wordpress# cp -r * /home/wwwroot/www.iostream.io/

更改网站目录所有者,让wordpress有更改内容的权限。如果不更改,wordpress在线安装主题与插件会报’Could not create directory‘错误。

root@iostream:/home/wwwroot# chown -R www www.iostream.io/
chown: changing ownership of 'www.iostream.io/.user.ini': Operation not permitted

.user.ini文件不允许被操作是因为被锁定了,即使root用户也不能更改。通过chattr解锁与锁定。

root@iostream:/home/wwwroot/www.iostream.io# chattr -i .user.ini
root@iostream:/home/wwwroot# chown -R www www.iostream.io/

到这里,服务器的配置就结束了。以后就可以在线配置博客网站。

WordPress配置

在浏览器访问网站www.iostream.io,会自动跳转到http://www.iostream.io/wp-admin/install.php


选择语言,点击Let's go!

================================================
Virtualhost infomation:
Your domain: www.iostream.io
Home Directory: /home/wwwroot/www.iostream.io
Rewrite: wordpress
Enable log: yes
Database username: hello
Database userpassword: 123456
Database Name: hello
FTP account name: hello
FTP account password: 123456
================================================

输入前面创建虚拟主机的数据库信息。


运行安装程序,注册网站。安装到此结束,enjoy it!


问题汇总

不定期更新

1 wordpress在线无法安装主题或插件,报错’Could not create directory‘

  wordpress没有更改网站目录的权限,修改目录所有者

root@iostream:/home/wwwroot# chown -R www www.iostream.io/

2 wordpress只显示当前激活主题,不显示其他已安装出题;尝试重复安装主题报错‘Can’t Install – Destination folder already exists’

  LNMP禁用了 scandir 函数,导致了wordpress无法缓存主题列表。所以后台无法显示安装好的wordpress主题,只显示当前使用的一个主题。解决方法只需要把禁用的 scandir 函数恢复就可以了。
编辑/usr/local/php/etc下的php.ini文件,删除disable_functions(禁用的都是有一定为危险性的函数,为了服务器的安全着想)中的scandir函数;重启php服务,刷新wordpress管理主题页面,就可以看到其它主题。

root@iostream:~# vim /usr/local/php/etc/php.ini
;disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,popen,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepas     sthru,stream_socket_server
disable_functions = passthru,exec,system,chroot,chgrp,chown,shell_exec,proc_open,proc_get_status,popen,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,str     eam_socket_server
root@iostream:~# /etc/init.d/php-fpm restart

参考文献

LNMP一键安装包
LNMP安装
LNMP下FTP服务器的安装与使用
添加、删除虚拟主机及伪静态管理
WordPress官网安装文档

发表回复

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