Installing different PHP app on same domain


#1

I’ve just installed Ghost 1.0 and updated to the latest 2.0; clean install so far and all is working well.
I was using WordPress before, but I want to switch. I’d like to be able to temporarily upload my old WordPress installation to a subdirectory like domain.com/myoldsite/ and have it run from there while I work on transposing the design and content.

The question is, how? I’ve created the subdirectory in /ghost/system/nginx-root/oldsite (as that nginx root is where the domain resolves from) but I think I’m being naive. I believe I have to configure the nginx conf in such a way that the /oldsite/ route is handled by PHP rather then Ghost (it now just shows a 404 page). But how? What? Where?

I’m pretty confident in LEMP server setups, but I’m not sure how Ghost’s installation fits into here.


#2

You need to configure your nginx config (which is going to be located in /etc/nginx/sites-enabled/domain-com.conf (or something similar)) to proxy requests to /old to WordPress. Here are some useful snippets from the WordPress docs:

location / {
                # This is cool because no php is touched for static content.
                # include the "?$args" part so non-default permalinks doesn't break when using query string
                try_files $uri $uri/ /index.php?$args;
        }

        location ~ \.php$ {
                #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
                include fastcgi.conf;
                fastcgi_intercept_errors on;
                fastcgi_pass php;
                fastcgi_buffers 16 16k;
                fastcgi_buffer_size 32k;
        }

#3

Thanks for the quick reply :slight_smile:
I figured it would be something like you said, but whatever I try it doesn’t seem to take; even if I purposely break the mapping it still shows the 404 (and yes I do restart Nginx after each change).
This is what I have now for location blocks in my server block;

location / {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Host $http_host;
    proxy_pass http://127.0.0.1:2368;

}

location ~ /.well-known {
    allow all;
}

   location /oldsite/ {
    try_files $uri $uri/ index.php?$args;
   }

   location ~ \.php$ {
    try_files $uri =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
   }

So I’ve (also) tried the /index.php?$args with and without forward slash; no cigar…
Edit: Also; I copied these blocks from other WordPress-configurations I have running on the same server without trouble.


#4
  • Which 404 is it? Ghost or Nginx? Based on your config I think it would be Nginx
  • Can you confirm that /oldsite exists in your webroot?

#5

It’s a Ghost 404 (that’s so strange to me), and yes the folder exists;
/var/www/ghost/system/nginx-root/oldsite/ is the absolute path.

In that folder is the old /www/ directory, so if it would load via PHP it should give back some Database connection error as I haven’t set up the database for it yet.


#6

If you’re getting a Ghost 404, that means the hierarchy of location blocks isn’t working. This means if you [temporarily] comment out the location / { } block, /oldsite should work. If that’s the case check out this article for info about fixing that. I don’t want to give you advice with that since I myself get confused quite a bit :slight_smile:


#7

Your remark about the hierarchy of location blocks made me think about the hierarchy of the configurations… I realized that I was editing the default conf whilst using SSL, so I should edit the *-ssl.conf

So I did, put the /oldsite/ block above the regular one, and now I get a Forbidden page; so it seems to be working so far :smiley:

Consider my question answered!

TL;DR: I edited the location blocks in the wrong file; using SSL? edit the SSL conf file in sites-enabled/


#8

Maybe I was celebrating too soon; that 403 Forbidden page won’t go away with even the right owner and chmod 777. Is there maybe some other part of Ghost config that might interfere with this?

Edit: Again, pretty simple. Adding the correct indexes to the location block did the trick.
Edit2: Ha. It seems that Ghost hijacks a wp-admin link and redirects it to /ghost… Next battle…


#9

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.