NET Core 上运行的 WordPress

在.NET Core 上运行的 WordPress,无需安装PHP既可跨平台运行WordPress。

在Peachpie中实现PHP所需的功能数月后,现在终于可以运行一个真实的应用程序:WordPress。

本文是基于Peachpie https://github.com/iolevel/peachpie

Peachpie是一个基于Microsoft的Roslyn的现代PHP编译器。

在.NET上运行WordPress

流行的Phalanger项目已经证明,可以在Microsoft .NET上运行几乎未经修改的WordPress应用。

但是这个解决方案存在着问题,与新的WordPress版本不兼容。现在,Peachpie 也能够将WordPress作为一个完全托管的应用程序运行在.NET和.NET Core上。

这只是一个证明Peachpie仍然是一个正在进行中的项目。不建议在生产环境中使用它

本篇文章主要目的是证明Peachpie真的与WordPress中使用的标准PHP兼容,并展示其优点。

先决条件:

.NET Core 1.0

MySQL Server

对WordPress修改

由于Peachpie 0.5.0版本,编译器不支持扩展有条件声明的类,如

if (condition) { class X {} }
class Y extends X {} // extending conditionally declared class
wp-includes/class-json.php:
  • 注释条件 if (!class_exists(...))
  • 注释第一个Services_JSON_Error类,保留第二个

这里准备了一个修改好的WordPress版本,已经包括上面修改,使你编译项目更容易。

.NET Core WordPress

预先修改 wp-config.php 配置了包含MySQL数据库的凭据的文件。使用默认端口3306,密码为'' ,服务器是'localhost'。这里大家根据实际情况进行修改。

编译WordPress

编译由dotnet及其website/project.json 项目文件驱动。

{
"version": "1.0.0", "buildOptions": {
"compilerName": "php",
"compile": "**\\*.php",
"debugType": "portable",
"xmlDoc": true
},
"dependencies": {
"Peachpie.App": "0.5.0-*"
},
"tools": {
"Peachpie.Compiler.Tools": "0.5.0-*"
},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0"
}
}
}
}
}

使用 Peachpie.Compiler.Tools 进行编译WordPress项目。

然后有一个app 项目也就是ASP.NET Core。

static void Main() {
var root = Path.GetDirectoryName(System.IO.Directory.GetCurrentDirectory()) + "/website"; var host = new WebHostBuilder()
.UseKestrel()
.UseWebRoot(root).UseContentRoot(root) // content root with wp static files
.UseUrls("http://*:5004/")
.UseStartup<Startup>() // initialization routine, see below
.Build(); host.Run();
} class Startup {
public void Configure(IApplicationBuilder app) {
Pchp.Core.Context.DefaultErrorHandler = new Pchp.Core.CustomErrorHandler(); // disables debug asserts app.UsePhp(); // installs handler for *.php files and forwards them to our website.dll
app.UseDefaultFiles();
app.UseStaticFiles();
}
}

接着还原项目,在根目录下dotnet restore.

还原好以后cd app dotnet run

然后访问http://localhost:5004/ ,只要MySQL 配置正确,就会跳转至安装界面。注意要先在数据库中创建wordpress 数据库。

为了证明该网站真的在.NET Core上运行,我们可以反编译website.dll 看看。

参考文档:

https://github.com/linezero/peachpie-wordpress

https://github.com/iolevel/peachpie-wordpress

http://www.peachpie.io/2017/02/wordpress-announcement.html

如果你觉得本文对你有帮助,请点击“推荐”,谢谢。

ASP.NET Core实践交流群: 133144964

.NET Core 跨平台交流群: 550897034
博客示例代码GitHub:https://github.com/linezero/Blog

