整个WordPress均已编译为.NET Core,并带有PeachPie的NuGet软件包

Why? Because it's awesome. Sometimes a project comes along that is impossibly ambitious and it works. I've blogged a little about Peachpie, the open source PHP compiler that runs PHP under .NET Core. It's a project hosted at https://www.peachpie.io.

为什么? 因为很棒有时,一个无法实现的雄心勃勃的项目来了,并且它可行。 我已经写了一些有关Peachpie的博客,Peachpie是在.NET Core下运行PHP的开源PHP编译器。 这是一个托管在https://www.peachpie.io的项目。

But...why? Here's why:

但为什么? 原因如下:

  1. Performance: compiled code is fast and also optimized by the .NET Just-in-Time Compiler for your actual system. Additionally, the .NET performance profiler may be used to resolve bottlenecks.

    性能:编译后的代码速度很快,而且.NET即时编译器还为您的实际系统进行了优化。 此外,.NET性能分析器可用于解决瓶颈。

  2. C# Extensibility: plugin functionality can be implemented in a separate C# project and/or PHP plugins may use .NET libraries.

    C#可扩展性:插件功能可以在单独的C#项目中实现,并且/或者PHP插件可以使用.NET库。

  3. Sourceless distribution: after the compilation, most of the source files are not needed.

    无源分发:编译后,不需要大多数源文件。

  4. Power of .NET: Peachpie allows the compiled WordPress clone to run in a .NET JIT'ted, secure and manageable environment, updated through windows update.

    .NET的功能: Peachpie允许编译的WordPress克隆在.NET JIT设置,安全且可管理的环境中运行,并通过Windows Update进行更新。

  5. No need to install PHP: Peachpie is a modern compiler platform and runtime distributed as a dependency to your .NET project. It is downloaded automatically on demand as a NuGet package or it can be even deployed standalone together with the compiled application as its library dependency.

    无需安装PHP: Peachpie是一个现代的编译器平台,其运行时作为对.NET项目的依赖项进行分发。 它可以根据需要作为NuGet软件包自动下载,或者甚至可以与已编译的应用程序一起作为库依赖项独立部署。

A year ago you could very happily run Wordpress (a very NON-trivial PHP application, to be clear) under .NET Core using Peachpie. You would compile your PHP into an assembly and then do something like this in your Startup.cs:

一年前,您可以使用Peachpie在.NET Core下非常愉快地运行Wordpress(一个非常简单PHP应用程序,很明显)。 您可以将PHP编译为程序集,然后在Startup.cs中执行以下操作:

public void Configure(IApplicationBuilder app)
{
    app.UseSession();

    app.UsePhp(new PhpRequestOptions(scriptAssemblyName: "peachweb"));
    app.UseDefaultFiles();
    app.UseStaticFiles();
}

And that's awesome. However, I noticed something on their GitHub recently, specifically under https://github.com/iolevel/wpdotnet-sdk. It says:

太棒了。 但是,我最近在他们的GitHub上注意到了一些东西,特别是在https://github.com/iolevel/wpdotnet-sdk下。 它说:

The solution compiles all of WordPress into a .NET assembly and additionally provides C# wrappers for utilization of compiled sources.

该解决方案将所有WordPress编译为.NET程序集,并另外提供C#包装程序以利用已编译的源代码。

Whoa. Drink that in. The project consists of several parts:

哇喝点饮料。该项目包括几个部分:

  • wordpress contains sources of WordPress that are compiled into a single .NET Core assembly (wordpress.dll). Together with its content files it is packed into a NuGet package PeachPied.WordPress. The project additionally contains the "must-use" plugin peachpie-api.php which exposes the WordPress API to .NET.

    wordpress包含WordPress的源代码,这些源代码被编译成单个.NET Core程序集( wordpress.dll )。 连同其内容文件一起被打包到一个NuGet包PeachPied.WordPress 。 该项目还包含“必用”插件peachpie-api.php ,该插件将WordPress API公开给.NET。

  • PeachPied.WordPress.Sdk defines abstraction layer providing .NET interfaces over PHP WordPress instance. The interface is implemented and provided by peachpie-api.php.

    PeachPied.WordPress.Sdk定义了在PHP WordPress实例上提供.NET接口的抽象层。 该接口由peachpie-api.php实现并提供。

  • PeachPied.WordPress.AspNetCore is an ASP.NET Core request handler that configures the ASP.NET pipeline to pass requests to compiled WordPress scripts. The configuration includes response caching, short URL mapping, various .NET enhancements and the settings of WordPress database.

    PeachPied.WordPress.AspNetCore是一个ASP.NET Core请求处理程序,它配置ASP.NET管道以将请求传递给已编译的WordPress脚本。 该配置包括响应缓存,简短的URL映射,各种.NET增强功能以​​及WordPress数据库的设置。

  • app project is the executable demo ASP.NET Core web server making use of compiled WordPress.

    app项目是使用编译后的WordPress的可执行演示ASP.NET Core Web服务器。

