之前一直用Wordpress搭建我的个人博客,但是用了一段时间后总觉得Wordpress有些重,对于我这种只是用博客来记录一些日常见闻和游记的人来说,不太好用。纠结了许久,通过谷哥找到了Ghost这款轻量级的,静态化的博客框架,试用了一下发现还不错。遂将安装过程记录如下:
环境说明
我所用的系统为Ubuntu 14.04 X64版本。在一下的各步骤中,标记为$
开头的为普通用户操作,标记为#
的为root用户操作。
安装Mysql数据库
参考:https://allaboutghost.com/migrating-ghost-installation-from-sqlite3-to-mysql/
由于Ghost默认使用的是sqlite数据库,为了能够更好的提升性能,也为了以后迁移数据更加方便,在本文中,我们修改Ghost的默认数据库为Mysql数据库。
更新系统:
1sudo apt-get update && sudo apt-get upgrade -y安装Mysql数据库:
1sudo apt-get install mysql-server -y配置Mysql。所有选项默认即可:
1mysql_secure_installation登陆Mysql:
1mysql -u root -p为Ghost新建一个数据库,执行Mysql命令:
1create database ghost;为Ghost创建新的数据库用户,执行Mysql命令,注意将其中password替换为自己的数据库密码:
1CREATE USER 'ghost'@'localhost' IDENTIFIED BY 'password';为刚才创建的新用户赋予权限,执行Mysql命令:
1GRANT ALL PRIVILEGES ON ghost.* TO 'ghost'@'localhost';刷新权限,执行Mysql命令:
1flush privileges;退出Mysql,执行Mysql命令:
1quit;
安装Nginx服务器
执行以下命令:
|
|
安装Ghost博客框架
参考:https://www.howtoinstallghost.com/how-to-install-ghost-on-ubuntu-server-12-04/
安装必要的软件包:
1sudo apt-get install -y zip vim wget安装Node.js:
12curl -sL https://deb.nodesource.com/setup | sudo bash -sudo apt-get install -y nodejs下载并安装Ghost:
1234567sudo mkdir -p /var/www/cd /var/www/sudo wget https://ghost.org/zip/ghost-latest.zipsudo unzip -d ghost ghost-latest.zipsudo rm ghost-latest.zipcd ghost/sudo npm install --production
配置Ghost使用Mysql
参考:https://allaboutghost.com/migrating-ghost-installation-from-sqlite3-to-mysql/
在Ghost的目录中创建配置文件:
12cd /var/www/ghostsudo cp config.example.js config.js修改配置文件,使用任何你喜欢的编辑器编辑
config.js
,在Production
这一节,修改如下内容:1) 设置本地域名,修改
url
到博客的域名。1url: 'http://my-ghost-blog.com',2) 设置Ghost使用Mysql数据库,修改:
1234567891011database: {client: 'mysql',connection: {host: 'localhost',user: 'ghost',password: 'password',database: 'ghost',charset: 'utf8'},debug: true},将其中的
user
和password
是我们之前在Mysql中创建的用户和对应的密码。database
是我们之前创建的数据库名称。3) 让Ghost可以被外网访问,修改:
1host: '127.0.0.1',到
1host: '0.0.0.0',测试Ghost是否可以使用,执行
1sudo npm start --production访问
http://your-domain:2368
,看能否正常工作。如果可以工作的话,我们为了安全将:
1host: '0.0.0.0',改回
1host: '127.0.0.1',
配置PHP环境
安装PHP环境:
1sudo apt-get install -y php5-fpm php5-mysql配置PHP:
编辑
/etc/php5/fpm/php.ini
文件,找到cgi.fix_pathinfo
字段,并将其修改为:1cgi.fix_pathinfo=0重启PHP:
1sudo service php5-fpm restart
配置Nginx虚拟服务器
配置Nginx反向代理Ghost
为了让我们的PHP网站和Ghost博客不相互影响,需要先配置两个虚拟机,一个用来反向代理Nginx,另一个用来支持PHP。
配置Ghost虚拟服务器,新建Nginx的Block文件:
12cd /etc/nginx/sites-availablesudo cp default ghost编辑ghost文件内容如下:
123456789101112server {listen 80 default_server;listen [::]:80 default_server ipv6only=on;server_name your-domain;location / {proxy_set_header X-Real-IP $remote_addr;proxy_set_header Host $http_host;proxy_pass http://127.0.0.1:2368;}}将
server_name
修改为你的域名。让刚才的配置生效:
123sudo rm /etc/nginx/sites-enabled/defaultsudo ln -s /etc/nginx/sites-available/ghost /etc/nginx/sites-enabledsudo service nginx restart测试是否生效:
1) 启动Ghost:
12cd /var/www/ghostsudo npm start --production2) 访问你的域名或IP看是否能够打开Ghost。
配置PHP虚拟服务器
新建虚拟服务器文件夹:
1sudo mkdir -p /var/www/root/html新建Nginx的Block文件:
12cd /etc/nginx/sites-availablesudo cp default root修改其内容如下:
12345678910111213141516171819202122232425262728server {listen 8080 default_server;listen [::]:8080 default_server ipv6only=on;root /var/www/root/html;index index.php index.html index.htm;server_name root;location / {try_files $uri $uri/ =404;}error_page 404 /404.html;error_page 500 502 503 504 /50x.html;location = /50x.html {root /usr/share/nginx/html;}location ~ \.php$ {try_files $uri =404;fastcgi_split_path_info ^(.+\.php)(/.+)$;fastcgi_pass unix:/var/run/php5-fpm.sock;fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include fastcgi_params;}}让刚才的配置生效:
12sudo ln -s /etc/nginx/sites-available/root /etc/nginx/sites-enabledsudo service nginx restart测试是否生效
新建测试文件:
1sudo touch /var/www/root/html/index.php编辑该文件,内容如下:
12345<?phpecho "Hello World!";echo "<br />";echo date('Y - m - d');?>访问你的网页:
1http://your-domain:8080
让你的Ghost永久服务
为了让我们的Ghost服务器不会在我们断开远程连接后关闭,我们需要进行如下设置:
安装
forever
:1sudo npm install forever -g新建启动脚本:
1sudo touch /var/www/ghost/start_ghost.sh在脚本中添加如下内容:
123#! /bin/shNODE_ENV=production forever start /var/www/ghost/index.js赋予可执行权限:
1sudo chmod -R 755 /var/www/ghost/start_ghost.sh测试运行:
12su/var/www/ghost/start_ghost.sh访问你的域名,看能否打开。
使用
forever list
可以查看当前运行的任务,使用forever stop /var/www/ghost/index.js
可以停止Ghost服务。
设置开机启动
在
/etc/rc.local
文件中,exit 0
前添加:1/var/www/ghost/start_ghost.sh重启机器并测试。
配置Ghost
配置邮件服务。邮件服务可以赋予你的Ghost发邮件的能力。
这里我使用的是新注册的Gmail账户。
编辑
/var/www/ghost/config.js
文件,修改其中的mail
部分:12345678910mail: {transport: 'SMTP',options: {service: 'Gmail',auth: {user: 'youremail@gmail.com',pass: 'yourpassword'}}},为了安全,Gmail的密码我使用的是两步验证生成的App密码。
配置Ghost用户。访问:
1http://your-domain/ghost/可以打开设置页面。第一次打开该页面可以注册管理员账号。
¶ The end
Share Link: http://d0u9.win/posts/2360490712.html