凯发k8国际娱乐官网入口-k8凯发> 弹性云服务器 ecs> > 基于wordpress搭建个人网站(linux)
更新时间:2024-01-03 gmt 08:00

基于wordpress搭建个人网站(linux)-凯发k8国际娱乐官网入口

应用场景

本文主要介绍了如何使用弹性云服务器的linux实例手工搭建lnmp平台,并部署wordpress环境。wordpress简称wp,最初是一款博客系统,后逐步演化成一款免费的cms(内容管理系统/建站系统)。该指导具体操作以centos 7.2 64位操作系统为例。

方案架构

图1 基于wordpress搭建个人网站示意图(linux)

方案优势

  • 快速构建站点,组网架构简单。
  • 网站安全易用。

资源和成本规划

表1 资源和成本规划

资源

资源说明

成本说明

虚拟私有云vpc

vpc网段:192.168.0.0/16

免费

虚拟私有云子网

  • 可用区:可用区1
  • 子网网段:192.168.0.0/24

免费

安全组

入方向规则:

  • 协议/应用:http
  • 端口:80
  • 源地址:0.0.0.0/0

免费

弹性云服务器

  • 计费模式:包年/包月
  • 可用区:可用区1
  • 规格:s6.large.2
  • 镜像:centos 7.2 64bit
  • 系统盘:40g
  • 弹性公网ip:现在购买
  • 线路:全动态bgp
  • 公网带宽:按流量计费
  • 带宽大小:5 mbit/s

ecs涉及以下几项费用:

  • 云服务器
  • 云硬盘
  • 弹性公网ip

具体的计费方式及标准请参考计费说明

nginx

是一个高性能的http和反向代理web服务器。

获取方式:

免费

mysql

是一款开源的关系数据库软件。

获取方式:

免费

php

是一款开源软件,用于web开发。

获取方式:

免费

wordpress

是一款开源的博客软件。

获取地址:

免费

域名

用于访问搭建的个人网站。

域名的价格以域名注册商所示为准,请参考域名注册商帮助文档。

如果您通过华为云的域名注册服务购买域名,具体的计费方式及标准请参考。

基于wordpress搭建个人网站操作流程

实施步骤(手动)

安装前准备

  • 已购买虚拟私有云和弹性公网ip。
  • 如果规划为网站配置域名,需已经购买好相应的域名。
  • 弹性云服务器所在安全组添加了如表2所示的安全组规则,具体步骤参见。
    表2 安全组规则

    方向

    协议

    端口

    源地址

    入方向

    http(80)

    80

    0.0.0.0/0

  • 为了更好的获取和更新系统和软件,建议您更新镜像源为华为云镜像源,详细操作,请参见。

