WordPress is a popular cms that tons of folks leverage for their businesses every day, but did you know that you could also run WordPress on.net core.
In this post, we’re going to see just exactly how we can do that. WordPress is a popular blogging system cms, and a lot of people run their businesses on WordPress. It powers around 30% of the websites. It has tens of thousands of plugins, and, contrary to what some people might say, it’s still by far the most popular and most widely used content management system on the internet. On the other hand, .net is very powerful in security, performance, and so on, but it lacks the content management system. So, isn’t it amazing to combine the best of both of those worlds? Hence, you get WordPress, which is fantastic in terms of all the plugins that you have. You can build a website from scratch in a short period and then combine it with all the advantages that .net offers: performance, security, a vast company backing its constant development, and continuous bug fixes.
Yes, WordPress on .net is possible with peachpie, that is a compiler built on top of the Roslyn platform, it’s a set of runtime and base class libraries and everything that allows compiling a PHP project, a group of PHP files into a regular .net project
How is it possible?
All the WordPress source files are compiled into a DLL file. Thanks to the peachpie project, we can use this compilation and integrate it into the asp.net core website running on the kestrel web server without any PHP or any unmanaged code. Everything is running purely on managed .net, taking advantage of the garbage collector and compiler. It is possible because everything in the ecosystem is rewritten from scratch in c sharp as a managed solution
How can I use the WordPress plugin?
You can use the WordPress plugin in different ways, and it has been well explained in their documentation. You can copy your existing plugins into a project, compile them as WordPress, so the first option is to compile them and create a .net project from them.
The second option is that peachpie has automatically compiled most of the plugins and themes into NuGet packages and already provided them on the NuGet feed to add a dependency in your project and use those plugins
Can I create a WordPress plugin in C#?
Yes, you can create plugins for WordPress in c-sharp or razor partial views and use it in your WordPress on .net installation.
Getting started with WordPress in .NET Core
You need to create an empty ASP.NET core project first.
You can use your existing asp.net core application as well.
The WordPress is already compiled and provided on the NuGet feed to add a dependency to the package, called PeachPied.WordPress.AspNetCore.
The next step is to add useWordPress in our request pipeline.
That’s it; now we have the WordPress in our asp.net core project.
We can also configure WordPress as our requirement. Here I have configured by DbPassword.
Now we need to set up a WordPress database. You can install MySQL on your system or use docker or any other services to create a single empty database.
Yes, you don’t need to install PHP or any web server for WordPress. Visual Studio or VS Code, dotnet SDK, NuGet package, and you are good to go.
Now we can run our WordPress application with default settings.
You can see the WordPress installation screen.
Great, so How can I upgrade my WordPress when a newer version comes?
Update the NuGet package. That’s it.
Peachpie has automated this process, so when the new WordPress comes out, it just fires action on their DevOps, creates a new package, runs the tests, and publishes the package so you will have the latest versions of WordPress as soon as it is available.
How can I use themes and plugins in WordPress that runs on .net Core?
First thing, the core WordPress is compiled, and you cannot modify it. The same applies to theme and plugins; they have to be compiled. PeachPie has modified the WordPress dashboard so that we can see the list of existing plugins, but they are not from wordpress.org, but they are compiled plugins.
The plugins you can see on your dashboard are NuGet packages. So it will download the NuGet package, extracts it, and in runtime, it loads the assembly into the memory, and you can activate it, which is similar to core WordPress.
Another way is to add peachpie feed in NuGet.
And then, you can install a plugin from the NuGet package manager.
OK, now tell me, Can I install my own custom Plugin in WordPress running on .net Core?
Well, yes, it is possible, but you need to compile it. You can create a new PeachPie Project, add your custom plugins as shown below, reference the project, and you are done.
You can see the plugins in your WordPress site now.
WordPress ecosystem has many great plugins, and we get .net performance, tooling of visual studio, and all the kinds of stuff that we are familiar with.