真正从零开始搭建个人博客,从只有一个初始服务器开始

从零开始搭建个人博客

使用wordpress搭建个人博客

前置条件:拥有一个服务器 (1核2g1M就足够)

以下教程使用mac电脑示范:

使用ssh连接远程服务器 (用户密码在服务器控制台可以设置,比如阿里云控制台)

  1. 输入命令:ssh root@ip
  2. 输入密码: *******

出现 Welcome to Alibaba Cloud Elastic Compute Service ! 表示连接成功。

搭建wordpress博客的步骤是:

  1. 安装nginx 并且运行
  2. 安装php 最好7.0.0以上 nginx需要配置php
  3. 安装mysql 运行
  4. 在wordpress.org下载源码包解压放在nginx目录下
  5. 浏览器输入网址开始安装

首先安装nginx

  1. gcc 安装:yum install gcc-c++
  2. PCRE pcre-devel 安装:yum install -y pcre pcre-devel
  3. zlib 安装:yum install -y zlib zlib-devel
  4. OpenSSL 安装:yum install -y openssl openssl-devel

直接按步骤输命令即可。

然后下载nginx。

官网下载地址
在这里插入图片描述

可在里面点击直接下载然后解压,将解压的文件夹上传至服务器目录中(同下方用命令下载和解压)

使用命令下载:
wget -c https://nginx.org/download/nginx-1.19.4.tar.gz (版本号自己改,可到官网查看最新稳定版)
如果没有安装wget,执行 yum install wget 安装。

解压:
tar -zxvf nginx-1.19.4.tar.gz
cd nginx-1.19.4

使用默认配置:
./configure

编译安装
make
make install
查看安装路径:(默认安装的都在这个目录)
whereis nginx (/usr/local/nginx)
进入目录:
cd /usr/local/nginx/sbin
运行 ./nginx
在浏览器输入服务器ip
在这里插入图片描述看到这个说明安装运行成功。

随便将html文件丢进 /usr/local/nginx/html 进行访问 (a.html)
ip/a.html
在这里插入图片描述
*如果页面无法访问请检查阿里云后台安全组配置是否配置端口

nginx常用命令:
cd /usr/local/nginx/sbin/ (在sbin目录下运行)
./nginx 运行
./nginx -s stop 此方式相当于先查出nginx进程id再使用kill命令强制杀掉进程。
./nginx -s quit 此方式停止步骤是待nginx进程处理任务完毕进行停止。
./nginx -s reload 重新运行(更改配置文件后)
nginx -t 查看配置文件是否正确
ps aux|grep nginx 查询nginx进程

如果希望配置全局nginx 命令 (不需要在sbin目录下运行)
cd /usr/local/nginx/sbin/
ln -s /usr/local/nginx/sbin/nginx /usr/local/bin/nginx
测试:
cd /
nginx -s quit
访问 ip/a.html
在这里插入图片描述
启动 :
nginx
在这里插入图片描述
nginx 开机启动:
systemctl enable nginx.service

取消开机自启动
systemctl disable nginx.service

如果报Failed to enable unit: Unit file nginx.service does not exist.

  1. 在系统服务目录里创建nginx.service文件
    vi /usr/lib/systemd/system/nginx.service(按i编辑,:wq保存退出)

  2. 写入内容如下:

[Unit]
Description=nginx
After=network.target
 
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
 
[Install]
WantedBy=multi-user.target

Description:描述服务
After:描述服务类别
[Service]服务运行参数的设置
Type=forking是后台运行的形式
ExecStart为服务的具体运行命令
ExecReload为重启命令
ExecStop为停止命令
PrivateTmp=True表示给服务分配独立的临时空间
注意:[Service]的启动、重启、停止命令全部要求使用绝对路径
[Install]运行级别下服务安装的相关设置,可设置为多用户,即系统运行级别为3

  1. 设置开机自启动
    systemctl enable nginx.service

  2. 查看nginx状态
    systemctl status nginx.service
    很奇怪,明明启动成功了,为什么显示Active: inactive (dead)?

  3. 杀死nginx重启nginx
    pkill -9 nginx

