本文尽可能详细介绍如何从零搭建typecho博客,只要按下文一步一步操作小白也能建博客
如果你是在pc端浏览器看到此文请多参考文章右侧目录
准备
域名、vps/虚拟主机
域名
推荐域名商namesilo
价格便宜、有免费的域名隐私、支持支付宝付款。
购买域名购买域名付款前可以输入优惠码:moenjoy
来减免1$,年付
.com域名仅需8美元
vps
首推搬瓦工
QN机房cn2电信直连线路512M年付仅需19$ 支持支付宝付款
输入优惠码 BWH1ZBPVK
永久优惠 6%
个人还比较喜欢的cloudcone
优点是支持支付宝,按小时计费,关机每月只有很少的占用费,解决吃灰问题。
部署
本文以搬瓦工centso6为例
ssh链接服务器
首先# yum -y update
更新一下
创建screen会话以防进程断掉,若安装中断用# screen -r lamp
恢复界面
# screen -S lamp
如果提示screen: command not found
则先安装# yum install screen
搭建lnmp环境
使用LNMP一键安装包安装环境
# wget -c http://soft.vpser.net/lnmp/lnmp1.4-full.tar.gz && tar -zxf lnmp1.4-full.tar.gz && cd lnmp1.4-full && ./install.sh lamp
之后的基本配置如下:
LNMB V1.3 for Centos Linux Server, Written by Licess A tool to auto-comoile install INMP/INMPA/LAMP on Linux For more information please visit http: //wwwlnmp. org
Please setup root password of MYSQL, (Default password: root
Please enter: testmm.com
MYSQL root password: testmm.com
Do you want to enable or disable the Innodb Storage Engine?
Default enable, Enter your choice (Y/n: n
You will disable the Innodb Storage Engine!
You have 5 options for your Database install
1: Install MYSQL 5.1.73
2: Install MYSQL 5.5.48 (Default)
3: Install MYSQL 5.6.29
2: Install MYSQL 5.5.48 (Default)
5: Install Mariadb 10.0.23
6: Install MYSQL 5.7. 11
Enter your choice (1,2,3,4,5 or 6):2
You will install MYSQL 5.5. 48
You have 6 options for your PHP install
1: Install PHP 5.2.17
2: Insta11 PHP 5.3.29
3: Install PHP 5.4.45 (Default)
4: Install PHP 5.5.36
5: Install PHP 5.6.1
6: Install PHP 7.0.7
Enter your choice (1,2,3,4,5 or 6):5
You will Install PHP 5.6.1
You have 3 options for your Memory Allocator install 1: don't install Memory Allocator. (Default)
2: Install Jemalloc
3: Install Tcmalloc
Enter your choice (1, 2 or 3): 1
You will install not install Memory Allocator
Please enter Administrator Email Address:[email protected]
Server Administrator Email: [email protected]
You have 2 options for your Apache install
Please enter Administrator Email Address: [email protected]
1:Install Apache 2. 2.31
2:Install Apache 2.4.20
Enter Your choice (1 or 2): 1
You WIII instal Apache 2. 2.31
Press any key to install,,, or Press ctrl+c to cancel
回车,至此将会安装lnmp,安装过程大概半个小时,耐心等待。
当出现Install lnmp Vi3 completed: enioy it
时说明安装成功
访问vps的ip地址就会看到以下界面
为了安全,我们要将数据库访问地址修改一下,如改为myphpm
# cd /home/wwwroot/default
# mv phpmyadmin myphpm
并将lnmp界面删除或改名
# rm -rf index.html 或者
# mv index.html example.html
之后我们可以删除lnmp的安装包了
# rm -rf /root/lnmp1.4-full.tar.gz
更新python
为保证之后的配置阶段正常,我们先更新一下python版本
# cd ~
# wget https://www.python.org/ftp/python/2.7.12/Python-2.7.12.tgz
# tar -zxf Python-2.7.12.tgz && cd Python-2.7.12
# ./configure
# make && make install
备份之前版本并更新软链接
# mv -f /usr/bin/python /usr/bin/python2.6
# ln -s /usr/local/bin/python2.7 /usr/bin/python`
安装pip,设置默认python
# wget https://bootstrap.pypa.io/get-pip.py
# python get-pip.py
# ln -s /usr/local/bin/pip2.7 /usr/bin/pip
查看python版本是否正确
# python --version
确认版本为新版后编辑# vi /usr/bin/yum
确保 yum 功能正常
这里使用vim编辑器,不了解请参考vim教程
输入i
进入编辑模式
移动光标将#!/usr/bin/python
修改为#!/usr/bin/python2.6
之后Esc
输入:qw
保存
别忘了删除之前的下载包
# cd ~ && rm -rf Python-2.7.12.tgz
至此python更新完毕
安装PHP缓存加速扩展
安装 OPchace
# cd /root/lnmp1.4-full
# ./addons.sh install opcache
出现Opcache installed successfully, enjoy it!
说明安装完毕
安装Memcached
# ./addons.sh install memcached
Which memcached php extension do you choose:
Install php-memcache,(Discuz x) please enter: 1
Install php-memcached, please enter: 2
Enter 1 or 2 (Default 1): 2
出现Memcached installed successfully, enjoy it!
安装完成
开启scandir函数
# vi /usr/local/php/etc/php.ini
输入?scandir
搜索
输入i
编辑将scandir字符连多余空格同删掉
再Esc
后:wq
保存
重启lnmp# lnmp restart
安装virtualenv
安装virtualenv为之后设置ssl
# pip install virtualenv
域名解析
首先到域名注册商那里修改dns记录
把域名A记录解析到你的vps地址,www和@都要修改。
然后为网站添加域名
# lnmp vhost add
回车输入域名
# test.com
回车,添加多域名
# www.test.com
回车,确定网站目录默认即可/home/wwwroot/test.com
/home/wwwroot/test.com/test2
下一步询问是否记录日志
# Y
输入站长邮箱
# [email protected]
询问数据库名和数据库用户名是否保持一致
# Y
输入数据库root用户密码 (前面安装lnmp时设置的密码)
# testmm.com
确定数据库名,例如:
# moenjoy
设置此数据库密码:
# moemm
询问是否开启ftp,建议开启
之后新版的lnmp会询问你是否开启ssl,这里建议开启,或者之后用
两次回车,当出现Virtualhost infomation:
时说明域名添加成功# lnmp ssl add
添加
Please enter domain(example: www.lnmp.org): test.com
Your domain: test.com
Enter more domain name(example: lnmp.org *.lnmp.org): www.test.com
domain list: www.test.com
Please enter the directory for domain seoimo.com: /home/wwwroot/test.com
Allow access log? (y/n) n
Disable access log.
Please enter Administrator Email Address: [email protected]
Server Administrator Email:[email protected]
1: Use your own SSL Certificate and Key
2: Use Let's Encrypt to create SSL Certificate and Key
Enter 1 or 2: 2
直到出现:
no crontab for root
Add Let's encrypt crontab renew rule...
no crontab for root
Let's Encrypt SSL Certificate create successfully.
Test Apache configure file...
test apache configure... Syntax OK
done
Restart Apache...
Restart apache... done
说明ssl安装成功
以后安装网站程序都可以直接安装在域名目录里了。
http301重定向https
编辑网站根目录下的.htaccess
文件
cd /home/wwwroot/test.com/
vi .htaccess
在顶部添加
# BEGIN Rewrite
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://test.com/$1 [R=301,L]
# END Rewrite
FTP
ftp服务默认不开启,但是有时候会用到
如若开启可以
# cd /root/lnmp1.4-full
# ./pureftpd.sh
等待安装完ftp服务,之后添加ftp用户
# lnmp ftp add
然后设置用户名、密码及访问的绝对路径。
如果在ftp访问时提示没有权限的话请# chown www:www -R /目录路径/
安装Typecho
下载typecho安装包到网站目录 最新链接去typecho安装包找
# cd /home/wwwroot/test.com/
# wget url http://typecho.org/downloads/1.1-17.10.30-release.tar.gz
# tar zxvf /home/wwwroot/test.com/1.1-17.10.30-release.tar.gz 解压
# mv build/* /home/wwwroot/test.com/ 将解压后的build文件内容移到网站目录内
# rm -rf 1.1-17.10.30-release.tar.gz build 删除安装包及build文件
之后访问你的域名
就可以看到安装向导
填写数据库用户名,密码,数据库名称,数据库前缀默认
至此typecho程序安装成功。
优化
避免权限问题无法写入
# chmod -R 755 /home/wwwroot
# chown -R www /home/wwwroot
删除mysql-bin.0000*日志文件
LNMP一键安装包默认开启日志记录,位置在/usr/local/mysql/var/
下
编辑/etc/my.cnf
文件关闭记录
# vi /etc/my.cnf
在以下两行前添加#
禁用日志
#log-bin=mysql-bin
#binlog_format=mixed
再:wq
保存
并# /etc/init.d/mysql restart
重启mysql
3 条评论
来这里多学习~!
感谢博主的分享
大佬我所有配置弄了过后访问出现没有权限访问服务器