NET Core WordPress的更多相关文章

  1. 在.NET Core 上运行的 WordPress

    在.NET Core 上运行的 WordPress,无需安装PHP既可跨平台运行WordPress. 在Peachpie中实现PHP所需的功能数月后,现在终于可以运行一个真实的应用程序:WordPre ...

  2. WordPress 主题开发 - (六) 创建主题函数 待翻译

    We’ve got a file structure in place, now let’s start adding things to them! First, we’re going to ad ...

  3. [EXP]WordPress Core 5.0 - Remote Code Execution

    var wpnonce = ''; var ajaxnonce = ''; var wp_attached_file = ''; var imgurl = ''; var postajaxdata = ...

  4. 搭建自己的apache tomcat php mysql 环境和WordPress站点制作

    无论你是web开发人员,还是程序员,拥有一个自己的站点总没有坏处,下面我们就从搭建wordpress的环境来说吧. 1.首先wordpre是用的php语言,所以需要php环境,最基本的数据库也不能缺少 ...

  5. WordPress访问打开速度很慢的几种解决方法

    最近WordPress网站访问特别的慢,有时间要加载一分钟才能完全打开,最初怀疑是服务器的问题,经过多方测试,还是没找到原因.后来,通过工具测出浏览器一直在加载fonts.googleapis.com ...

  6. Windows下apache php wordpress配置

    2. Use notepad to open httpd.conf config file. Make use the line "LoadModule rewrite_module mod ...

  7. 给WordPress Page页面添加摘要输入框

    默认情况下 WordPress Page 编辑页面没有摘要(Excerpt)输入框,所以对 WordPress 进行 SEO 的时候比较麻烦. 这个时候我们就可以通过以下代码给我 WordPress ...

  8. 25款漂亮的 WordPress 杂志主题

    WordPress是一个免费和开源博客工具和一个内容管理系统(CMS)基于 PHP 和 MySQL,它运行在一个 Web 托管服务.每个月的 WordPress 主题是由开发人员,其中用户喜欢使用 W ...

  9. How to install Wordpress 4.0 on CentOS 7.0

    This document describes how to install and configure Wordpress 4.0 on CentOS 7.0. WordPress started ...

随机推荐

  1. (转)RTMP协议从入门到放弃

    转载自:  http://blog.csdn.net/shangmingyang/article/details/50837852 RTMP协议是Real Time Message Protocol( ...

  2. unity3d mvvm c#

    using UnityEngine; using System.Collections; public interface IState { void BeforEnter(); void Befor ...

  3. UVA1389 Hard Life[二分答案+最小割]

    我真菜啊←地址 求最大密度子图方案.密度=边数/点数 假设E,V为最大密度子图的边数点数.则$\forall \rho$有$\rho \leqslant \frac{E}{V}$即$E- \rho V ...

  4. Set_ML

    参考资料:斯坦福(http://cs231n.github.io/linear-classify/:http://cs231n.stanford.edu/slides/2017/) Mastering ...

  5. hibernate学习五 Hibernate补充

    1  MiddleGenIDE可以生成映射类和映射文件. 2

  6. Linux 切换字符界面和图形界面

    1. 切换方式 # root 权限 systemctl get-default # 获取当前模式 systemctl set-default graphical.target # 设置开机为图形界面 ...

  7. Linux命令总结_touch创建文件

    1.touch命令,用来创建文件或者修改文件时间戳 格式:touch [选项]... 文件... 选项 : -a   或--time=atime或--time=access或--time=use  只 ...

  8. 转:使用 VisualVM 进行性能分析及调优

    使用 VisualVM 进行性能分析及调优 VisualVM 是一款免费的\集成了多个 JDK 命令行工具的可视化工具,它能为您提供强大的分析能力,对 Java 应用程序做性能分析和调优.这些功能包括 ...

  9. Spring Boot实现学生信息增删改查

    上一篇博客写了如何初始化一个简单的Spring Boot项目,这次详细记录一下如何连接数据库并实现增删改查基本操作. 我使用的是MySQL 5.5+Navicat,MySQL量级比较轻,当然微软的SQ ...

  10. HDU - 6081 2017百度之星资格赛 度度熊的王国战略

    度度熊的王国战略  Accepts: 644  Submissions: 5880  Time Limit: 40000/20000 MS (Java/Others)  Memory Limit: 3 ...