文章目录
前言
搭建一个wordpress的个人博客,这里使用LAMP的结构搭配,分别是linux、Apache、php、mariadb
一、实验环境
这里使用的是centos7.6的系统
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
服务器IP
[root@localhost ~]# ifconfig ens32 | awk 'NR==2{print $2}'
192.168.38.34
二、搭建步骤
2.1 清空防火墙规则
[root@localhost ~]# iptables -F
[root@localhost ~]# systemctl stop firewalld.service
[root@localhost ~]#
2.2 临时关闭selinux
[root@localhost ~]# setenforce 0
2.3 检查网络状态
[root@localhost ~]# ping -c1 192.168.38.34
PING 192.168.38.34 (192.168.38.34) 56(84) bytes of data.
64 bytes from 192.168.38.34: icmp_seq=1 ttl=64 time=0.017 ms
--- 192.168.38.34 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.017/0.017/0.017/0.000 ms
2.4 查看本地光盘是否已经有挂载上
[root@localhost ~]# df -h /mnt
文件系统 容量 已用 可用 已用% 挂载点
/dev/sr0 4.3G 4.3G 0 100% /mnt
2.5 查看yum源状态
[root@localhost ~]# yum repolist
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: ftp.sjtu.edu.cn
* extras: ftp.sjtu.edu.cn
* updates: ftp.sjtu.edu.cn
源标识 源名称 状态
base/7/x86_64 CentOS-7 - Base 10,072
epel/x86_64 Extra Packages for Enterprise Linux 7 - x86_64 13,744
extras/7/x86_64 CentOS-7 - Extras 515
updates/7/x86_64 CentOS-7 - Updates 4,691
repolist: 29,022
2.6 系统默认装的是PHP5.4,而这里要配置的是PHP7以上的程序,所以需要更换包括PHP7以上的源
[root@localhost ~]# rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
获取https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
警告:/var/tmp/rpm-tmp.LWDuV7: 头V4 RSA/SHA256 Signature, 密钥 ID 352c64e5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:epel-release-7-14 警告:/etc/yum.repos.d/epel.repo 已建立为 /etc/yum.repos.d/epel.repo.rpmnew
################################# [100%]
[root@localhost ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm #更换包括php7的源
获取https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
警告:/var/tmp/rpm-tmp.Oh7fvu: 头V4 RSA/SHA1 Signature, 密钥 ID 62e74ca5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:webtatic-release-7-3 ################################# [100%]
2.7 下载安装remi包(包含PHP7.0 7.1 7.2),并且更换remi-php72 来指定预安装的php版本
[root@localhost ~]# yum install -y http://rpms.remirepo.net/enterprise/remi-release-7.rpm
[root@localhost ~]# yum-config-manager --enable remi-php72
已加载插件:fastestmirror, langpacks
=============================== repo: remi-php72 ===============================
[remi-php72]
async = True
..... #此处省略
ui_repoid_vars = releasever,
basearch
username =
2.8 下载安装LAMP所需要的软件包
[root@localhost ~]# yum install php php-mysql php-mysqlnd httpd mariadb mariadb-server -y
2.9 启动程序服务
[root@localhost ~]# systemctl restart httpd
[root@localhost ~]# systemctl restart mariadb
[root@localhost ~]# systemctl enable mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
[root@localhost ~]# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[root@localhost ~]# netstat -antup | grep httpd
tcp6 0 0 :::80 :::* LISTEN 14917/httpd
[root@localhost ~]# netstat -antup | grep mysqld
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 15196/mysqld
2.10 创建数据库并授权
[root@localhost ~]# mysql
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)]> create database wordpress; #创建数据库
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> grant all privileges on wordpress.* to 'wordpress'@'localhost'identified by '123456';
Query OK, 0 rows affected (0.00 sec) #授权WordPress用户访问本地WordPress数据库
MariaDB [(none)]> exit
Bye
2.11 上传wordpress包并移动到对应的目录下,(在Xshell上用rz命令上传wordpress)
下载 | WordPress.org China 简体中文 -- wordpress所在位置
[root@localhost ~]# rz
[root@localhost ~]# ll wordpress-6.1.1-zh_CN.zip
-rw-r--r--. 1 root root 25206808 12月 29 22:15 wordpress-6.1.1-zh_CN.zip
[root@localhost ~]# unzip wordpress-6.1.1-zh_CN.zip
[root@localhost ~]# mv wordpress /var/www/html/
[root@localhost html]# chown -R apache:apache wordpress/ #修改目录属主属组权限
[root@localhost html]# ll -d wordpress/
drwxr-xr-x. 5 apache apache 4096 12月 18 15:00 wordpress/
记得要修改wordpress的属主属组权限,不然wordpress无法写入信息到文件中
2.12 配置Apache主配置文件
[root@localhost html]# vim /etc/httpd/conf/httpd.conf
[root@localhost html]# systemctl restart httpd.service
[root@localhost html]# tail -n 3 /etc/httpd/conf/httpd.conf
<VirtualHost *:80>
DocumentRoot /var/www/html/wordpress
</Virtualhost>
2.13 开始设置wordpress ,点击 '现在就开始!'
2.14 输入数据库连接信息,都填写好之后点击确认提交
2.15 输入标题、账号、密码、邮箱等,再点击安装wordpress
2.16 接下来你会看到登录的画面,这个时候已经完成了
总结
如果要对外显示自己的网站,则需要有域名才行,并且需要备案好域名;若要购买域名,可到万网(现在在阿里云)等一些大厂,都会有域名出售,备案审核一般要7-14个工作日的时间,有时间不妨搭建属于自己的网站吧,不管是记录生活,还是学习,工作,都是不错的体验。