Question

Install Discourse on a droplet with WordPress served by Apache ?

Posted January 28, 2020 1.8k views
NginxApacheCMSUbuntu 18.04

Hello everyone ! :)
I’m really puzzled by a little problem with my personnal website project : I can’t manage to install any Discourse instance on my droplet, with already WordPress and Apache installed.

I know there are already many threads for this. But they don’t exactly fit to my case : Install Discourse in a Docker container, with Apache used to serve WordPress.

For example, this thread is for installing WordPress on a droplet with Discourse. But I need the reverse : https://www.digitalocean.com/community/questions/need-help-with-installing-discourse-and-wordpress

And this one is for installing Discourse on a droplet / server with WordPress served by Nginx. But my WordPress is served by Apache : https://blog.khophi.co/install-run-discourse-behind-nginx-right-way-first-time/

So it doesn’t fit to my situation.

The manipulations are probably 95% similar between Apache and Nginx, but I don’t want to do any mistake.

I could use a separate droplet for Discourse, but I need to use Discourse’s API to share its database with a custom social network app, created by the main programmer of my project. And it also uses a JSON add-on installed on the WordPress instance.

So it will be way simplier if I can install all that stuff on the same droplet. Without any conflicts.

  • Apache is listening to port 80.

  • My droplet uses Ubuntu 18.04.

  • Discourse will be installed on a subdomain : forum.example.com. DNS records are already done.

Any tips or suggestions are welcome ! :)

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
1 answer

Hello,

This is a really good question.

I’ve tried to replicate your setup and create a step by step guide on how to set Discourse on a Droplet with Apache and an existing Wordpress installation. To be honest it took me a while to figure the whole process out.

Here are the steps that you would need to take:

Prerequisites

  • To be on the safe side make sure to backup your Droplet, so that in case anything goes wrong, you could revert back to a working version

  • SSH to your Droplet

  • Apache installed, you can follow the steps on how to do that here:

https://www.digitalocean.com/community/tutorials/how-to-install-the-apache-web-server-on-ubuntu-18-04

Step 1 - Install Docker

To install Docker please follow the steps here:

https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-18-04

Step 2 - Download Discourse

First, create a directory where you would store your Discourse files:

mkdir /var/discourse

After that clone the official Discourse Docker Image into /var/discourse.

git clone https://github.com/discourse/discourse_docker.git /var/discourse

Step 3 - Configure Discourse to listen on port 8080

We will use the standalone.yml template it includes all of the necessary services like PostgreSQL, Redis and etc.

You copy the sample file with the following command:

cp /var/discourse/samples/standalone.yml /var/discourse/containers/app.yml

After that edit the file with your favorite editor. Open the /var/discourse/containers/app.yml and update and the ports on lines 23 and 24:

## which TCP/IP ports should this container expose?
expose:
  - "8080:80"   # fwd host port 8080   to container port 80 (http)
  - "8443:443"   # fwd host port 8443 to container port 443 (http)

Also if you do not yet have an SSL certificate make sure to comment line 16 out:

  #- "templates/web.ssl.template.yml"

Just add the # symbol in front of the - "templates/web.ssl.template.yml line otherwise Discourse would not start.

Step 4 - Setup Discourse

Then, start Discourse (as this is the first time that you are starting the service it would bootstrap the application with the new changes that you have in your app.yml file):

