1

I bought a VPS for my new project running apache.
On it I have 2 websites on the same domain.
The first one is Ruby on Rails /var/www/html
The second one is Wordpress /var/www/blog

I want Wordpress to act like a subdirectory of ruby ( /blog).
Ruby on Rails website works, but if i go to /blog it just says that the page im looking is not available(with RoR 404 template)

Conf for RoR:

<VirtualHost *:443>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html/public
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
        SSLEngine on
        SSLCertificateFile /etc/apache2/certificate/apache-certificate.crt
        SSLCertificateKeyFile /etc/apache2/certificate/apache.key
  
</VirtualHost>

Conf for Wordpress:

<VirtualHost *:443>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/blog
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
        SSLEngine on
        SSLCertificateFile /etc/apache2/certificate/apache-certificate.crt
        SSLCertificateKeyFile /etc/apache2/certificate/apache.key
        Alias /blog /var/www/blog
</VirtualHost>

Maybe the solution is a htacces file in /var/www. Can you pleasep point me? Thank you !

MrWhite
  • 12,647
  • 4
  • 29
  • 41
Adelle
  • 13
  • 3

1 Answers1

0

On it I have 2 websites on the same domain.

Well, you actually have 1 website (1 domain). It's just that you have WordPress in a subdirectory of that 1 website. Consequently, you should only have 1 <VirtualHost> container, not 2 - which is where you would seem to be going wrong here.

The second <VirtualHost> is not being used and should be removed.

You need to move the Alias /blog /var/www/blog directive into the first <VirtualHost> container and allow access to this directory by including the following inside the vHost container:

# WordPress
<Directory /var/www/blog>
    # Permit access to this area
    Require all granted

    # Allow per-directory overrides if want to use WP htaccess file
    AllowOverride All
</Directory>

I assume you must already have something similar for /var/www/html/public?

You should really include a ServerName directive inside this vHost container, otherwise, this is just acting as the "default" by being defined first. For example:

# Declare the hostname that this vHost defines
ServerName example.com

And then define a "default" vHost container before this that catches non-canonical requests.

MrWhite
  • 12,647
  • 4
  • 29
  • 41
  • This is my defaultconf: – Adelle Jun 02 '21 at 00:48
  • This is my defaultconf: ServerName fdcb.site Alias /blog /var/www/blog ServerAdmin webmaster@localhost DocumentRoot /var/www/html/public SSLEngine on SSLCertificateFile /etc/apache2/certificate/apache-certificate.crt SSLCertificateKeyFile /etc/apache2/certificate/apache.key # WordPress # Permit access to this area Require all granted # Allow per-directory overrides if want to use WP htaccess file AllowOverride All – Adelle Jun 02 '21 at 00:54
  • i created a file https://fdcb.site/blog/a.php and it is accesible, but index.php is not. i have disabled htaccess file, tried some things inside it, but again, i dont have the skills. have to say i tried many methods just to bypass server settings. tried to make it run in public, installed wordpress from terminal. came here after many hours of failing. Thank you for your help – Adelle Jun 02 '21 at 01:03
  • @Adelle "i created a file fdcb.site/blog/a.php and it is accessible" - and `a.php` is physically located at `/var/www/blog/a.php`? In that case, this would seem to have answered your question. (In which case you should mark it as "accepted" - tick/checkmark on the left below the voting arrows. Once you have 15+ rep then you can also upvote answers you find useful. Thanks, much appreciated. :) – MrWhite Jun 02 '21 at 01:24
  • @Adelle "but index.php is not" - presumably you mean when accessing the `/blog/` subdirectory? This is a different problem. For `index.php` to be served when requesting a directory, you need to set `DirectoryIndex index.php` in the appropriate `` container. – MrWhite Jun 02 '21 at 01:27
  • even if i type https://fdcb.site/blog/index.php it does not work . I have added DirectoryIndex index.php to default conf inside Directory /var/www/blog and rr but nothing. – Adelle Jun 02 '21 at 01:40
  • What do you mean by "does not work" exactly? If `/blog/a.php` is accessible then so should `/blog/index.php` if you are putting the files in the same directory? – MrWhite Jun 02 '21 at 01:43
  • inside /blog/ directory i have a wordpress instalation. Yes, the file is there. The filepermision is 755 . The only time i got it to work was when the blog was configured by me to work in http, with different virtualhost. – Adelle Jun 02 '21 at 01:47