Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Running WordPress on ASP.NET Core with Peachpie

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 frontend to an existing ASP.NET Core application step by step.

  • Also, read CRUD Operation with Razor Pages in ASP.Net Core 3.1

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

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

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

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.

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

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.

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.

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.

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.

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

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

and Visit Site.

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.

The post Running WordPress on ASP.NET Core with Peachpie appeared first on DotNetTec.



This post first appeared on Asp Dot Net Tricks And Tips, Dot Net Coding Tips, Google Maps API Developer, please read the originial post: here

Share the post

Running WordPress on ASP.NET Core with Peachpie

×

Subscribe to Asp Dot Net Tricks And Tips, Dot Net Coding Tips, Google Maps Api Developer

Get updates delivered right to your inbox!

Thank you for your subscription

×