Learn more about WordPress running on. NET Core

Source: Internet
Author: User
Tags dotnet php compiler wordpress database
WordPress runs on. NET Core without having to install PHP to run WordPress across platforms.





After several months of implementing PHP's functionality in Peachpie, you can now 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's Roslyn.



Running WordPress on. Net



The popular Phalanger project has proven to be available at Microsoft. NET to run almost unmodified WordPress apps.



However, there is a problem with this solution and is incompatible with the new version of WordPress. Now, Peachpie is also able to run WordPress as a fully managed application on. NET and. NET Core.



This is just a proof thatPeachpie is still an ongoing project. It is not recommended to use it in a production environment .



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



Prerequisite:



. NET Core 1.0



MySQL Server



Changes to WordPress



Because of the Peachpie 0.5.0 version, the compiler does not support extending conditionally declared classes, such as


if (condition) { class X {} }
class Y extends X {} 
// extending conditionally declared class


wp-includes/class-json.php:


    • Comment Condition if (!class_exists (...))

    • Note the first Services_json_error class, preserving the second


A modified version of WordPress has been prepared, which includes the above modifications to make it easier for you to compile the project.



. NET Core WordPress



Prewp-config.php-modified files configured with the credentials of the MySQL database. Using the default port 3306, the password is ' ', the server is ' localhost '. Here everyone changes according to the actual situation.



Compiling WordPress



compiled by dotnet and its website/project.jsonProject Files Drive .


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


Compile the WordPress project using Peachpie.Compiler.Tools.



Then there is an app project called ASP.


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 dotnet restore under the root directory.



Restore the CD app Dotnet run later






Then access http://localhost:5004/, as long as the MySQL configuration is correct, will jump to the installation interface. Note To create the WordPress database in the database first.






To prove that the site is really running on. NET core, we can decompile Website.dll to see.





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.