[Solved] How to install Wordpress + Nextcloud same domain?

Hi Nextcloud and thanks for your good work !
Everything was working just fine until yesterday…

…when I decided to install Wordpress on my domain, the same used for Nextcloud. And now when I try to reach Nextcloud, only Wordpress appears.

I tried to change the trusted domains but didn’t work.

Wordpress is on https://mydomain.com
And I would love to have nextcloud on https://mydomain.com/nextcloud

How can I do it ?

Nextcloud 12.0.3.3,
Ubuntu 16.04.3 LTS 64bits,
Apache2 version 2.4.18
PHP 7.1.11-1

The output of your Nextcloud log in Admin > Logging : it seems empty ?
The output of your Apache/nginx/system log in /var/log/____: could’nt find it ?

Yes, first time encountered this error

The config.php :

<?php
$CONFIG = array (
  'instanceid' => 'XXX',
  'passwordsalt' => 'XXX',
  'secret' => 'XXX',
  'trusted_domains' => 
  array (
    0 => 'mydomain.com',

  ),
  'datadirectory' => '/homepages/43/d6XXX4/htdocs/nextcloud/data',
  'overwrite.cli.url' => 'https://mydomain/nextcloud',
  'dbtype' => 'sqlite3',
  'version' => '12.0.3.3',
  'installed' => true,
  'mail_from_address' => 'XXX',
  'mail_smtpmode' => 'php',
  'mail_smtpauthtype' => 'LOGIN',
  'mail_domain' => 'XXX',
  'htaccess.RewriteBase' => '/',
  'maintenance' => false,
  'theme' => '',
  'loglevel' => 2,
);

Most likely it is related to the .htaccess rewrite rules set by Wordpress.
Try setting permalinks in Wordpress to ugly and see if that helps.

It is possible to have nice urls in wordpress and the same time working subdirectories, but it is a bit more difficult to set up via .htaccess

Hi @Krischan and thanks for your answer.

