Created: 28 Sep 2022
Last modified: 26 Mar 2023
Wordpress Setup
配置
本文参照官方配置文档:https://wordpress.org/support/article/how-to-install-wordpress/ 整体思路:
- 先安装 apache、mysql、php;
- 下载最新 wordpress 包,解压至 webroot 目录;
- 配置 mysql,并且更新 wp-config.php 文件;
- 登录页面进行配置。
依赖安装
涉及软件包如下:
sudo apt update sudo apt install apache2 \ ghostscript \ libapache2-mod-php \ mysql-server \ php \ php-bcmath \ php-curl \ php-imagick \ php-intl \ php-json \ php-mbstring \ php-mysql \ php-xml \ php-zip
此时可以验证 apache 的安装,通过 systemd 查看进程或者浏览器访问你的 IP
systemctl status apache2.service
数据库配置
该部分可参照:https://ubuntu.com/tutorials/install-and-configure-wordpress#5-configure-database 主要进行如下几项操作:
- create database
- create user
- grant user
~# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 8.0.30-0ubuntu0.22.04.1 (Ubuntu) Copyright (c) 2000, 2022, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> CREATE DATABASE wordpress; Query OK, 1 row affected (0.02 sec) mysql> CREATE USER wordpress@localhost IDENTIFIED BY '1'; Query OK, 0 rows affected (0.04 sec) mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,ALTER ON wordpress.* TO wordpress@localhost; Query OK, 0 rows affected (0.00 sec) mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.01 sec) mysql> quit Bye
上面粘贴完整的交互输出,有几个官方文档说到的点还需要摘录下:
- database 名推荐使用 wordpress;
- 用户名也推荐使用 wordpress;
- 主机名推荐使用 localhost;
- 用户密码使用强密码。
下载 wordpress
下载 wordpress 包,解压并配置 webroot 目录:
为何选择 /srv 目录可以参考这里 https://web.mit.edu/rhel-doc/4/RH-DOCS/rhel-rg-en-4/s1-filesystem-fhs.html
sudo su - cat > /etc/apache2/sites-available/wordpress.conf << EOF <VirtualHost *:80> DocumentRoot /srv/www/wordpress <Directory /srv/www/wordpress> Options FollowSymLinks AllowOverride Limit Options FileInfo DirectoryIndex index.php Require all granted </Directory> <Directory /srv/www/wordpress/wp-content> Options FollowSymLinks Require all granted </Directory> </VirtualHost> EOF a2ensite wordpress a2enmod rewrite a2dissite 000-default service apache2 reload
配置 wordpress 连接 Mysql
mkdir -p /srv/www curl https://wordpress.org/latest.tar.gz | tar zx -C /srv/www mv wp-config-sample.php wp-config.php
编辑器修改 wp-config.php 文件如下部分:
- DBNAME The name of the database you created for WordPress
- DBUSER The username you created for WordPress
- DBPASSWORD The password you chose for the WordPress username
- DBHOST The hostname you determined (usually localhost, but not always; see some possible DBHOST values). If a port, socket, or pipe is necessary, append a colon (:) and then the relevant information to the hostname.
- DBCHARSET The database character set, normally should not be changed (see Editing wp-config.php).
- DBCOLLATE The database collation should normally be left blank (see Editing wp-config.php).
浏览器登录进行配置
创建个人账号部分。
如果主题安装时出现权限错误问题,
Installation failed: Could not create directory
则需更改 wordpress 根目录属主:
chown -R www-data:www-data /srv/www/wordpress/
renyddd by Renyddd is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.