通过WordPress(基于Apache/PHP/MYSQL)建立博客网站的操作教程

提纲:

一、安装Apache (httpd), PHP, MariaDB (mysql)
二、为WordPress进行数据库创建和写入操作
三、下载和配置WordPress
四、设置安全组规则开放http/https访问(80/80端口)
五、在线安装WordPress

Before start, you need a non-root user ID with sudo privileges:
usermod -aG wheel tianr
Note: wheel is the group for sudoers

install Apache

sudo yum install httpd
sudo systemctl enable httpd
sudo systemctl start httpd
sudo systemctl status httpd
sudo httpd -v

To reload the Apache service after you made some configuration changes:
sudo systemctl reload httpd
You might also reboot to allow update take place.
配置文件所在文件夹:/etc/httpd
主配置文件:/etc/httpd/conf/httpd.conf
virtalhost虚拟主机的配置文件:
/etc/httpd/conf.d/mydomain.com.conf
日志文件(access_log and error_log)所在文件夹:
/var/log/httpd/
常见的域名(网站)文件根目录可以选择如下:
/var/www/
/var/www/html/

install php

sudo yum install epel-release yum-utils
sudo yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
sudo yum-config-manager --enable remi-php73
sudo yum install php php-common php-opcache php-mcrypt php-cli php-gd php-curl php-mysqlnd
php -v

install mariaDB

hostname
hostname -f
sudo yum update
sudo yum install mariadb-server
Enable MariaDB to start on boot and then start the service:
sudo systemctl enable mariadb
sudo systemctl start mariadb
Change the MariaDB root password, remove anonymous user accounts, disable root logins outside of localhost, and remove test databases.
sudo mysql_secure_installation
mysql -u root -p

到此为止建站的基本软件就已经安装到位,下面操作数据库,为WordPress的安装做准备:
mysql -u root -p
mysql> create database wordpress;
mysql> create user wordpressuser@localhost identified by 'yourpassword';
mysql> grant all privileges on wordpress.* to wordpressuser@localhost;
mysql> flush privileges;
mysql> exit

命令和名字一个字母都不要敲错,以上命令是为WordPress创建了一个数据库,一个用户,并赋予该用户操作该数据库的所有权限。在home/tianr/下载WordPress:
wget http://wordpress.org/latest.tar.gz
tar xzvf latest.tar.gz

sudo yum update
sudo yum install php-gd libssh2 libssh2-devel
cd ~/wordpress
cp wp-config-sample.php wp-config.php
vi wp-config.php
修改如下:
define('DB_NAME', 'wordpress');
define('DB_USER', 'wordpressuser');
define('DB_PASSWORD', 'yourpassword')
保存。

复制文件到Apache文件根目录:
sudo rsync -avzP ~/wordpress/ /var/www/html/
cd /var/www/html
mkdir /var/www/html/wp-content/uploads

设置uploads文件夹权限。

在云服务器控制台设置安全组规则,允许公网访问http, https等服务访问,就是要开放80/80端口给所有IP地址(0.0.0.0/0)。具体的:实例-安全组设置-安全组规则-添加安全组规则,设置之后服务器需要reboot。

云解析(域名解析)
http://yourserverIP
or http://yourdomainName

剩下的就是傻瓜式的在线安装配置了。

参考文献:

1 How To Install Apache on CentOS 7 (https://linuxize.com/)
2 Install PHP 7 on CentOS 7 (https://linuxize.com/)
3 How to Install MariaDB on CentOS 7 (https://www.linode.com)
4 Can’t figure out how to install php-gd for PHP7 with yum (https://www.digitalocean.com/)
5 如何在阿里云上部署 WordPress 实例 (alibabacloud.com)