I tried setting permalinks in Wordpress to ugly (like for example https://mydomainname/?p=123) and it directly showed the homepage, keeping in the URL https://mydomain.com/?p=123 and not https://mydomain.com/ as i assume would be logical.

For now I set up permalinks as custom like https://mydomain//%postname%/ and it is showing “that the page cannot be found”.

I tried to educate myself at rewritecond&rules with Uncle Google but everything I tried wasn’t working. Seems I don’t have the knowledge to fix it by myself.

I really need a hand, can anyone go with me in details step by step please ? :slight_smile:

Here is an extract of my .htaccess wordpress file :

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R,L]

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>` 

Here is my .htaccess file from my Nextcloud folder :

<IfModule mod_headers.c>
  <IfModule mod_setenvif.c>
    <IfModule mod_fcgid.c>
       SetEnvIfNoCase ^Authorization$ "(.+)" XAUTHORIZATION=$1
       RequestHeader set XAuthorization %{XAUTHORIZATION}e env=XAUTHORIZATION
    </IfModule>
    <IfModule mod_proxy_fcgi.c>
       SetEnvIfNoCase Authorization "(.+)" HTTP_AUTHORIZATION=$1
    </IfModule>
  </IfModule>

  <IfModule mod_env.c>
    # Add security and privacy related headers
    Header set X-Content-Type-Options "nosniff"
    Header set X-XSS-Protection "1; mode=block"
    Header set X-Robots-Tag "none"
    Header set X-Download-Options "noopen"
    Header set X-Permitted-Cross-Domain-Policies "none"
    SetEnv modHeadersAvailable true
  </IfModule>

  # Add cache control for static resources
  <FilesMatch "\.(css|js|svg|gif)$">
    Header set Cache-Control "max-age=15778463"
  </FilesMatch>
  
  # Let browsers cache WOFF files for a week
  <FilesMatch "\.woff$">
    Header set Cache-Control "max-age=604800"
  </FilesMatch>
</IfModule>
<IfModule mod_php5.c>
  php_value upload_max_filesize 511M
  php_value post_max_size 511M
  php_value memory_limit 512M
  php_value mbstring.func_overload 0
  php_value always_populate_raw_post_data -1
  php_value default_charset 'UTF-8'
  php_value output_buffering 0
  <IfModule mod_env.c>
    SetEnv htaccessWorking true
  </IfModule>
</IfModule>
<IfModule mod_php7.c>
  php_value upload_max_filesize 511M
  php_value post_max_size 511M
  php_value memory_limit 512M
  php_value mbstring.func_overload 0
  php_value default_charset 'UTF-8'
  php_value output_buffering 0
  <IfModule mod_env.c>
    SetEnv htaccessWorking true
  </IfModule>
</IfModule>
<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteCond %{HTTP_USER_AGENT}  DavClnt
  RewriteRule ^$         /remote.php/webdav/          [L,R=302]
  RewriteRule .* - [env=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
  RewriteRule ^\.well-known/host-meta /public.php?service=host-meta [QSA,L]
  RewriteRule ^\.well-known/host-meta\.json /public.php?service=host-meta-json [QSA,L]
  RewriteRule ^\.well-known/carddav /remote.php/dav/ [R=301,L]
  RewriteRule ^\.well-known/caldav /remote.php/dav/ [R=301,L]
  RewriteRule ^remote/(.*) remote.php [QSA,L]
  RewriteRule ^(?:build|tests|config|lib|3rdparty|templates)/.* - [R=404,L]
  RewriteCond %{REQUEST_URI} !^/.well-known/acme-challenge/.*
  RewriteRule ^(?:\.|autotest|occ|issue|indie|db_|console).* - [R=404,L]
</IfModule>
<IfModule mod_mime.c>
  AddType image/svg+xml svg svgz
  AddEncoding gzip svgz
</IfModule>
<IfModule mod_dir.c>
  DirectoryIndex index.php index.html
</IfModule>
AddDefaultCharset utf-8
Options -Indexes
<IfModule pagespeed_module>
  ModPagespeed Off
</IfModule>
#### DO NOT CHANGE ANYTHING ABOVE THIS LINE ####

ErrorDocument 403 /nextcloud/core/templates/403.php
ErrorDocument 404 /nextcloud/core/templates/404.php
<IfModule mod_rewrite.c>
  Options -MultiViews
  RewriteRule ^core/js/oc.js$ index.php [PT,E=PATH_INFO:$1]
  RewriteRule ^core/preview.png$ index.php [PT,E=PATH_INFO:$1]
  RewriteCond %{REQUEST_FILENAME} !\.(css|js|svg|gif|png|html|ttf|woff|ico|jpg|jpeg)$
  RewriteCond %{REQUEST_FILENAME} !core/img/favicon.ico$
  RewriteCond %{REQUEST_FILENAME} !core/img/manifest.json$
  RewriteCond %{REQUEST_FILENAME} !/remote.php
  RewriteCond %{REQUEST_FILENAME} !/public.php
  RewriteCond %{REQUEST_FILENAME} !/cron.php
  RewriteCond %{REQUEST_FILENAME} !/core/ajax/update.php
  RewriteCond %{REQUEST_FILENAME} !/status.php
  RewriteCond %{REQUEST_FILENAME} !/ocs/v1.php
  RewriteCond %{REQUEST_FILENAME} !/ocs/v2.php
  RewriteCond %{REQUEST_FILENAME} !/robots.txt
  RewriteCond %{REQUEST_FILENAME} !/updater/
  RewriteCond %{REQUEST_FILENAME} !/ocs-provider/
  RewriteCond %{REQUEST_URI} !^/.well-known/acme-challenge/.*
  RewriteRule . index.php [PT,E=PATH_INFO:$1]
  RewriteBase /
  <IfModule mod_env.c>
    SetEnv front_controller_active true
    <IfModule mod_dir.c>
      DirectorySlash off
    </IfModule>
  </IfModule>
</IfModule>

And I also have a .htaccess on the main directory, my ftp, my server :

RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

<IfModule mod_headers.c>
Header set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
</IfModule>

If you remove Wordpress, does the problem go away? What about installing Wordpress in domain.com/wordpress, and Nextcloud in domain.com/nextcloud?

what terry_tibbles descibes is (probably) the best and cleanest way. if you install wp for yourdomain.com it rewrites everything directed to yourdomain.com/
you can do stuff with apache-rewrites or directory-aliases but this can (and probably will) lead to trouble later on.
GOOD LUCK!

Yeah, not an .htaccess expert either, but I had Wordpress and Nextcloud running like that with two subdirectories, with an invisible redirection so that wordpress was reachable under www.yourdomain.com.

I have since replaced Wordpress with another CMS, but I don’t think I changed the .htaccess file much:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^\.htaccess$ - [F]
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTP_HOST} ^(www.)?yourdomain.com$
RewriteCond %{REQUEST_URI} !^/wordpressdirectory/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /wordpressdirectory/$1
RewriteCond %{HTTP_HOST} ^(www.)?yourdomain.com$
RewriteRule ^(/)?$ wordpressdirectory/index.php [L]
</IfModule>

It forces https and you can still access the /nextcloud subdirectory (or any other) as long as your CMS does not create a page with that exact same /nextcloud etc. name.

I do however have issues with the pico_cms Nextcloud plugin which I suspect is due to this .htaccess. Somehow the directory names for that app’s webpages get duplicated and I have no idea why. But other than that it seems to work fine with multiple web-services I run on the same server.

Thanks everyone, I did uninstall Wordpress, the problem was gone.
I installed nextcloud at mydomain.com/nextcloud and wordpress at mydomain.com/blog and it works perfectly well.

:sunny: Long live Nextcloud ! :wink:

To have wordpress on the domain (mydomain.com) and nextcloud on a subdomain (nextcloud.mydomain.com) what .htaccess configuration has to be done? And more, is it possible to have a common authentication?

If it is on a subdomain it should work without .htaccess modification.

Nextcloud can use WordPress accounts easily with the user_sql addon.

I have nextcloud installed on my Raspberrypi, how would I get wordpress to install at mypiaddress/wordpress ? When I tried before I could not get to the configuration page to get wordpress going. I would enter the raspberryip/wordpress and it would redirect me to nextcloud.