在云服务器centos7.6上利用LAMP搭建Typecho博客

没有人挡得住,你疯狂的努力进取。你可以不够强大,但你不能没有梦想。如果你没有梦想,你只能为别人的梦想打工筑路。

导读:本篇文章讲解 在云服务器centos7.6上利用LAMP搭建Typecho博客,希望对大家有帮助,欢迎收藏,转发!站点地址:www.bmabk.com,来源:原文

在云服务器centos7.6上利用LAMP搭建Typecho博客

一、前言

其实LAMP就是Linux、Apache、MySQL、PHP这些开头字母。
本次演示过程使用腾讯云的轻量应用服务器演示,虽然在云服务器中,在选购过程中都可以选择预装什么系统,比如:宝象塔、LAMP这些预装,但是如果对于想自己搭建出来的,还是建议自己上手试一试。

二、云服务器选购

对于云服务器选购,由于都是用于个人搭建的,所以在配置这一块,可以随便选择,不同的供应商在同样的配置下,可能有不同的价格,这边就不做推荐,多对比对比就可以看出谁家贵谁家便宜。但是如果是企业那还是要着重考虑到负载这一块。
像我购买的这个服务器是用新人账号购买的,正好赶到腾讯云搞活动,一年80元拿下的。配置是:cpu:2核、内存:8G、系统盘:80GB、流量包1200G/月(带宽8Mbps),还是很香的。

三、云服务器设置

1.密码设置

云服务器在购买的时候,会让你设置密码,这个密码别忘记,如果忘记了也没事,在实例信息页面会有一个重置密码的选项,点进去重置就好了,选择root用户,输入新密码和确认密码,点击下一步,一般会发个验证短信到你注册的手机号上,输入验证短信就可以了。
在这里插入图片描述

2.防火墙设置

(1)通常在云服务器购买来的时候,云服务器厂商会默认根据系统类型开放不同的端口,阿里云默认好像是只开通了SSH的端口,其他端口都是默认关闭的。腾讯云默认是开通HTTP、HTTPS、SSH、Ping-ICMP,不全面,可能由于我购买的是轻量应用服务器所以默认开通了这些端口。
可以根据不同的需求更改不同的端口,按照自己的需求来定,但SSH端口一定要开启,不然就无法登录了。
在这里插入图片描述

(2)添加规则也是比较简单的,应用类型可以选择云厂商提前设定好的,也可以自定义设定。
在这里插入图片描述

3.快照设置

其实快照这个都不需要过多的解释,一般折腾过虚拟机的都知道。回滚其实就是恢复,好像就腾讯云叫回滚吧-.-,删除快照需要手机号的验证码,腾讯云绑定微信号后,需要在微信号里确认。
在这里插入图片描述

4.监控设置

其实监控设置,就看看就可以了,没有多少访问量也用不到多少资源。至于设置告警,如果真的想搭建一个大型网站,供别人访问,那还是需要设置的,不过不少需要钱,个人玩一玩的就不用太在意了。
在这里插入图片描述

其它的一些配置等后期如果有时间在出一篇专门介绍云服务器的文章再说吧!下面进入正题。

四、安装Apache服务

##安装Apache服务
[root@centos7 ~]# yum install -y httpd  
##设定开机自启动
[root@centos7 ~]# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
##启动Apache服务
[root@centos7 ~]# systemctl start httpd
##查看Apache服务状态
[root@centos7 ~]# systemctl status httpd
##防火墙,其实针对对外开放的服务器是不建议关闭防火墙的,但是我们这里做演示就直接关闭了,只利用云服务器上的防火墙进行控制。
[root@centos7 ~]# systemctl stop firewalld

打开浏览器输入HTTP://云服务器IP,检查一下Apache服务运行是否正常。
在这里插入图片描述

五、安装PHP服务

