Ubuntu 18.04 搭建维护与改造你的 Wordpress

Quick Summary

Ubuntu Server 基础配置

环境说明
Ubuntu 18.04
服务器信息参考 Evernote

参考资料

服务器基本搭建
Initial Server Setup with Ubuntu 16.04

LAMP技术栈搭建 LAMP Stack Configuration
How To Install Linux, Apache, MySQL, PHP (LAMP) stack on Ubuntu 18.04

Wordpress 部署
How To Install WordPress with LAMP on Ubuntu 16.04

注意 Wordpress 部署的目录权限配置的命令可能有一些问题。

其他次要参考资料

重置 MySQL 密码 / reset MySQL password 【建议使用root用户】 【测试失败】
https://www.vultr.com/docs/reset-mysql-root-password-on-debian-ubuntu

【可用】在 Ubuntu 18.04 环境下重置 MySQL 密码
How to reset root MySQL password on Ubuntu 18.04 Bionic Beaver Linux

流程记录

基本流程记录

1
2
# 以此方式 手动启动 MySQL 服务 可以略过密码认证阶段
sudo /usr/sbin/mysqld --skip-grant-tables --skip-networking &

Create Sudoer User

1
2
3
4
# Ubuntu 18.04 LTS \n \l
adduser <username>
passwd <username>
usermod -aG sudo <username>

LAMP Stack Configuration

Apache2

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 安装 Apache2
sudo apt-get update
sudo apt-get install apache2
# 检查配置项
sudo apache2ctl configtest
# 修改 ServerName 配置项
sudo nano /etc/apache2/apache2.conf
# ServerName server_domain_or_IP
# 重启服务器
sudo systemctl restart apache2
# 配置防火墙
sudo ufw allow in "Apache Full"
# 验证访问
http://your_server_IP_address

MySQL

Ubuntu 18.04 预装 MySQL Ver 14.14 Distrib 5.7.22

重置 MySQL root 密码 请参考上方资料。

PHP

php-mcrypt package is missing in ubuntu-server 18.04 LTS?
https://askubuntu.com/questions/1031921/php-mcrypt-package-is-missing-in-ubuntu-server-18-04-lts

1
2
3
4
5
6
7
sudo apt-get install php libapache2-mod-php php-mysql [php-mcrypt]
sudo add-apt-repository ppa:ondrej/php
sudo apt-get install php7.1-mcrypt
sudo apt-get install php5.6-mcrypt
sudo apt-get install php7.0-mcrypt
# https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu-16-04
sudo nano /etc/apache2/mods-enabled/dir.conf

Install WordPress with LAMP

Step 1: Create a MySQL Database and User for WordPress

1
2
3
4
5
mysql -u root -p
CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
GRANT ALL ON wordpress.* TO 'wordpressuser'@'localhost' IDENTIFIED BY 'WPpassw@rd2018';
FLUSH PRIVILEGES;
EXIT;

Step 2: Install Additional PHP Extensions

1
2
sudo apt-get install php-curl php-gd php-mbstring php-xml php-xmlrpc [php-mcrypt]
sudo systemctl restart apache2

Step 3: Adjust Apache’s Configuration to Allow for .htaccess Overrides and Rewrites

1
2
3
4
5
6
7
sudo vim /etc/apache2/apache2.conf
<Directory /var/www/html/>
AllowOverride All
</Directory>
sudo a2enmod rewrite
sudo apache2ctl configtest
sudo systemctl restart apache2

Step 4: Download WordPress

1
2
cd /tmp
curl -O https://wordpress.org/latest.tar.gz

如何修复 Wordpress Internal 500 错误

检查 Apache 是否故障
digitalocean 的 教程似乎权限配置有问题,不应该按照他的提示修改权限。
https://www.digitalocean.com/community/tutorials/how-to-install-wordpress-with-lamp-on-ubuntu-16-04

调试思路

1
2
3
4
5
6
7
8
9
# http://wp.blkstone.me/index.html
# 1. 确认 Apache 可以解析 静态HTML
http://your_server_IP_address/index.html
sudo chown -R jack:www-data /var/www/html
# 2. 确认 Apache 可以解析 phpinfo()
<?php
phpinfo();
?>

错误的权限配置导致 wordpress 无法上传文件

错误信息

1
Unable to create directory wp-content/uploads/2018/05. Is its parent directory writable by the server?

操作说明

1
2
3
4
5
6
7
cd /var/www/html/wp-content
mkdir uploads
chown -R jack:www-data uploads
chmod 770 -R uploads
chmod 770 -R themes
chmod 770 -R plugins
systemctl restart apache2

经过测试 760, 660 均无法正常上传文件。
关于这个 770 的潜在隐患,
如果服务器上没其他用户,一般来说没问题,如果是虚拟主机,可能会有跨的问题 (phith0n)

安全配置参考

带上 Nginx
https://blog.csdn.net/hrayha/article/details/45767003

Wordpress 迁移指南

经常性的在服务器和本地之间测试迁移

Moving WordPress
https://codex.wordpress.org/Moving_WordPress

备份

推荐插件 All-in-One WP Migration

编辑器与语法高亮
WP Markdown Editor
Crayon Syntax Highlighter

在 WordPress 里使用Markdown和语法高亮
http://tuziel.com/blog/2017/03/use-markdown-and-syntax-highlight-in-wordpress/

注意事项 Wordpress 管理员的用户名和密码会被覆盖

其他备份插件
http://www.jiangwenrou.com/%E5%A6%82%E4%BD%95%E8%87%AA%E5%8A%A8%E5%A4%87%E4%BB%BDwordpress%E6%95%B4%E7%AB%99.html
https://www.zhihu.com/question/35115061
https://www.wpdaxue.com/backwpup.html

Markdown 迁移

Markdown Importer
https://wordpress.org/plugins/markdown-importer/

Wordpres 改进指南

Mario Peshev - Code Architecture With WordPress
https://www.youtube.com/watch?v=vlaPRUyNTlg&t=1564s

Wordpress Template Hierachy Explained
Make sense of WP Core load