• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
Email: info@dotnettec.com | Mobile: +91-8800268750

DotNetTec

  • Home
  • Tutorials
    • Programming Language
      • C#
      • JavaScript
    • .Net Development
      • .NET Framework
      • ASP.NET Web Forms
      • MVC Architecture
      • Web API
      • .NET Core Framework
    • Front End Frameworks
      • JavaScript
      • HTML
    • Cloud Computing
      • Microsoft Azure
    • Database
      • SQL Server
    • Google Maps API
    • RPA
      • Blue Prism
      • UiPath
  • How to
  • Knowledge Base
  • Shop

Running WordPress on ASP.NET Core with Peachpie

September 24, 2020 by Ravi Kumar Leave a Comment

In this article, you will learn how to use or integrate WordPress in ASP.NET and Running WordPress on ASP.NET Core, without PHP, or any source files on the server. The following demonstration will show you how to add WordPress as a front-end to an existing ASP.NET Core application step by step.

  • Keep reading on CRUD Operation with Razor Pages in ASP.Net Core 3.1, How to uninstall npm package

Running WordPress on NET Core

WordPress is a free, simplest, and most popular open-source content management system to create your own website or blog which is written in PHP and paired up with MySQL. WordPress on .Net Core is possible with peachpie, which 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.

Peachpie allows for seamless both-way interoperability between PHP and .NET applications. In simpler terms, this means that one can have some parts of an application written in PHP, while other modules are written in .NET and everything will work together as one application. Here is the original Repository of the WordPress SDK by PeachPie.

Here are the following steps to run WordPress with ASP.Net Core:-

Step1: Open your Visual Studio IDE and Create a new project – > ASP.NET Core Web Application

create new project | wordpress on asp.net core

Step 2: Select Web Application: A project template for creating an ASP.Net Core application with example ASP.Net Razor Pages Content.

wordpress on asp.net core

After this, a new project will be created as shown below:-

solution explorer

Step 3: You need to install the specified Package from Nuget. So open your Package Manager Console and run the following command:-

Install-Package PeachPied.WordPress.AspNetCore -Version 5.5.1-preview1

It might take a couple of minutes to install all the necessary packages, as the WordPress package itself is around 30Mb in file size. It took me around 4 minutes or so.

installing package

A new folder will be added named “wordpress” as shown below:-

wordpress

Step 4: Now you need to set up the MySQL database. Make sure that you have the latest versions of both MySQL Server (Community) and MySQL WorkBench installed on your machine. If not, download and install them from the below link.

https://dev.mysql.com/downloads/windows/installer/8.0.html

Open the MySQL Workbench and create a blank database/schema for our WordPress Application to run. The tables will be auto-generated by WordPress as soon as the application launches for the first time. Make sure you remember the username, password, database name, and the port at which MySQL is running. You need these details when we start configuring WordPress with ASP.NET Core.

create a new database

Step 5: Let’s add the above database connection details in the appsettings.json file as follows:-

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    }
  },
  "AllowedHosts": "*",

  "WordPress": {
    "dbhost": "localhost",
    "dbpassword": "abc123",
    "dbuser": "root",
    "dbname": "wordpressdb"
  }
}

Next, open up Startup.cs -> ConfigureServices method and add services.AddWordPress(options => { });

public void ConfigureServices(IServiceCollection services)
        {
            services.AddRazorPages();
            services.AddWordPress(options => { });
        }

Now go to Configure method and add app.UseWordPress(); as follows:-

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
       {
           if (env.IsDevelopment())
           {
               app.UseDeveloperExceptionPage();
           }
           else
           {
               app.UseExceptionHandler("/Error");
               // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
               app.UseHsts();
           }

           app.UseHttpsRedirection();
           app.UseStaticFiles();
           app.UseWordPress();
           app.UseRouting();

           app.UseAuthorization();

           app.UseEndpoints(endpoints =>
           {
               endpoints.MapRazorPages();
           });
       }

And here you go, you have an instance of WordPress on ASP.NET Core.

wordpress on asp.net core | wordpress installation wizard

Select your preferred language and click on continue. Next, you need to enter your site details and credentials so that you can use it to log in to the WordPress dashboard.

welcome page

It will take some time to set up WordPress in the back-end and creating the required tables in the MySQL database we have created. You will get a success page after completing the process.

success page

After this, you will see the login page and enter the credentials which you have set previously.

login page

That’s it. Now you will enter the dashboard of your WordPress site on ASP.Net Core application.

wordpress on asp.net core | wordpress site dashboard

and Visit Site.

wordpress on asp.net core application

Download Source Code

Benefits of Running WordPress on ASP.NET Core

  • Performance: The 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.
  • Sourceless Distribution: After the compilation, most of the source files are not needed. Peachpie compiles the entire source to DLLs which makes lives much easier.
  • C# Extensibility: You can implement plugins in a separate C# project and/or PHP plugins may use .NET libraries.
  • Secure: Peachpie allows the compiled WordPress clone to run in a .NET JIT’ted, secure and manageable environment, updated through windows update.

Conclusion

I hope you liked this article on ASP.NET Core on WordPress. I would like to have feedback from my blog readers. Your valuable feedback, question, or comments about this article are always welcome.

Category icon.NET Core,  ASP.NET Tag iconwordpress asp.net core,  Wordpress on ASP.NET Core,  wordpress with asp.net core

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Recent Posts

  • Google Maps Draw Polygon Get Coordinates
  • Check if point inside polygon Google Maps JavaScript
  • How to Create a Calendar Control in ASP.NET
  • Interview Etiquette Before, During and After
  • How to Attend Telephonic Interview Tips

Products

  • Online Shopping ASP.NET Project Source Code Online Shopping ASP.NET Project Source Code
    Rated 5.00 out of 5
    $69.00 $39.00
  • responsive-aspnet-mvc-grid-view ASP.NET MVC full Ajaxify and Bootstrap Grid with CRUD Operation
    Rated 4.67 out of 5
    $21.00 $9.00
  • eCommerce Website Source Code in ASP.NET eCommerce Website Source Code in ASP.NET $99.00
  • Hospital Management System Project ASP.Net Source Code
    Rated 5.00 out of 5
    $99.00
  • Whatsapp Bulk Message Sender Source Code WhatsApp Bulk Message Sender Source Code
    Rated 5.00 out of 5
    $69.00

Footer

DotNetTec

A platform for Software Developers and Architects. Learn new skills and apply them in real-life to build an end to end applications.

Sitemap

  • About
  • Blog
  • Shop
  • Contact
  • Privacy Policy

Expertise

  • Web Development
  • Custom Software Development
  • Web API Development
  • Google Maps APIs
  • Facebook
  • Instagram
  • Pinterest
  • Twitter
  • YouTube

Copyright © 2021 DotNetTec. All rights reserved. Return to top