在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 看看。
以上就是详细了解在.net core 上运行的wordpress的详细内容。
