Answers.Body: <p>To get ckeditor 4 working in Drupal 9, you have to look at the http error you get:</p>
  <ul>
  <li>404: means the library cannot be found</li>
  <li>403, 500: means an access / permission problem</li>
  </ul>
  <p>Personally, I had the 404 error first.</p>
  <p>When I tried to browse for an image on the server, the url in the window was:</p>
  <pre><code>libraries/civicrm/packages/kcfinder/browse.php?cms=civicrm&amp;type=images&amp;CKEditor=html_message&amp;CKEditorFuncNum=0&amp;langCode=en
  </code></pre>
  <p>But looking at the files on the server, there was no browse.php file in libraries/civicrm/packages/kcfinder</p>
  <p>However, in my installation I could find it in vendor/civicrm/civicrm-packages/kcfinder</p>
  <p>So I copied the kcfinder directory from vendor to libraries:</p>
  <pre><code>cp -r vendor/civicrm/civicrm-packages/kcfinder web/libraries/civicrm/packages
  </code></pre>
  <p>Now, the browse.php file could be found, but I got an access error.</p>
  <p>I solved this by adding the following lines to the .htaccess file.</p>
  <pre><code>  RewriteCond %{REQUEST_URI} !/libraries/civicrm/packages/kcfinder.*$
    RewriteCond %{REQUEST_URI} !/libraries/civicrm/extern.*$
  </code></pre>
  <p>Add these lines above the line:</p>
  <pre><code>  RewriteRule &quot;^(.+/.*|autoload)\.php($|/)&quot; - [F]
  </code></pre>
  <p>Next issue was that the civicrm configuration file could not be found.
  The installation tries to locate the file civicrm.config.php but it was not available.</p>
  <p>You should copy this file from a Drupal7 installation to the directory:</p>
  <pre><code>  web/libraries/civicrm
  </code></pre>
  <p>This file tries to fill in the variable $settingsFile with the exact location of civicrm.settings.php.</p>
  <p>For some reason, the code could not locate my file. Because I ran out of patience, I replaced:</p>
  <pre><code>  $settingsFile = civicrm_conf_init() . '/civicrm.settings.php';
  </code></pre>
  <p>with the hard coded path of my settings file:</p>
  <pre><code>  $settngsFile = '/var/www/ (...etc...) sites/default/civicrm.settings.php';
  </code></pre>
  <p>I would like to hear from Drupal 9 experts how this can be improved!</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-05-19T22:34:46.153Z
Answers.Text: +1. I confirm that you have to do all these steps if one wants to get kcfinder working. In addition , I also had to edit the the file /web/libraries/civicrm/packages/kcfinder/conf/config.php and set [disabled' => false,]
     under / GENERAL SETTINGS.  I just don't think its secure to allow all these .php files that .htaccess forbids (haven't looked enough about the effect of file upload to that mix)