They compiled the whole of WordPress into a NuGet Package.

他们将整个WordPress编译为NuGet软件包。

YES.

是。

  • The compiled website runs on .NET Core

    编译的网站在.NET Core上运行
  • You're using ASP.NET Core request handling and you can extend WordPress with C# plugins and themes

    您正在使用ASP.NET Core请求处理,并且可以使用C#插件和主题扩展WordPress。

Seriously. Go get the .NET Core SDK version 2.1.301 over at https://dot.net and clone their repository locally from https://github.com/iolevel/wpdotnet-sdk.

说真的在https://dot.net上获取.NET Core SDK版本2.1.301,并从https://github.com/iolevel/wpdotnet-sdk在本地克隆其存储库。

Make sure you have a copy of mySQL running. I get one started FAST with Docker using this command:

确保您具有运行的mySQL的副本。 我使用以下命令使用Docker启动了FAST:

docker run --name=mysql1 -p 3306:3306 -e MYSQL_ROOT_PASSWORD=password -e MYSQL_DATABASE=wordpress mysql --default-authentication-plugin=mysql_native_password

Then just "dotnet build" at the root of the project, then go into the app folder and "dotnet run." It will show up on localhost:5004.

然后,只需在项目根目录下进行“ dotnet构建”,然后进入app文件夹并“ dotnet运行”即可。 它将显示在localhost:5004上。

NOTE: I needed to include the default authentication method to prevent the generic Wordpress "Cannot establish database connection." I also added the MYSQL_DATABASE environment variable so I could avoid logging initially using the mysql client and creating the database manually with "CREATE DATABASE wordpress."

注意:我需要包括默认的身份验证方法,以防止通用Wordpress“无法建立数据库连接”。 我还添加了MYSQL_DATABASE环境变量,因此可以避免最初使用mysql客户端登录并通过“ CREATE DATABASE wordpress”手动创建数据库。

Look at that. I have my mySQL in one terminal listening on 3306, and ASP.NET Core 2.1 running on port 5004 hosting freaking WordPress compiled into a single NuGet package.

看那个。 我在一个终端上侦听3306上的mySQL,在端口5004上运行的ASP.NET Core 2.1托管怪异的WordPress,并将其编译为单个NuGet包。

Wordpress under .NET Core

Here's my bin folder:

这是我的bin文件夹:

WordPress as a single DLL

There's no PHP files which is a nice security bonus - not only are you running from the one assembly but there's no text files for any rogue plugins to modify or corrupt.

没有PHP文件,这是一个不错的安全性奖励-不仅您是从一个程序集中运行,而且没有文本文件供任何恶意插件修改或破坏。

Here's the ASP.NET Core 2.1 app that hosts it, in full:

这是完全托管它的ASP.NET Core 2.1应用程序:

using System.IO;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using PeachPied.WordPress.AspNetCore;

namespace peachserver
{
    class Program
    {
        static void Main(string[] args)
        {
            // make sure cwd is not app\ but its parent:
            if (Path.GetFileName(Directory.GetCurrentDirectory()) == "app")
            {
                Directory.SetCurrentDirectory(Path.GetDirectoryName(Directory.GetCurrentDirectory()));
            }

            //
            var host = WebHost.CreateDefaultBuilder(args)
                .UseStartup<Startup>()
                .UseUrls("http://*:5004/")
                .Build();

            host.Run();
        }
    }

    class Startup
    {
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, IConfiguration configuration)
        {
            // settings:
            var wpconfig = new WordPressConfig();
            configuration
                .GetSection("WordPress")
                .Bind(wpconfig);

            //
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseWordPress(wpconfig);

            app.UseDefaultFiles();
        }
    }
}

I think the app.UseWordPress() is such a nice touch. ;)

我认为app.UseWordPress()这个应用程序真是太好了。 ;)

I often get emails from .NET developers asking what blog engine they should consider. Today, I think you should look closely at Peachpie and strongly consider running WordPress under .NET Core. It's a wonderful open source project that brings two fantastic ecosystems together! I'm looking forward to exploring this project more and I'd encourage you to check it out and get involved with Peachpie.

我经常收到来自.NET开发人员的电子邮件,询问他们应该考虑使用哪种博客引擎。 今天,我认为您应该仔细研究Peachpie,并强烈考虑在.NET Core下运行WordPress。 这是一个很棒的开源项目,将两个出色的生态系统融合在一起! 我期待着进一步探索这个项目,并鼓励您进行检查并参与Peachpie

Sponsor: Check out dotMemory Unit, a free unit testing framework for fighting all kinds of memory issues in your code. Extend your unit testing with the functionality of a memory profiler!

赞助商:查看dotMemory Unit ,这是一个免费的单元测试框架,用于解决代码中的各种内存问题。 使用内存分析器的功能扩展您的单元测试!

翻译自: https://www.hanselman.com/blog/the-whole-of-wordpress-compiled-to-net-core-and-a-nuget-package-with-peachpie

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值