Link to home
Start Free TrialLog in
Avatar of Colin Brazier
Colin BrazierFlag for United Kingdom of Great Britain and Northern Ireland

asked on

How to run a side-by-side staging website

Hi experts,

The time has come for me to move from mysql to mysqli.   I have developed a copy of my site using apache on my Windows PC and the new version seems to work fine on it.  But the live site is on a shared Linux host and so there will be many differences to my test environment.

Simply copying all the new files over from my PC to the live site would probably work OK but I want to take a more professional approach going forward.

I have created a new subdomain under the live site but when testing that, links like <img src="/gifs/Ollies_01d1.gif"> simply point to the existing image and not to one under the staging subdomain, if you follow me!

So, how do people run a staging site which best mirrors their live site and enables development without having to take down the live site?

Thanks for reading.

  Col
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Colin Brazier

ASKER

Hi Julian,

Thanks - good stuff.

I'm not using a <base href=""> tag or .htaccess file - should I be?  

How do the practicalities work for a staging site?  Would I buy another domain name and set up a copy of the database with the same hosting company as the live site?   Or could I get the subdomain idea to work using the base href and/or .htaccess file?

Google Analytics?  I haven't been there yet!  That's another question!
If the question is "what's the best way forward with MySQLi" then you might want to consider the possibility of running both extensions in parallel.  You can make a connection to MySQL and a separate connection to MySQLi.  You can convert the queries one at a time, and if you use the MySQLi object-oriented notation, there will be very little change needed, relative to the changes required by PDO or procedural MySQLi.  

Mapping of the familiar, but obsolete MySQL functions to the currently supported extensions:
https://iconoun.com/mysql_mysqli_pdo_function_map.php

Some examples and guidance are available in this article:
https://www.experts-exchange.com/articles/11177/PHP-MySQL-Deprecated-as-of-PHP-5-5-0.html
I'm not using a <base href=""> tag or .htaccess file - should I be?  
No, but if you have setup a sub-domain and your images are loading as /imagepath and you are getting the wrong image then the above would be potential causes.

Regarding a stage environment. I usually setup a subdomain
http://stage.mydomain.com

Open in new window

This is important as using a sub-folder (http://www.mydomain.com/stage) will work but create potential problems with paths. You want your stage to operate as root domain.
Depending on your hosting environment you will be given the option to setup the sub-domain to point to a different folder off the same root as the main site or as a sub-folder of your main site. The former is preferable as it prevents access to the domain through the main site url. If the option for a separate folder is not provided then you can point the sub-domain to a sub-folder of the main site but then it is even more important that you set up security (.htpasswd) to control access to the folder.

Going back to your question:
How you get the sub-domain to work is dependent on your ISP - usually you have the option to create a sub-domain in your control panel and from there you configure where it points. Once you have set it up you should be able to access the website in the sub-domain with no problems with paths.
Thanks Ray.  I have made the conversion on my XAMPP site on my PC and all seems to work well there, but this was a more generic question, I really would like a staging site in the same environment as the live one.

The mySQLi change got me thinking about this as it involves virtually every page on my website being updated (probably due to bad design) and I got shivers at the thought of it.  I'll be making a lot more changes in future, when I can find the time.
You might want to think about abstracting your database access.

There are libraries that do this - I prefer to roll my own.

I have a Database class that has a number of methods defined on it
find
find_first
update_record
add_record
etc

These essentially hide the library implementation and allow for a relatively painless upgrade / crossgrade to another library.

It also makes your code more secure - by wrapping the MySQL functions you can ensure that the risk of vulnerabilities are minimized.
Julian,
Depending on your hosting environment you will be given the option to setup the sub-domain to point to a different folder off the same root as the main site or as a sub-folder of your main site.
I'm on the right track with a sub-domain then.  I only have the option to point to a sub-folder of my main site.  So sub-domain "staging" is http://staging.fobgfc.org pointing to a sub-folder of my htdocs main site folder.

Re-reading your posts, you imply that I shouldn't be running into path issues doing it this way.  I will check again the base href issue.
I checked again and I don't use base href.  My hosting company has told me I can only use .htaccess for "basic mod_rewrite", whatever that means!
.htaccess is not a requirement for this - I was saying it was a potential cause of why /imagepath was resolving to your live site.
If you are not using .htaccess for your current site then you don't need it - same for <base href>

What does your folder structure look like for your setup - live and stage?
Just saw your previous post
Re-reading your posts, you imply that I shouldn't be running into path issues doing it this way.  I will check again the base href issue.
No, if you are accessing the site with http://staging.fobgfc.org then all paths will be relative to this root - you should not be able to get access to the parent from here even if you wanted to.
Just had a look at your stage site - if you look at the image on the home page it's src is set to
http://www.fobgfc.org/gifs/pitch_seq_04.gif

Open in new window

In other words it is hard coded to the parent site.
To setup your stage environment you will have to edit the content and make sure all paths to resources (images, css, js etc) are relative.
Yes that image is hard-coded, that's an effect of the third-party s/w I used to add the news items.  If you look at the sponsors' pictures on the right, they are not hard-coded, they begin /gifs/...

The file structure, simplified, is  

htdocs
    CSS
    classes
    gifs
    staging
        CSS
        classes

The sub-domain points at the staging folder.  There is no gifs folder under staging, so those sponsors images shouldn't have been found?

Incidentally, I type http://www.staging.fobgfc.org and it is changed to fobgfc.org/staging which is why I need the password I guess.
If I remove the initial / in the staging links it points to what it should.  Otherwise it goes back to use fobgfc.org as the root.

So is it safe to say I should remove that in all links, whether staging or not?
Yup - that will do it.
Thanks again.
You are welcome