First cd to the /var/discourse directory:

  • cd /var/discourse`

Then run the following setup command:

./discourse-setup

Note: Make sure to provide valid Mail server settings as otherwise, the setup might fail.

Step 5 - Setup Apache

In your /etc/apache2/sites-available/ create a new file called forum.example.com.conf and add the following Vhost content:

<VirtualHost *:80>
  ServerName forum.example.com
  ServerAlias www.forum.example.com

  <IfModule proxy_module>
    ProxyPreserveHost on
    ProxyPass / http://localhost:8080/
    ProxyPassReverse / http://localhost:8080/
  </IfModule>
</VirtualHost>
  • Enable the Vhost with the following command:
a2ensite forum.example.com
  • Enable Mod Proxy:
a2enmod proxy
a2enmod proxy_http
a2enmod proxy_balancer
a2enmod lbmethod_byrequests
  • Restart Apache:
systemctl restart apache2

And after that, you would be able to access Discourse directly via your domain name.

Hope that this helps!
Regards,
Bobby

by Justin Ellingwood
by Kathleen Juell
The Apache HTTP server is the most widely-used web server in the world. It provides many powerful features including dynamically loadable modules, robust media support, and extensive integration with other popular software. In this guide, we'll explain how to install an Apache web server on your Ubuntu 18.04 server.
  • My problem start from .discourse-setup

    First i am having error with my hostname, is example.com not allowed or is it just forum.example.com?

  • Hi @bobbyiliev.

    I’m attempting to install Discourse on the same server as LAMP to run in parallel with an HTML or WordPress frontpage. Using Ubuntu 18.04 and, of course, Apache.

    There are a few things missing from this tutorial so I filled in the blanks, starting with installing LAMP immediately after doing the initial server setup, which is really just creating a sudo user for SSH.

    Everything else, I followed closely. My frontpage currently works just fine but when visiting my Discourse forum, community.mysite.com, I get the following error:

    Proxy Error
    The proxy server received an invalid response from an upstream server.
    The proxy server could not handle the request
    
    Reason: Error reading from remote server
    

    I’m assuming there is a missing configuration somewhere. Yes, my DNS settings are correct and no, I have not installed Let’s Encrypt SSL.

    I’ve tried getting support on the Discourse forums but that was quite an undertaking that didn’t provide anything worthwhile. They just kept linking to the same two outdated tutorials from several years ago, that are designed with CentOS and Nginx in mind.

    • Hi there @orbitstorm88,

      Ah yes, that is a good point, I’ve added installation Apache to the prerequisites.

      Can you share the output of the following command:

      • sudo docker ps -a

      It sounds like that your Discourse container might not be listening on port 8080.

      Also, do you get to Discourse if you visit yourdomain.com:8080?

      Regards,
      Bobby

      • Thanks for the response, @bobbyiliev.

        CONTAINER ID        IMAGE                 COMMAND             CREATED             STATUS              PORTS                                         NAMES
        d4f6a52ca30e        local_discourse/app   "/sbin/boot"        21 hours ago        Up 5 minutes        0.0.0.0:8080->80/tcp, 0.0.0.0:8443->443/tcp   app
        

        I get an err_connection_refused in my browser whenever visiting community.mydomain.com:8080 or mydomain.com:8080.

        • Hello,

          It looks correct in terms of port mapping.

          Can you share the contents of your Apache virtual host here as well?

          The error that you get when visiting the site directly on port 8080 might indicate that either you have a firewall and you need to open port 8080 or your Discourse service is having some issues indeed.

          I would also recommend checking the logs of your container to see if there are any problems as the container has been running only for the past 5 minutes based on the output that you’ve shared:

          docker logs your_container_id
          

          Let me know how it goes.
          Regards,
          Bobby

          • @bobbyiliev,

            That low uptime was a result of my rebooting the droplet to see if that would alleviate the issue. Logs show the following error:

            nginx: [emerg] cannot load certificate "/shared/ssl/community.mysite.com.cer": PEM_read_bio_X509_AUX() failed (SSL: error:0909006C:PEM routines:get_name:no start line:Expecting: TRUSTED CERTIFICATE)
            

            Odd that Nginx is showing given that I don’t even have it installed.

            Here is mysite.com.conf:

            <VirtualHost *:80>
                ServerAdmin webmaster@localhost
                ServerName mysite.com
                ServerAlias www.mysite.com
                DocumentRoot /var/www/mysite.com
                ErrorLog ${APACHE_LOG_DIR}/error.log
                CustomLog ${APACHE_LOG_DIR}/access.log combined
            </VirtualHost>
            

            … and community.mysite.com.conf:

            <VirtualHost *:80>
              ServerName community.mysite.com
              ServerAlias www.community.mysite.com
            
              <IfModule proxy_module>
                ProxyPreserveHost on
                ProxyPass / http://localhost:8080/
                ProxyPassReverse / http://localhost:8080/
              </IfModule>
            </VirtualHost>
            
          • @bobbyiliev,

            Previous comment was flagged for spam but the information you required is there.

            I snapshooted my droplet then tried a clean slate. Everything went swimmingly, again, but now when navigating to community.mysite.com, it shows this error:

            Service Unavailable
            The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.
            
          • Hi there @orbitstorm88,

            From the error that you’ve shared, to me it looks like that there might not be enough resources on your server like RAM and CPU in order to run Discourse.

            I believe that Discourse needs about ~2GB of RAM and it is recommended to have SWAP as well.

            Would mind confirming how much memory does your Droplet have?

            If it is a $5 Droplet, I would recommend upgrading to a plan with at least 2GB RAM and adding a swap space as instructed here:

            https://www.digitalocean.com/community/tutorials/how-to-add-swap-space-on-ubuntu-18-04

            Regards,
            Bobby

            by Brian Boucheron
            One of the easiest way of guarding against out-of-memory errors in applications is to add some swap space to your server. In this guide, we will cover how to add a swap file to an Ubuntu 18.04 server.
          • @bobbyiliev,

            Discourse creates swap space during installation by default. I checked by resource usage earlier and was well below acceptable thresholds. I’ve gone ahead and upgraded to the $10 droplet just out of curiosity and the result is still the same.

            Is this an Apache limitation? When I shared your guide on the Discourse forums a few days ago, one individual claims that it wouldn’t work.

            I just tried restarting the docker container for Discourse and got the following error:

            Error starting userland proxy: listen tcp 0.0.0.0:80: bind: address already in use
            

            I find it odd that the local IP is straight zeros.

            Also, for what it’s worth, here are the two tutorials they often link to:

            https://meta.discourse.org/t/running-other-websites-on-the-same-machine-as-discourse/17247
            

            and …

            https://meta.discourse.org/t/how-to-set-up-discourse-on-a-server-with-existing-apache-sites/30013
            
          • Hi there,

            Actaully, the 0.0.0.0:80 is quite standard, this means that the service is open for connections from the outside world.

            I tried following the tutorial as described step by step and it all works as expected.

            Here is the temporary subdomain that I’ve used to install the application on:

            http://discourse.bobbyiliev.com/

            It is pointing to the following IP, you can verify this by pinging the domain:

            http://164.90.185.154/

            If you visit the domain you will be able to see the Discourse application and if you visit the IP you will get the Apache default page.

            I will keep the above for ~24 hours and then shut down that test Droplet.

            It is odd that they are saying that this would not work without testing it. It is quite a standard setup with Apache reverse proxy.

            Did you get any feedback on why they think that this would not work?

            Also, have you tried following the two tutorials that they recommended? Do the results look better?

            Can you run the following command and share the output with me:

            • sudo netstat -plant

            Regards,
            Bobby

          • @bobbyiliev, thank you for continuing with this.

            It’s really strange that this is being so problematic. I don’t think I’m missing a step anywhere. I’ll summarize my steps and perhaps there is something I missed? To be clear, my DNS settings have three A records:

            • mysite.com, pointed at my droplet
            • www.mysite.com, pointed at the same droplet
            • community.mysite.com, pointed at the same droplet

            These are the steps I take after rebuilding my droplet using Ubuntu 18.04:

            1. Add and configure new sudo user
            2. Add OpenSSH to firewall, open firewall
            3. Install Apache, add Apache Full to firewall
            4. Confirm Apache is running
            5. Create domain root at /var/www/mysite.com
            6. Create virtual host as mysite.com.conf
            7. ConfigTest comes back ok
            8. Restart Apache
            9. Download Discourse
            10. Copy app.yml sample
            11. Update app.yml for the new ports. Don’t need to comment out the SSL bit because it already is
            12. CD /var/discourse
            13. Run Discourse setup
            14. Create new community.mysite.com.conf virtualhost file
            15. Enable vhost
            16. Enable the mod proxies
            17. Restart Apache

            After that, primary site loads. Discourse does not. Am I missing something in there or doing something out of order?

          • @bobbyiliev,

            Alright, so not to blow up your notifications again but I finally got it working and it’s so silly.

            After downloading the standalone.yml file and then running the Discourse setup, that yml file gets replaced by the installation process. I don’t have an SSL on my site (yet) and the new yml uncomments lines 16 and 17. So, Discourse kept trying to load an SSL-enabled page but couldn’t because it isn’t. Should probably note this issue in your tutorial.

            Also for the tutorial, you should mention that in order to run the Discourse setup, you need to change the directory: cd /var/discourse. I already knew that but noticed it wasn’t in your tutorial.

            At this point I just need to add Let’s Encrypt to Apache and hope it works for Discourse automatically.

            I think in the future — even though it should work just fine — I’ll just create a droplet for each new domain because I’m not certain I’ll be able to get another installation of Discourse on this droplet. It took me a week to get this far. I shudder to image the time it’ll take to install another copy of Discourse on the same machine.

            Thank you so much for your patience and continued effort to help me resolve this. Absolutely phenomenal.

          • Hi there @orbitstorm88,

            No problem at all! Happy to hear that you’ve solved the mystery at the end!

            Let me know how the SSL setup goes!

            I’ve added the cd step as you suggested!

            Indeed I think that it is a good idea to keep the projects separate on different Droplets, that way you minimize the possibility of one single site bringing other websites down as well. That way if one site has a huge spike in the traffic it would only affect the Droplet that it is running on and your other projects would remain up and running on the other Droplets.

            Let me know if anything else pops up!
            Regards,
            Bobby

Submit an Answer