ps aux | grep nginx

systemctl start nginx

再次查看状态,变成了active,搞定。

  1. 重启服务器(可以不执行)
    reboot

  2. 再次连接后,查看服务状态
    systemctl status nginx.service

看到nginx已经启动,至此,nginx自启动配置成功。

下面安装php

  1. 首先安装 EPEL 源:yum install epel-release
  2. 安装 REMI 源:yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
  3. 安装 Yum 源管理工具:yum install yum-utils
  4. 安装 PHP7.3:yum install -y php73-php-fpm php73-php-cli php73-php-bcmath php73-php-gd php73-php-json php73-php-mbstring php73-php-mcrypt php73-php-mysqlnd php73-php-opcache php73-php-pdo php73-php-pecl-crypto php73-php-pecl-mcrypt php73-php-pecl-geoip php73-php-recode php73-php-snmp php73-php-soap php73-php-xml

设置开机启动、运行服务:
systemctl enable php73-php-fpm
systemctl start php73-php-fpm

查找php.ini位置:
find /etc/opt/remi/php73 -name php.ini (/etc/opt/remi/php73/php.ini)
编辑/etc/opt/remi/php73/php.ini 替换 cgi.fix_pathinfo=1 为 cgi.fix_pathinfo=0
快捷命令:
sed -i 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/' /etc/opt/remi/php73/php.ini
重启php73-php-fpm
systemctl restart php73-php-fpm

常用命令:
systemctl restart php73-php-fpm #重启
systemctl start php73-php-fpm #启动
systemctl stop php73-php-fpm #关闭
systemctl status php73-php-fpm #检查状态

更新 PHP
运行下面的命令系统就会更新所有可以更新的软件包括 PHP
yum update

然后配置nginx支持php文件

修改 /usr/local/nginx/conf/nginx.conf 文件

location / {
    root   html;
    index  index.html index.htm index.php;
}
location ~ \.php$ {
  	fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include        fastcgi_params;
}

重启nginx

测试 新建个文件 test.php

<?php
echo phpinfo();
?>

放入 /usr/local/nginx/html
浏览器输入地址 ip/test.php
在这里插入图片描述

说明php运行成功。

安装mysql

  1. 下载mysql源安装包
    wget https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
  2. 安装mysql源
    yum localinstall mysql80-community-release-el7-1.noarch.rpm
  3. 安装mysql
    yum install mysql-community-server

启动mysql:
systemctl start mysqld
查看启动状态:
systemctl status mysqld
设置开机启动:
systemctl enable mysqld

*mysql8以上有默认密码,需要更改密码

获取默认密码:
grep 'temporary password' /var/log/mysqld.log
mysql -u root -p
输入上面打印的临时密码
修改密码:
ALTER USER "root"@"localhost" IDENTIFIED BY "password"; (8.0以上的密码需要有大写数字特殊符号)

添加远程登录用户(8.0后需要设置,否则后面wordpress连接不上数据库 非常重要!!!!)

update user set host='%' where user ='root';
然后使用下面命令使修改生效:
flush privileges;
修改加密规则:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'yourpassword' PASSWORD EXPIRE NEVER;
更新 root 用户密码
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'yourpassword';
刷新权限
flush privileges;

创建wordpress数据库:
create database wordpress

下载wordpress

下载地址
下载完后解压,把文件夹放入nginx目录下 /usr/local/nginx/html

在这里插入图片描述
在这里插入图片描述
点提交后复制框里的信息,创建wp-config.php文件,把内容粘贴进去,然后上传至/usr/local/nginx/html/wordpress 目录就行。

更改皮肤或者下载插件的时候会提示登录FTP,不想要的话编辑wp-config.php

define("FS_METHOD","direct");
define("FS_CHMOD_DIR", 0777);
define("FS_CHMOD_FILE", 0777);

在这里插入图片描述
然后 命令行:

chmod -R 777 /usr/local/nginx/html/wordpress/

接下来一点小尾巴应该没什么难度了吧!

到这里就恭喜大家完成个人博客的搭建,有什么问题请留言。

博客原文
http://blog.jw946.com/?p=8#comment-2

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值