##安装PHP
[root@centos7 ~]# yum install -y php 
##安装PHP 驱动程序
[root@centos7 ~]# yum install -y php-mysql
##可以测试一下是否安装成功
[root@centos7 ~]# cd /var/www/html  ##先到html目录下
##先做个info.php文件
[root@centos7 html]# vim info.php
<?php
phpinfo();
?>
##重启Apache服务
[root@centos7 html]# systemctl restart httpd

打开浏览器访问http://云服务器ip/info.php
在这里插入图片描述

六、 安装Maria DB数据库

这里借鉴一下,刚开始学如何搭建博客的一篇文章中用到的数据库,MySQL比较慢,而且还麻烦。

```html
##安装Maria DB数据库
[root@centos7 ~]yum install -y mariadb-server mariadb*
##设置数据库开机自启动
[root@centos7 ~]# systemctl enable mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
##启动数据库
[root@centos7 ~]# systemctl start mariadb

```html
##初始化Maria DB数据库,并且设定root密码
##除了备注的地方需要输入y,其他地方都直接回车!
[root@centos7 ~]# mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y       #选择Y
New password:                    #输入密码
Re-enter new password:           #确认密码
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n]    
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] 
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] 
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] 
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!
##重启数据库
[root@centos7 ~]# systemctl restart mariadb
##登录数据库,创建typecho的数据库
[root@centos7 ~]# mysql -uroot -p
Enter password:          ##数据密码
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.68-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> grant all privileges on *.* to root@'%' identified by 'zxcvbnm'; #设定相关权限
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> create database typecho;   #创建typecho的库
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> flush privileges;           #重新加载相关权限
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> select User,Host,Password from mysql.user;     
+------+-----------+-------------------------------------------+
| User | Host      | Password                                  |
+------+-----------+-------------------------------------------+
| root | localhost | *D1523220ED740182587AB4860EA1EF4ECEC0F0F5 |
| root | 127.0.0.1 | *D1523220ED740182587AB4860EA1EF4ECEC0F0F5 |
| root | ::1       | *D1523220ED740182587AB4860EA1EF4ECEC0F0F5 |
| root | %         | *7DE69B235B6AD96041172B949D90F88326B74612 |
+------+-----------+-------------------------------------------+
4 rows in set (0.00 sec)

MariaDB [(none)]> exit    #退出数据库
Bye

七、安装typecho

下载:[typecho下载网址](http://typecho.org/download)

把下载的文件上传的云服务器中,我是使用xshell个人版连接的,可以先试一下输入rz,如果显示未安装就安装一下。

##未安装
[root@centos7 typecho]# rz
-bash: rz: command not found
##安装lrzsz
[root@centos7 typecho]# yum -y install lrzsz

安装完成再次输入rz就能够打开传输文件的界面了,在传输之前先创建一个目录。

##创建typecho目录
[root@centos7 ~]# mkdir typecho
##切换到typecho目录中,因为上传文件,会上传到当前目录,所以使用时,最好在新创建的目录中
[root@centos7 ~]# cd typecho
##上传文件,上传完会在目录中显示。

在这里插入图片描述

##解压typecho安装包
[root@centos7 typecho]# tar -xzvf 1.1-17.10.30-release.tar.gz 
##解压完输入ls 会看到一个build的文件,把这个文件剪切到网站的根目录下/var/www/html.
[root@centos7 typecho]# cp -r build/* /var/www/html
##把原来创建的info.php删除
[root@centos7 html]# rm  info.php

打开浏览器输入HTTP://云服务器IP/install.php进行后续的安装。
在这里插入图片描述在这里插入图片描述在这里插入图片描述
安装后,这里需要创建一个config.inc.php文件
在这里插入图片描述

##创建config.inc.php文件,把内容复制进去就可以了。
[root@centos7 ~]# cd /var/www/html
[root@centos7 html]# vi config.inc.php

设定好后,就可以点击继续安装了,其实也就是完成了。
在这里插入图片描述
至此就完成了全部安装。
在这里插入图片描述
如果觉得默认的主题不是太好看,可以去百度搜索好看的主题。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/133463.html

(0)
飞熊的头像飞熊bm

相关推荐

发表回复

登录后才能评论
极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!