Answers.UserDisplayName: salah-1
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-02-07T12:30:57.743Z
Answers.LastActivityDate: 2022-02-07T12:30:57.743Z
Answers.UserDisplayName: AlainB
Answers.Body: <p>For two days, i couldn't get kcfinder working. After clicking on &quot;browse server&quot; it tries to load the link below and then gives http 403 forbidden.</p>
  <pre><code>libraries/civicrm/packages/kcfinder/browse.php?cms=civicrm&amp;type=images&amp;CKEditor=crmUiId_1&amp;CKEditorFuncNum=0&amp;langCode=en
  </code></pre>
  <p>Yes, i tried putting code under &quot;composer.json in the extra section&quot;,
  followed by &quot;composer civicrm:publish&quot; as suggested here: <a href="https://lab.civicrm.org/dev/civicrm-asset-plugin/-/issues/4" rel="nofollow noreferrer">https://lab.civicrm.org/dev/civicrm-asset-plugin/-/issues/4</a></p>
  <p>While, it did copy the files to libraries/civicrm/packages/kcfinder, it didn't solve the 403 issue.</p>
  <p>Note: kcfinder isn't maintained (last update 2014 according to links below)</p>
  <p>My solution is TO move to ckeditor5 and its fileManager.</p>
  <p><strong>From the docs</strong></p>
  <blockquote>
  <p>An ongoing challenge with ckeditor4 as implemented with CiviCRM is that the filemanager  (kcfinder)
  is pretty hard to work with and requires some hacks to be able to figure out paths.</p>
  <p>Integrations. The integration that currently looks most promising is
  elFinder This is currently being maintained (as opposed to kcfinder
  which is not).
  See under fileManager
  <a href="https://lab.civicrm.org/extensions/ckeditor5" rel="nofollow noreferrer">https://lab.civicrm.org/extensions/ckeditor5</a></p>
  </blockquote>
  <p>Steps to get ckeditor 5 working:</p>
  <ul>
  <li><p>cd to your ext dir, then.</p>
  </li>
  <li><p>wget -vv <a href="https://lab.civicrm.org/extensions/ckeditor5/-/archive/1.5/ckeditor5-1.5.zip" rel="nofollow noreferrer">https://lab.civicrm.org/extensions/ckeditor5/-/archive/1.5/ckeditor5-1.5.zip</a></p>
  </li>
  <li><p>unzip ckeditor5-1.5.zip</p>
  </li>
  <li><p>chown and chmod to set permissions on the downloaded ckeditor5 extention</p>
  </li>
  <li><p>cd to your [project-root] where you have composer.json, then</p>
  </li>
  <li><p>enable the ckeditor5 extention (cv -vv ext:enable  ckeditor5)</p>
  </li>
  <li><p>setup the new ckeditor5 extention as per &quot;usage section&quot; of : <a href="https://lab.civicrm.org/extensions/ckeditor5" rel="nofollow noreferrer">https://lab.civicrm.org/extensions/ckeditor5</a></p>
  </li>
  <li><p>Then get the elfinder (file upload manager to work. look at Wiki pages!)
  <a href="https://github.com/Studio-42/elFinder" rel="nofollow noreferrer">https://github.com/Studio-42/elFinder</a></p>
  </li>
  </ul>
  <p>more on docs:
  <a href="https://civicrm.org/extensions/ckeditor-5" rel="nofollow noreferrer">https://civicrm.org/extensions/ckeditor-5</a></p>
  <p>If you're using Drupal, you may try this old docs of getting Drupal file manager (IMCE) to work for civicrm.</p>
  <p>**haven't implimented this myself.</p>
  <p><a href="https://civicrm.org/it/blog/kurund/enable-image-uploads-and-server-browsing-for-ckeditor" rel="nofollow noreferrer">https://civicrm.org/it/blog/kurund/enable-image-uploads-and-server-browsing-for-ckeditor</a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-02-04T02:02:07.223Z
Answers.Text: nice documentation
Answers.UserDisplayName: petednz - fuzion
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-02-03T21:00:28.460Z
Answers.LastActivityDate: 2022-05-20T21:42:20.970Z
Answers.LastEditDate: 2022-05-20T21:42:20.970Z
Answers.UserDisplayName: salah-1
Answers.Body: <p>I had exactly the same issue and solved the problem with the new <a href="https://civicrm.org/extensions/summernote" rel="nofollow noreferrer">Summernote extension</a>.</p>
  <p>We needed for various reasons to have access to the underlying code (the old 'Source' toggle to see the underlying HTML) and the current version of CKEditor5 available via the <a href="https://civicrm.org/extensions/ckeditor-5" rel="nofollow noreferrer">CKEditor5 extension</a> did not support it.  There was discussion about merging the newer CKEditor5 code in, which does now have a source editor, but as of writing this it was not yet there.</p>
  <p>Installation of Summernote is via the command line, but is very straight forward:</p>
  <ol>
  <li><p>Go to your current extensions directory</p>
  </li>
  <li><p>Download the url defined in the download link.  For me this was:
  <code>wget -vv https://lab.civicrm.org/extensions/summernote/-/archive/1.2.2/summernote-1.2.2.zip</code></p>
  </li>
  <li><p>unzip summernote-1.2.2.zip</p>
  </li>
  <li><p>enable the extension either through the UI or just run</p>
  <p><code>cv en summernote</code>  if your setup requires you to run this as a particular acount use the <code>--user=my_user</code> option</p>
  </li>
  <li><p>Go to Administer -&gt; Customise Data and Screens -&gt; Display Preferences and select Summernote as your WYSIWYG editor:</p>
  </li>
  </ol>
  <p><a href="https://i.sstatic.net/QQeK0.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/QQeK0.png" alt="WYSIWYG Editor Selection" /></a></p>
  <ol start="6">
  <li>Check it works as exepected and then clean up by deleting the downloaded Zip file</li>
  </ol>
  <p>That's about it - there are some more options available to look at, but we are using successfully straight out of the box with the defaults.  This is where to find the other settings in case you need them.</p>
  <p>Administer -&gt; Customise Data and Screens -&gt; Summernote</p>
  <p>So now we have a source editor and the elFinder file browser (this replaces kcfinder) working perfectly under Drupal 10 and CiviCRM 5.66.2 (as of writing).  Hope this helps as I suspect many will run into this when upgrading to the latest Drupal.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-11-08T15:43:04.460Z
