WordPress and corewordpress running on. NET Core

Source: Internet
Author: User
Tags php compiler wordpress database wordpress version

WordPress and corewordpress running on. NET Core

For WordPress running on. NET Core, you can run WordPress across platforms without installing PHP.

After several months of implementing the functions required by PHP in Peachpie, you can finally run a real application: WordPress.

This article is based on Peachpie https://github.com/iolevel/peachpie

Peachpie is a modern PHP compiler based on Microsoft Roslyn.

Run WordPress on. NET

The popular Phalanger project has proved that it can run almost unmodified WordPress applications on Microsoft. NET.

However, this solution is incompatible with the new WordPress version. Currently, Peachpie can run WordPress as a fully hosted application on. NET and. NET Core.

This is just a proof,Peachpie is still an ongoing project.We do not recommend that you use it in a production environment..

The main purpose of this article is to prove that Peachpie is truly compatible with the standard PHP used in WordPress and demonstrate its advantages.

Prerequisites:

. NET Core 1.0.

MySQL Server

 

Modify WordPress

Because of Peachpie 0.5.0, the compiler does not support extending classes with conditional declarations, as shown in

if (condition) { class X {} }class Y extends X {} // extending conditionally declared class
Wp-DES/class-json.php:
  • Annotation condition if (! Class_exists (...))
  • Comment out the first Services_JSON_Error class and retain the second class.

Here we have prepared a modified WordPress version, which includes the above modifications to make it easier for you to compile the project.

. NET Core WordPress

Pre-Modificationwp-config.phpThe file that contains the MySQL database creden。 is configured. Use the default port 3306, the password is '', and the server is 'localhost '. You can modify the settings as needed.

 

Compile WordPress

Compile by dotnet andwebsite/project.jsonProject File driver.

{  "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"        }      }    }  }}

Use Peachpie. Compiler. Tools to compile WordPress projects.

Then there is an app project, namely 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();    }}

Then, restore the project and run the dotnet restore command in the root directory.

After restoration, cd app dotnet run

Access http: // localhost: 5004/. If MySQL is correctly configured, the installation page is displayed. Note that you must first create a wordpress database in the database.

To prove that the website is actually running on. NET Core, we can decompile website. dll.

 

Reference:

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

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

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

 

If you think this article is helpful to you, click"Recommendation", Thank you.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.