Articles in this section
Category / Section

Embed .NET Core Application with WordPress on Ubuntu Using Apache

Published:

This section explains how to install and embed .NET Core Application with WordPress on Ubuntu using the Apache Server.

  1. Refer to this help link to setup and configure WordPress-one-click-install in digital ocean.

  2. Refer to this link to install .NET SDK and .NET runtime.

  3. Move the given .NET Core application to the following location on your Ubuntu machine and unzip it.
    Location - /var/www/html

  4. Now, create a service for the .NET core application in the following location.
    Service file location - /etc/systemd/system

  5. Create a file name with the .service extension, copy-paste the following code sample, and modify the application path.
    Examplenewapp.service

    [Unit]
    Description=newapp
    [Service]
    WorkingDirectory=/var/www/html/<Embed-folder name>
    ExecStart=/usr/share/dotnet/dotnet /var/www/html/<Embed-folder name>/SampleCoreApp.dll --urls=http://localhost:5000
    Restart=always
    #Restart service after 10 seconds if the dotnet service crashes:
    RestartSec=10
    KillSignal=SIGINT
    SyslogIdentifier=newapp
    User=root
    Environment=ASPNETCORE_ENVIRONMENT=Production
    Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false
    [Install]
    WantedBy=multi-user.target
    
    

    embed-service.png

  6. Save the file and run the following commands to enable and start the service.

    sudo systemctl enable <service file name>
    sudo systemclt start <service file name>
    sudo systemctl status <service file name>
    

    Example- sudo systemctl enable newapp.service

  7. Afterwards, create an Apache2 configuration for hosting our application. Therefore, navigate to the directory /etc/apache2/sites-available and create a file with a .conf extension as shown follows.
    For Examplesample-app.conf

  8. Create your virtual host as the following inside the created .conf file: Copy-paste the code sample and fill in the required values.

    <VirtualHost *:*>
    RequestHeader set "X-Forwarded-Proto" expr=%{REQUEST_SCHEME}
    </VirtualHost>
    
    <VirtualHost *:80>
        DocumentRoot "/var/www/html/"
        ServerName <your-domain-name>
        ErrorLog ${APACHE_LOG_DIR}helloapp-error.log
        CustomLog ${APACHE_LOG_DIR}helloapp-access.log common
    RewriteEngine on
    RewriteCond %{SERVER_NAME} =<your-domain-name>
    RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
    </VirtualHost>
    
    <VirtualHost *:80>
        ProxyPreserveHost On
        ProxyPass / http://127.0.0.1:5000/
        ProxyPassReverse / http://127.0.0.1:5000/
        ServerName <your-sub-domain-name>
        ErrorLog ${APACHE_LOG_DIR}helloapp-error.log
        CustomLog ${APACHE_LOG_DIR}helloapp-access.log common
    RewriteEngine on
    RewriteCond %{SERVER_NAME} =<your-sub-domain-name>
    RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
    </VirtualHost>
    

    apache-conf.png

  9. After creating the file, enable the site using the following command.

    a2ensite <conf file name>
    
  10. Then, restart the Apache2 server and access the server name in a web browser.

  11. For configuring SSL for the site, create a .conf file in the following location.
    /etc/apache2/sites-available

  12. Then, place your SSL cert and key files in /etc/ssl.

  13. Now, create an SSL conf file as follows.
    Example - Sample-app-ssl.conf

    <VirtualHost *:443>
        ProxyPreserveHost On
        ProxyPass / http://127.0.0.1:5000/
        ProxyPassReverse / http://127.0.0.1:5000/
        ServerName <your-sub-domain-name>
        ErrorLog ${APACHE_LOG_DIR}helloapp-error.log
        CustomLog ${APACHE_LOG_DIR}helloapp-access.log common
    
    SSLCertificateFile /etc/ssl/<Crt-file-name>
    SSLCertificateKeyFile /etc/ssl/<Key-file-name>
    </VirtualHost>
    
    <VirtualHost *:443>
       ServerName <your-domain-name>
       DocumentRoot "/var/www/html"
    
       SSLEngine on
       SSLCertificateFile /etc/ssl/<Crt-file-name>
       SSLCertificateKeyFile /etc/ssl/<Key-file-name>
    </VirtualHost>
    

    apache-conf-ssl.png

  14. After creating the file, enable the site through the following command.

    a2ensite <conf file name>
    
  15. Now, restart the Apache2 server using the following command and refresh the site. The site will now be redirected to HTTPS.

    sudo systemctl restart apache2.services
    
Was this article useful?
Like
Dislike
Help us improve this page
Please provide feedback or comments
SS
Written by Sivanesan Saravanan
Updated
Comments (0)
Please  to leave a comment
Access denied
Access denied