Answers.LastActivityDate: 2023-11-08T15:53:44.537Z
Answers.LastEditDate: 2023-11-08T15:53:44.537Z
Answers.UserDisplayName: ChumKui
Body: <p>I migrated a D7 site + civi to Drupal 9.</p>
  <p>Everything works fine except in the <strong>CKEditor</strong> when I click on &quot;browse server&quot;: I get the error <strong>403 Forbidden</strong>. (the URL is MYSITE/libraries/civicrm/packages/kcfinder/browse.php?cms=civicrm&amp;type=images&amp;CKEditor=html_message&amp;CKEditorFuncNum=0&amp;langCode=en)</p>
  <p>I upgraded today to 5.40.2, but I get the same error.</p>
  <p>I tried CKEditor 5 (<a href="https://civicrm.org/extensions/ckeditor-5" rel="nofollow noreferrer">https://civicrm.org/extensions/ckeditor-5</a>), but then I get the error:  Invalid backend response. Error occurred on the server side. HTTP error 500.</p>
  <p>Does anybody know what the issue could be? htaccess? Folder permissions?</p>
  <p>How can I further debug this?</p>
  <p>Thanks!</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-08-19T22:21:57.197Z
Comments.Text: For the error 500, can you try this patch: https://github.com/civicrm/civicrm-packages/pull/328
Comments.UserDisplayName: Demerit
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-08-24T20:13:17.213Z
Comments.Text: @Demerit Thanks for the suggestion. I replaced getUsername() with getAccountName(). I also had to create some missing folders: sites/default/files/civicrm/persist/contribute/images + .trash + .trash/.tmb
  
  Now I can browse the server, but when I insert an image a placeholder is shown and not the image itself. The url of the image is https://sites/default/files/civicrm/persist/contribute/images/logo.png.
  
  How can https://sites be replaced by the real url of the site?
Comments.UserDisplayName: AlainB
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-09-27T09:52:47.207Z
Comments.Text: @Demerit : I could debug this further. 
  I could get rid of the 403 error by adding this to the .htaccess file:
  
  RewriteCond %{REQUEST_URI} !/libraries/civicrm/packages/kcfinder/[a-z_]+\.php$
  RewriteCond %{REQUEST_URI} !/libraries/civicrm/packages/kcfinder/.*/[a-z_]+\.php$
  
  (I guess this could be written in 1 line)
Comments.UserDisplayName: AlainB
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-09-27T10:01:10.347Z
Comments.Text: Then next thing I noticed is that libraries/civicrm/packages/kcfinder/integration/civicrm.php tries to bootstrap civicrm by searching for the file civicrm.config.php in the directory libraries/civicrm
  
  But this file did not exist in my Drupal9 installation. So I copied one from another project into the libraries/civicrm directory.
  
  In that file, I needed to replace the right hand side of $settingsFile = civicrm_conf_init() . '/civicrm.settings.php'; with the absolute path of my civi settings file in order to make it work.
  
  A terrible hack, but now ckeditor4 works in my D9 installation.
Comments.UserDisplayName: AlainB
Tags: <ckeditor><drupal-9>
Title: ckeditor + Drupal9 gives 403 Forbidden when browsing server
ThreadText: # ckeditor + Drupal9 gives 403 Forbidden when browsing server
  
  (Asked by: username_0 on 2021-08-19)
  
  I migrated a D7 site + civi to Drupal 9.
  
  Everything works fine except in the **CKEditor** when I click on "browse server": I get the error **403 Forbidden**. (the URL is MYSITE/libraries/civicrm/packages/kcfinder/browse.php?cms=civicrm&type=images&CKEditor=html\_message&CKEditorFuncNum=0&langCode=en)
  
  I upgraded today to 5.40.2, but I get the same error.
  
  I tried CKEditor 5 (<https://civicrm.org/extensions/ckeditor-5>), but then I get the error: Invalid backend response. Error occurred on the server side. HTTP error 500.
  
  Does anybody know what the issue could be? htaccess? Folder permissions?
  
  How can I further debug this?
  
  Thanks!
  
  **Tags:** ckeditor, drupal-9
  
  > **Comments:**
  > **username_1**: For the error 500, can you try this patch: https://github.com/civicrm/civicrm-packages/pull/328  
  > **username_0**: @username_1 Thanks for the suggestion. I replaced getUsername() with getAccountName(). I also had to create some missing folders: sites/default/files/civicrm/persist/contribute/images + .trash + .trash/.tmb  Now I can browse the server, but when I insert an image a placeholder is shown and not the image itself. The url of the image is https://sites/default/files/civicrm/persist/contribute/images/logo.png.  How can https://sites be replaced by the real url of the site?  
  > **username_0**: @username_1 : I could debug this further.  I could get rid of the 403 error by adding this to the .htaccess file:  RewriteCond %{REQUEST_URI} !/libraries/civicrm/packages/kcfinder/[a-z_]+\.php$ RewriteCond %{REQUEST_URI} !/libraries/civicrm/packages/kcfinder/.*/[a-z_]+\.php$  (I guess this could be written in 1 line)  
  > **username_0**: Then next thing I noticed is that libraries/civicrm/packages/kcfinder/integration/civicrm.php tries to bootstrap civicrm by searching for the file civicrm.config.php in the directory libraries/civicrm  But this file did not exist in my Drupal9 installation. So I copied one from another project into the libraries/civicrm directory.  In that file, I needed to replace the right hand side of $settingsFile = civicrm_conf_init() . '/civicrm.settings.php'; with the absolute path of my civi settings file in order to make it work.  A terrible hack, but now ckeditor4 works in my D9 installation.  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_0 on 2022-02-07. Score: 2
  
  To get ckeditor 4 working in Drupal 9, you have to look at the http error you get:
  
  404: means the library cannot be found
  403, 500: means an access / permission problem
  
  Personally, I had the 404 error first.
  When I tried to browse for an image on the server, the url in the window was:
  libraries/civicrm/packages/kcfinder/browse.php?cms=civicrm&type=images&CKEditor=html_message&CKEditorFuncNum=0&langCode=en
  
  But looking at the files on the server, there was no browse.php file in libraries/civicrm/packages/kcfinder
  However, in my installation I could find it in vendor/civicrm/civicrm-packages/kcfinder
  So I copied the kcfinder directory from vendor to libraries:
  cp -r vendor/civicrm/civicrm-packages/kcfinder web/libraries/civicrm/packages
  
  Now, the browse.php file could be found, but I got an access error.
  I solved this by adding the following lines to the .htaccess file.
    RewriteCond %{REQUEST_URI} !/libraries/civicrm/packages/kcfinder.*$
    RewriteCond %{REQUEST_URI} !/libraries/civicrm/extern.*$
  
  Add these lines above the line:
    RewriteRule "^(.+/.*|autoload)\.php($|/)" - [F]
  
  Next issue was that the civicrm configuration file could not be found.
  The installation tries to locate the file civicrm.config.php but it was not available.
  You should copy this file from a Drupal7 installation to the directory:
    web/libraries/civicrm
  
  This file tries to fill in the variable $settingsFile with the exact location of civicrm.settings.php.
  For some reason, the code could not locate my file. Because I ran out of patience, I replaced:
    $settingsFile = civicrm_conf_init() . '/civicrm.settings.php';
  
  with the hard coded path of my settings file:
    $settngsFile = '/var/www/ (...etc...) sites/default/civicrm.settings.php';
  
  I would like to hear from Drupal 9 experts how this can be improved!
  
  > **Comments:**
  > **username_2**: +1. I confirm that you have to do all these steps if one wants to get kcfinder working. In addition , I also had to edit the the file /web/libraries/civicrm/packages/kcfinder/conf/config.php and set [disabled' => false,]    under / GENERAL SETTINGS.  I just don't think its secure to allow all these .php files that .htaccess forbids (haven't looked enough about the effect of file upload to that mix)  
  
  ---
  
  ### Answer by username_2 on 2022-02-03. Score: 2
  
  For two days, i couldn't get kcfinder working. After clicking on "browse server" it tries to load the link below and then gives http 403 forbidden.
  libraries/civicrm/packages/kcfinder/browse.php?cms=civicrm&type=images&CKEditor=crmUiId_1&CKEditorFuncNum=0&langCode=en
  
  Yes, i tried putting code under "composer.json in the extra section",
  followed by "composer civicrm:publish" as suggested here: https://lab.civicrm.org/dev/civicrm-asset-plugin/-/issues/4
  While, it did copy the files to libraries/civicrm/packages/kcfinder, it didn't solve the 403 issue.
  Note: kcfinder isn't maintained (last update 2014 according to links below)
  My solution is TO move to ckeditor5 and its fileManager.
  From the docs
  
  An ongoing challenge with ckeditor4 as implemented with CiviCRM is that the filemanager  (kcfinder)
  is pretty hard to work with and requires some hacks to be able to figure out paths.
  Integrations. The integration that currently looks most promising is
  elFinder This is currently being maintained (as opposed to kcfinder
  which is not).
  See under fileManager
  https://lab.civicrm.org/extensions/ckeditor5
  
  Steps to get ckeditor 5 working:
  
  cd to your ext dir, then.
  
  wget -vv https://lab.civicrm.org/extensions/ckeditor5/-/archive/1.5/ckeditor5-1.5.zip
  
  unzip ckeditor5-1.5.zip
  
  chown and chmod to set permissions on the downloaded ckeditor5 extention
  
  cd to your [project-root] where you have composer.json, then
  
  enable the ckeditor5 extention (cv -vv ext:enable  ckeditor5)
  
  setup the new ckeditor5 extention as per "usage section" of : https://lab.civicrm.org/extensions/ckeditor5
  
  Then get the elfinder (file upload manager to work. look at Wiki pages!)
  https://github.com/Studio-42/elFinder
  
  
  more on docs:
  https://civicrm.org/extensions/ckeditor-5
  If you're using Drupal, you may try this old docs of getting Drupal file manager (IMCE) to work for civicrm.
  **haven't implimented this myself.
  https://civicrm.org/it/blog/kurund/enable-image-uploads-and-server-browsing-for-ckeditor
  
  > **Comments:**
  > **username_3**: nice documentation  
  
  ---
  
  ### Answer by username_4 on 2023-11-08. Score: 2
  
  I had exactly the same issue and solved the problem with the new [Summernote extension](https://civicrm.org/extensions/summernote).
  
  We needed for various reasons to have access to the underlying code (the old 'Source' toggle to see the underlying HTML) and the current version of CKEditor5 available via the [CKEditor5 extension](https://civicrm.org/extensions/ckeditor-5) did not support it. There was discussion about merging the newer CKEditor5 code in, which does now have a source editor, but as of writing this it was not yet there.
  
  Installation of Summernote is via the command line, but is very straight forward:
  
  1. Go to your current extensions directory
  2. Download the url defined in the download link. For me this was:
     `wget -vv https://lab.civicrm.org/extensions/summernote/-/archive/1.2.2/summernote-1.2.2.zip`
  3. unzip summernote-1.2.2.zip
  4. enable the extension either through the UI or just run
  
     `cv en summernote` if your setup requires you to run this as a particular acount use the `--user=my_user` option
  5. Go to Administer -> Customise Data and Screens -> Display Preferences and select Summernote as your WYSIWYG editor:
  
  [![WYSIWYG Editor Selection](https://i.sstatic.net/QQeK0.png)](https://i.sstatic.net/QQeK0.png)
  
  6. Check it works as exepected and then clean up by deleting the downloaded Zip file
  
  That's about it - there are some more options available to look at, but we are using successfully straight out of the box with the defaults. This is where to find the other settings in case you need them.
  
  Administer -> Customise Data and Screens -> Summernote
  
  So now we have a source editor and the elFinder file browser (this replaces kcfinder) working perfectly under Drupal 10 and CiviCRM 5.66.2 (as of writing). Hope this helps as I suspect many will run into this when upgrading to the latest Drupal.
  
  
  ---
  
  