# Trouble connecting drupal and discourse

**URL:** https://meta.discourse.org/t/trouble-connecting-drupal-and-discourse/34168
**Category:** Support
**Created:** [6 oktober 2015 om 00:14 UTC](https://meta.discourse.org/t/trouble-connecting-drupal-and-discourse/34168 "2015-10-06T00:14:02Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![tbecker](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tbecker/32/116538_2.png) [@tbecker](https://meta.discourse.org/u/tbecker)
#### Post date: [6 oktober 2015 om 00:14 UTC](https://meta.discourse.org/t/trouble-connecting-drupal-and-discourse/34168/1 "2015-10-06T00:14:02Z")

</div>

Setup a hosted discourse instance and trying the Drupal Discourse Module: [Client Challenge](https://www.drupal.org/project/discourse)

Reading the Drupal module’s README says:

- Log into the Discourse instance as an admin and go to the site settings screen /admin/site\_settings  
Set force\_hostname to be the Drupal url and path in Discourse site settings.  
Eg [drupalsite.com/discourse](http://drupalsite.com/discourse) This will give correct links in emails sent by Discourse.
- Your forum should now be available at /discourse

“force\_hostname” doesn’t exist in my Discourse instance. Has this been deprecated?  
Also noticed the Drupal Module was tested with Discourse 1.2.0.beta5 and Discourse is on ver 1.4.  
Has anybody tried this module with newest Discourse? Does it work?

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [6 oktober 2015 om 08:25 UTC](https://meta.discourse.org/t/trouble-connecting-drupal-and-discourse/34168/2 "2015-10-06T08:25:59Z")

</div>

> [@tbecker](#):
>
> Set force\_hostname to be the Drupal url and path in Discourse site settings. Eg [drupalsite.com/discourse](http://drupalsite.com/discourse) This will give correct links in emails sent by Discourse.

That’s very wrong. The referenced setting is restricted to development mode only because of people doing stupid things like that.

> [@tbecker](#):
>
> - Your forum should now be available at /discourse

Sounds like it’s trying to set up subfolder. You can do that with hosted forums, but it’s a bit expensive.

Reading the page, seems like it doesn’t offer much other than SSO? In that case, might as well skip it.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [6 oktober 2015 om 10:13 UTC](https://meta.discourse.org/t/trouble-connecting-drupal-and-discourse/34168/3 "2015-10-06T10:13:37Z")

</div>

If you want our official supported SSO follow this topic

> [@Setup DiscourseConnect - Official Single-Sign-On for Discourse (sso)](https://meta.discourse.org/t/official-single-sign-on-for-discourse/13045):
>
> [DiscourseConnect](https://meta.discourse.org/t/13045?silent=true) is a core Discourse feature that allows you to configure “Single Sign-On (SSO)” to completely outsource all user registration and login from Discourse to another site. Offered to our [pro, business and enterprise hosting customers](https://discourse.org/pricing). information_source (Feb 2021) ‘[Discourse SSO](https://meta.discourse.org/t/13045?silent=true)’ is now ‘[DiscourseConnect](https://meta.discourse.org/t/13045?silent=true)’. If you are running an old version of Discourse, the settings below will be named sso\_... rather than discourse\_connect\_... The Problem Many sites wishing to integrate wit…

---

<div class="post-metadata">

### Author: ![tbecker](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tbecker/32/116538_2.png) [@tbecker](https://meta.discourse.org/u/tbecker)
#### Post date: [6 oktober 2015 om 18:19 UTC](https://meta.discourse.org/t/trouble-connecting-drupal-and-discourse/34168/4 "2015-10-06T18:19:43Z")

</div>

The module is trying to embed Discourse into Drupal, so instead of using Drupal Forums you’re using Discourse. Doesn’t look like the module works though. It’s doing some whacky monkey patch with Ember to get Discourse to run on the Drupal page. Not looking like a robust, quick and easy solution to get Discourse in Drupal.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [6 oktober 2015 om 21:52 UTC](https://meta.discourse.org/t/trouble-connecting-drupal-and-discourse/34168/5 "2015-10-06T21:52:03Z")

</div>

If you want to embed discourse, follow our official supported instructions at

> [@Embed Discourse comments on another website via Javascript](https://meta.discourse.org/t/embedding-discourse-comments-via-javascript/31963):
>
> Discourse has the ability to embed the comments from a topic in a remote site using a Javascript API that creates an IFRAME. For an example of this in action, check out [Coding Horror’s blog](http://blog.codinghorror.com/welcome-to-the-internet-of-compromised-things/#discourse-comments). The blog is run via [Ghost](https://ghost.org/) but the comments are embedded from his [Discourse forum](http://discourse.codinghorror.com/t/welcome-to-the-internet-of-compromised-things/3550). One important thing to note with this setup is that users have to navigate to your forum to post replies. This is intentional, as we feel that the posting interface on a Discourse forum is currently much richer than what we …

---

<div class="post-metadata">

### Author: ![tarek](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tarek/32/124831_2.png) [@tarek](https://meta.discourse.org/u/tarek)
#### Post date: [6 mei 2016 om 03:00 UTC](https://meta.discourse.org/t/trouble-connecting-drupal-and-discourse/34168/6 "2016-05-06T03:00:16Z")

</div>

After spending quite a while getting login integration, I finally have OAuth2 working between Discourse and Drupal. See here:

> [@OAuth2 integration with Drupal](https://meta.discourse.org/t/howto-oauth2-integration-with-drupal/43652):
>
> Special thanks to @dashohoxha for his help!! Continuing the discussion from [OAuth2 Basic Support](https://meta.discourse.org/t/oauth2-basic-support/33879/59): I will use this thread to document my steps and progress in integrating Discourse and Drupal via OAuth2. At present, the status of my implementation is WORKING. Installation on Discourse: For installation on Discourse, do the following: Install [OAuth2 Basic plugin](https://github.com/discourse/discourse-oauth2-basic) as per [this thread](https://meta.discourse.org/t/oauth2-basic-support). See [Install a plugin](https://meta.discourse.org/t/install-a-plugin/19157) for details on how to install a plugin Configure OAuth2 plugin: You should see an…

I hope that saves some time for others!

tarek : )

---

<div class="post-metadata">

### Author: ![Ivan\_Rapekas](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ivan_rapekas/32/248924_2.png) [@Ivan\_Rapekas](https://meta.discourse.org/u/Ivan_Rapekas)
#### Post date: [24 augustus 2017 om 11:45 UTC](https://meta.discourse.org/t/trouble-connecting-drupal-and-discourse/34168/7 "2017-08-24T11:45:16Z")

</div>

Hi,

Let me share our implementation of SSO based on Drupal 7.56 and Discourse 1.9.0.beta7 using [discourse\_sso](https://www.drupal.org/project/discourse_sso) plugin. I have tried the plugin on the subject, even OAuth2 integration but the most interesting were this one. Unfortunately, there is no enough information how to force SSO to run, even Readme does not contain useful information. For that reason, I decided to publish my live configuration.

 ![SSO Drupal Discourse](https://global.discourse-cdn.com/meta/original/3X/5/0/508f0f71e12bac337dce16d59ea55d6597ed266e.png)

The configuration is:

```
Ubuntu 16.04.1 x86_64
Nginx/1.10.3
Docker 17.06.1-ce
Discourse 1.9.0.beta7
Drupal 7.56
Php v7.0.22
Discourse_sso (from github)

```

On test environment, both services, Discourse and Drupal are located on the same server as virtual servers managed by Nginx. Both services are managed by two separate config files (see below). The sources how to install Discourse and Drupal are [here](https://github.com/discourse/discourse/blob/master/docs/INSTALL-cloud.md) and [here](https://www.1and1.com/cloud-community/learn/application/drupal/install-drupal-7-on-ubuntu-1604-with-nginx/).

I have to mention that Discourse is the main service in our case (because Drupal is more flexible to tune), it uses port 80. But as desired by our team, the forum has moved from root (/) folder to /support folder. The guide I used for this is located [here](https://meta.discourse.org/t/subfolder-support-with-docker/30507) but the settings are described below as well.

Next, Drupal website operates on port 8080 on the same server.

```
Forum URL: http://example.com/support
Drupal site URL: http://example.com:8080

```

Config for Drupal _/etc/nginx/sites-enabled/drupal_:

```
server {
        listen 8080 default_server;
        root /var/www/html/drupal;
        server_name example.com;
 
        location / {
                # This line and below allow to use clean links
                try_files $uri /index.php?$query_string;
        }
 
        location @rewrite {
                rewrite ^/(.*)$ /index.php?q=$1;
        }
 
        location ~ ^/sites/.*/files/styles/ {
                try_files $uri @rewrite;
        }
 
        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        }
 
}

```

Enable clean URLs in Drupal: _Configuration - Search and metadata (block) - Clean URLs - Enable clean URLs_

To disable a blank screen on root folder apply redirection definition into Nginx config for Discourse:  
Config for Discourse _/etc/nginx/sites-enabled/discourse_:

```
server {
        listen 80;
        server_name forum.example.com;
 
        location /support {
                proxy_pass http://unix:/var/discourse/shared/standalone/nginx.http.sock:;
                proxy_set_header Host $http_host;
                proxy_http_version 1.1;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Forwarded-Proto $scheme;
        }
 
        # Forward requests from Discourse root to Drupal root 
        location / {
                proxy_pass http://127.0.0.1:8080;
# proxy_redirect off;
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Forwarded-Proto $scheme;
                proxy_read_timeout 30m;
        }
}

```

Some additional settings to Discourse **app.yml** :  
Add a line to templates:

```
   templates:
   - "templates/web.socketed.template.yml" # <-- Added

```

Comment a line answering for the port 80 redirection:

```
expose:
# - "80:80" # http

```

Add to ‘env’ section:  
` DISCOURSE_RELATIVE_URL_ROOT: /support`  
version: 1.9.0.beta7

Modify your ‘ **run** ’ section (completely view):

```
run:
    - exec:
        cd: $home
        cmd:
          - mkdir -p public/support
          - cd public/support && ln -s ../uploads && ln -s ../backups
    - replace:
       global: true
       filename: /etc/nginx/conf.d/discourse.conf
       from: proxy_pass http://discourse;
       to: |
          rewrite ^/(.*)$ /support/$1 break;
          proxy_pass http://discourse;
    - replace:
       filename: /etc/nginx/conf.d/discourse.conf
       from: etag off;
       to: |
          etag off;
          location /support/ {
             rewrite ^/support/?(.*)$ /$1;
          }
    - replace:
         filename: /etc/nginx/conf.d/discourse.conf
         from: $proxy_add_x_forwarded_for
         to: $http_fastly_client_ip
         global: true
    - exec:
         cmd:
           - sed -i '/no-referrer-when-downgrade/a proxy_redirect http:\/\/example.com\/ \/support\/;' /etc/nginx/conf.d/discourse.conf

```

Configure your discourse\_sso plugin, download  
[discourse\_sso.tar.gz](https://global.discourse-cdn.com/meta/original/3X/7/6/766ea15d7895ed4d4e0e801ea503bd593096c1b7.gz) (129.1 KB)

 ![190](https://global.discourse-cdn.com/meta/original/3X/8/6/8649a8613c28d1ee4fbf1b7feff122134abed14c.png)

Fill **Discourse site URL** with your Discourse URL (our case: [http://example.com/support](http://example.com/support)).  
Fill **SSO secret** with your secret token.

Go to your Discourse forum as admin and set the following options:

 ![196](https://global.discourse-cdn.com/meta/original/3X/5/f/5ff3dfd6ff50afd327f1a665fe7d3613d875f27e.png)

**enable sso** - enabled  
**sso url** - \< **your Drupal URL + /discourse/sso** \> (example: [http://example.com:8080/discourse/sso](http://example.com:8080/discourse/sso), this address should not return 404!)  
**sso secret** - fill the same secret token as used above in Drupal.

Open your forum in private browser and click ‘Login’. If above settings were configured properly, you will be redirected to Drupal site. Enter your credentials and next second you will be redirected back to the forum.

p.s. After applying settings you are not allowed to login locally using your credentials. To prevent lost connection to your forum use private browsing and do not close admin settings, use /users/admin-login to login. If something went wrong, follow the instruction how to disable SSO using rails commands:

```
cd /var/discourse
./launcher enter app
rails c
irb > SiteSetting.enable_sso = false
irb > SiteSetting.enable_local_logins = true
irb > exit
exit

```

p.p.s. Disable option ‘ **email editable** ’ in Discourse admin settings to prevent using a single Drupal account to recreate Discourse user if the email was changed by a user.

---

<div class="post-metadata">

### Author: ![Ivan\_Rapekas](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ivan_rapekas/32/248924_2.png) [@Ivan\_Rapekas](https://meta.discourse.org/u/Ivan_Rapekas)
#### Post date: [18 oktober 2017 om 14:18 UTC](https://meta.discourse.org/t/trouble-connecting-drupal-and-discourse/34168/8 "2017-10-18T14:18:19Z")

</div>

Hi, there is another SSO solution for Drupal 7 and Discourse tested on beta13.

1. Download [discourse 7.x-1.5](https://www.drupal.org/project/discourse/releases/7.x-1.5) module.
2. Install module and dependency (querypath)
3. Go to _Configuration - System - Discourse_:  
 ![изображение](https://global.discourse-cdn.com/meta/original/3X/c/c/cccd6c538f3e48e4de2268d6c933bd07987d652b.png)

in my case forum works from folder /forum.

1. Set SSO endpoint ( **/discourse\_sso** ) and secret in Discourse settings:

 ![245](https://global.discourse-cdn.com/meta/original/3X/3/f/3f813e82ef97dbfec7da84c2340eda97aea6da96.png)

You may use both [discourse sso](https://meta.discourse.org/t/13045?silent=true) plugins mentioned above.

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [23 november 2019 om 21:22 UTC](https://meta.discourse.org/t/trouble-connecting-drupal-and-discourse/34168/9 "2019-11-23T21:22:35Z")

</div>



---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [24 november 2019 om 23:23 UTC](https://meta.discourse.org/t/trouble-connecting-drupal-and-discourse/34168/10 "2019-11-24T23:23:41Z")

</div>