操作步骤

  1. 安装nginx。
    1. 登录弹性云服务器。
    2. 执行以下命令,下载对应当前系统版本的nginx包。

      wget http://nginx.org/packages/centos/7/noarch/rpms/nginx-release-centos-7-0.el7.ngx.noarch.rpm

    3. 执行以下命令,建立nginx的yum仓库。

      rpm -ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm

    4. 执行以下命令,安装nginx。

      yum -y install nginx

    5. 执行以下命令,启动nginx并设置开机启动。

      systemctl start nginx

      systemctl enable nginx

    6. 查看启动状态。

      systemctl status nginx.service

    7. 使用浏览器访问 “http://服务器ip地址”,显示如下页面,说明nginx安装成功。
      图2 测试访问nginx
  2. 安装mysql。
    1. 依次执行以下命令,安装mysql。

      wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm

      yum -y install mysql57-community-release-el7-10.noarch.rpm

      yum -y install mysql-community-server --nogpgcheck

    2. 依次执行以下命令,启动mysql服务并设置开机自启动。

      systemctl start mysqld

      systemctl enable mysqld

    3. 查看mysql运行状态。

      systemctl status mysqld.service

      [root@ecs-adc3 ~]# systemctl status mysqld.service
      ● mysqld.service - mysql server
         loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
         active: active (running) since mon 2021-08-16 19:33:40 cst; 36s ago
           docs: man:mysqld(8)
                 http://dev.mysql.com/doc/refman/en/using-systemd.html
       main pid: 7916 (mysqld)
         cgroup: /system.slice/mysqld.service
                 └─7916 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
      aug 16 19:33:35 ecs-adc3 systemd[1]: starting mysql server...
      aug 16 19:33:40 ecs-adc3 systemd[1]: started mysql server.
    4. 执行以下命令,获取安装mysql时自动设置的root用户密码。

      grep 'temporary password' /var/log/mysqld.log

      回显如下类似信息。
      2021-08-16t11:33:37.790533z 1 [note] a temporary password is generated for root@localhost: ;8npd29lhs,k
    5. 执行以下命令,并按照回显提示信息进行操作,加固mysql。

      mysql_secure_installation

      securing the mysql server deployment.
      enter password for user root:    #输入上一步骤中获取的安装mysql时自动设置的root用户密码
      the existing password for the user account root has expired. please set a new password.
      new password:  #设置新的root用户密码
      re-enter new password:   #再次输入密码
      the 'validate_password' plugin is installed on the server.
      the subsequent steps will run with the existing configuration of the plugin.
      using existing password for root.
      estimated strength of the password: 100
      change the password for root ? ((press y|y for yes, any other key for no) : n   #是否更改root用户密码,输入n
       ... skipping.
      by default, a mysql installation has an anonymous user,
      allowing anyone to log into mysql 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? (press y|y for yes, any other key for no) : y   #是否删除匿名用户,输入y
      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? (press y|y for yes, any other key for no) : y   #禁止root远程登录,输入y
      success.
      by default, mysql 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? (press y|y for yes, any other key for no) : y   #是否删除test库和对它的访问权限,输入y
       - 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? (press y|y for yes, any other key for no) : y   #是否重新加载授权表,输入y
      success.
      all done!
  3. 安装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. 执行以下命令,安装php 7.4。

      yum -y install php74-php-gd php74-php-pdo php74-php-mbstring php74-php-cli php74-php-fpm php74-php-mysqlnd

    5. 执行以下命令,验证php的安装版本。

      php74 -v

      回显如下类似信息:

      php 7.4.33 (cli) (built: jun  6 2023 15:55:08) ( nts )
      k8凯发 copyright (c)  the php group
      zend engine v3.4.0, k8凯发 copyright (c) zend technologies
    6. 执行以下命令,启动php服务并设置开机自启动。

      systemctl start php74-php-fpm

      systemctl enable php74-php-fpm

    7. 修改nginx配置文件以支持php。
      1. 执行以下命令打开配置文件/etc/nginx/nginx.conf。
        vim /etc/nginx/nginx.conf
        图3 nginx.conf

        从nginx.conf可以看出,配置文件定向至/etc/nginx/conf.d/*.conf。

      2. 输入:quit退出nginx.conf。
      3. 执行以下命令打开配置文件/etc/nginx/conf.d/default.conf。

        vim /etc/nginx/conf.d/default.conf

      4. i键进入编辑模式。
      5. 修改打开的“default.conf”文件。
        找到server段落,修改或添加下列配置信息。
            server {
                listen       80;
                server_name  localhost;
                #access_log /var/log/nginx/host.access.log  main;
            location / {
                root   /usr/share/nginx/html;
                index  index.php index.html index.htm;    }
            location ~ \.php$ {
                root           html;
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_param  script_filename /usr/share/nginx/html$fastcgi_script_name;
                include        fastcgi_params;
            }

        图4所示:

        图4 修改后截图
      6. esc键退出编辑模式,并输入:wq保存后退出。
    8. 执行以下命令,重新载入nginx的配置文件。

      service nginx reload

  4. 浏览器访问测试。
    1. 在/usr/share/nginx/html目录下创建“info.php”的测试页面。
      1. 执行以下命令创建并打开“info.php”的测试文件。

        vim /usr/share/nginx/html/info.php

      2. i键进入编辑模式。
      3. 修改打开的“info.php”文件,将如下内容写入文件。
      4. esc键退出编辑模式,并输入:wq保存后退出。
    2. 使用浏览器访问“http://服务器ip地址/info.php”,显示如下页面,说明环境搭建成功。

  5. 创建数据库。
    1. 执行以下命令,并按照提示信息输入mysql的root用户,登录到mysql命令行。

      mysql -u root -p

    2. 执行以下命令,创建一个新的数据库。

      create database wordpress;

      其中,“wordpress”为数据库名,可以自行设置。

    3. 执行以下命令,为数据库创建用户并为用户分配数据库的完全访问权限。

      grant all on wordpress.* to wordpressuser@localhost identified by 'block@123';

      其中,“wordpressuser”为数据库用户名,“block@123”为对应的帐户密码,可以自行设置。

    4. 执行以下命令,退出mysql命令行。

      exit

    5. (可选)依次执行以下命令,验证数据库和用户是否已成功创建,并退出mysql命令行。

      mysql -u wordpressuser -p

      show databases

      exit

      其中,“wordpressuser”为刚刚创建的数据库用户名。

  6. 安装wordpress。
    1. 请自行获取wordpress软件包并上传至/usr/share/nginx/html目录。操作方法请参见。

      后续操作软件包以“wordpress-6.4.2.tar.gz”为例。

    2. 执行以下命令,进入/usr/share/nginx/html/目录,解压缩软件包。

      cd /usr/share/nginx/html

      tar zxvf wordpress-6.4.2.tar.gz

      解压后生成一个“wordpress”的文件夹。

    3. 执行以下命令,进入 wordpress 安装目录,将wp-config-sample.php文件复制到wp-config.php文件中,并将原先的示例配置文件保留作为备份。

      cd /usr/share/nginx/html/wordpress

      cp wp-config-sample.php wp-config.php

    4. 执行以下命令,打开并编辑新创建的配置文件。

      vim wp-config.php

    5. i键进入编辑模式。找到文件中mysql的部分,并将相关配置信息修改为步骤5中的内容。
      图5 修改mysql配置
    6. esc键退出编辑模式,并输入:wq保存后退出。
    7. 浏览器访问“http://服务器ip地址/wordpress”进入安装向导。
      图6 安装向导
    8. 设置站点标题、管理员账号、密码和邮箱,并单击“安装 wordpress”。
      表3 配置参数

      参数

      说明

      站点标题

      wordpress网站名称。

      用户名

      wordpress管理员名称。

      密码

      可以使用默认的密码或者自定义密码。

      请勿重复使用现有密码,并确保将密码保存在安全的位置。

      您的电子邮箱地址

      接收通知的电子邮件地址。

    9. 安装完成后,弹出安装成功界面。
      图7 安装成功
    10. 单击“登录”,或者浏览器访问“http://服务器ip地址/wordpress/wp-login.php”,输入用户名/电子邮箱地址和密码后单击“登录”,进入wordpress。
      图8 登录wordpress
      图9 进入wordpress界面
  7. 购买域名。

    为了便于网站的访问和使用,可以给网站设置一个单独的域名,使用域名访问网站。首先,需要在域名注册商处获得授权的域名。

  8. 进行备案。

    如果网站未进行备案,且需要使用华为云进行托管,则需要通过华为云备案系统进行备案。具体操作请参见。

  9. 配置域名解析。

    配置域名解析后才能使用注册的域名访问网站。具体操作请参见。

    例如,配置的域名为“www.example.com”,配置成功后,可在浏览器地址栏中输入“http://www.example.com”访问部署的网站。

实施步骤(自动)

分享:
网站地图