WordPress
Dev Environment
I have recently move my website from one server to another, and I have to build a dev environment the same to product environment.
I did these:
- Dump the database on product environment, and import it into dev environment.
- Download the whole WordPress home directory, replaced it to my dev environment. (Tar it into a single file first, this will save a lot of time)
- Use MailHog on my dev environment for email testing(I cannot use google. And I haven’t test it yet, but it seems pretty good).
— brew install mailhog / brew services start mailhog / brew services stop mailhog
— http://localhost:8025/
— Set the SMTP in WordPress to localhost, port 1025
Update the Plugin
It is more easier to test and develop in local dev environment. I can use script to update the plugins I am developing into local server easily, while using a free server has too many limitations. For example, I have to zip the plugin and upload it through WordPress plugin installation. It was hard to see the results of my codes, especially while I am tuning the appearance of my pages.
I should develop some scripts to update my plugins to the remote server too, since I have full access to the server, but I think I can do that later.
Special Setting
I used multiple site on my WordPress, but in local, it is hard to build the same environment. So I change it into single site, and just develop the current website.
Something Else
I can use a script to update the plugin files into the dir of local server now.
I figured this out but finally found it not necessary: The problem came while I used wp-cli to reactivate the plugin. The database cannot accessed. The point is in xampp, I have to use 127.0.0.1 instead of ‘localhost’ in the database config in wp-config.php.
Still Getting Errors
I got a problem that said “setLocalData” can not be accessed. AI said it was because I used a i18n.js in React, which had some conflicts with the WordPress multi language model. But I changed my code according to the AI and the errors were still on. I have to figure out some other way.
Related Platforms
(Github Issues) / (Notion) / (Blog)
Advertisement
(A website to optimize your resume and to boost your career: Nonpareil.me)
WordPress
开发环境
最近我更换了网站托管服务器,所以需要在本地修改出一个和远程尽量一样的环境。
以下是我的做法:
- 导出数据库再导入到本地。
- 从远程服务器上下载整个Wordpress文件夹(要先压缩,会节约不少时间)。
- 本地安装MailHog用于测试邮件服务。我还没试,不过看起来不错。
— brew install mailhog / brew services start mailhog / brew services stop mailhog
— http://localhost:8025/
— 安装完成后,将WordPress 本地开发环境配置为将 SMTP 服务器设置为 localhost,端口设置为 1025,就可以使用 MailHog 来捕获和查看发送的邮件了
更新插件
本地更新插件更简单。远程托管服务器如果是免费的那种,有太多限制了,比如上传插件只能先压缩打包然后通过Wordpress的安装插件界面上传,效率太低。尤其我在调整页面显示效果时需要频繁修改,这更麻烦。所以还是在本地(有条件的话在一个可以上传文件的远程服务器也差不多),可以用脚本复制文件直接更新。
我也可以写一些脚本让插件直接上传到远端服务器上,不过之后再来做这个。
特殊的变化
远程我用了域名、多站点设置,本地因为域名冲突的问题,我还是使用单站点模式进行开发和测试。
没用上的尝试
当使用wp-cli命令重新激活插件时,提示数据库无法连接。这是因为在wp-config.php文件中,数据库写成了”localhost”,需要修改成”127.0.0.1”。
然而没用上这个功能,插件文件更新后,不需要重新激活插件就可以生效。前端在打开开发者界面时,按着ctrl点击刷新,会出现三个选项,选第二个强制刷新就可以了。
仍然存在的问题
这个问题之前就遇到过,提示“setLocalData”不可用。AI认为这是因为我在React中使用了i18n.js文件,和Wordpress的多语言设置冲突,所以建议我修改。可是我修改之后,问题仍然存在。需要想办法解决。
相关平台
(Github Issues) / (Notion) / (Blog)