Jump to content

How do you develop on a live site?


totoff
 Share

Recommended Posts

Hi all,

my new website is online but not yet finished. Though it looks good, I have plans for several improvements on both, coding and design. I wonder how others develop on websites that are live? What is your workflow? Do you have a clone and sync your changes back to live? Do you put the site offline for the times you develop on it? Or don't you care at all and just work on the live site?

Curious to learn how others deal with this task.

Thanks!

Link to comment
Share on other sites

Hi @totoff,

it depends on what tasks I want apply to a site. If it only rely on template files, css and js files, I switch from regular to dev-files. Means, I use a little abstraction layer for including my files like this:

$myMainJSfile = "scripts/main.js";
$myMainCSSfile = "styles/main.css";

When working on a live site, I use something like this:

if($user->isSuperuser()) {
    $config->debug = true;
    $myMainJSfile = "scripts/main.dev.js";
    $myMainCSSfile = "styles/main.dev.css";
} else {
    $myMainJSfile = "scripts/main.js";
    $myMainCSSfile = "styles/main.css";
}

When working on templatefiles, I put in the top of the template file a few lines of code:

if($user->isSuperuser()) {
    include("./nameOfMyTemplateFile.dev.php");
    return;
}

This switches to a dev version of the template file and returns directly after including it. (The code of the original isn't executed).

This is a basic description. Depending on how you have organized your site, there is a lot room for improvements, go into depth, make it a more granular system. But you get the idea.

If I need to alter the DB too, I use a separate site/config.dev.php too. YOu can read about it here, scroll down to the end: "Maintaining a separate development configuration file". (I duplicate the DB to a dev-version and connect to it for development)

Edited by horst
added more to the example, (I hit the post button by accident)
  • Like 7
Link to comment
Share on other sites

This methode works for the complete /template/ folder, too....so you could have a whole dev version and change it to live and back if there was problems....

From Diogo's tipps to bookmark:

https://processwire.com/talk/topic/2475-quick-tip-for-testing-on-live-website/#entry23571

;)

Best version i see on this topic for me i copy the template folder and rename it to /dev/ and use the snippet from the post above...make a backup of the live templates and copy the dev files...so you can create simple steps.

Not that perfect like versioning with git - but for small/medium websites it should be a save methode to test and change things live without a risk.

regards mr-fan

Edit: Additional there is a great recipe from Raymond on this topic

https://processwire-recipes.com/recipes/use-different-sets-of-template-files/

Edited by mr-fan
  • Like 4
Link to comment
Share on other sites

Hi,

it is just an example. I use module SPEX, that provides delayed output and a lot more. With it I call the files like this:

$spex->addScript('scripts/jquery.min.js');
$spex->addScript($myMainJSfile);

$spex->addStyle('styles/main.less');

It is similar to the regular use of

$config->scripts->add( $config->urls->templates . $myMainJSfile );
Link to comment
Share on other sites

That's interesting. Usually I have a local copy of each site. For sync (and deploy) I use capistrano. 

For example: cap production db:server_to_local.

- db:server_to_local         Import server database locally
--- executes ---
- db:dump_server_db          dump server database
- db:download_server_dump    download server database dump
- db:dump_local_db           backup local database
- db:import_server_db        import server database locally
- db:download_assets         you will be asked, whether to fetch assets from server

This way I can also sync between servers easily (production to staging for example).

  • Like 5
Link to comment
Share on other sites

I'll make sure that nobody is working on the content for that time (for example disabling login for editors). And I exclude tables which contain dynamic content, for example incoming contact requests ( ignore_tables = ['field_scf_email', 'field_scf_fullname', ... ]; ). But I know this doesn't handle all cases...

  • Like 1
Link to comment
Share on other sites

I am yet trying to encorporate this in my workflow, but deployer seems to be valid alternative to capistrano. And it is in PHP, so no need for Ruby.

The developer is Russian, so that gives me a little pride. A lot of Capistrano maintainers are also my fellow contrymen - just to point that we not only bomb and confront :).

@pwired: There seems to be a web interface to deployer too. You can see it on the frontpage of offsite and the source is on github/ At least i think I saw it there.

  • Like 5
Link to comment
Share on other sites

I'm currently working on a bigger project with migration files, like posted here: https://processwire.com/talk/topic/11382-migrating-modules/?p=106238. Currently there's no migration automation, but it keeps changes to the db manageable by source control. I just deploy by git pull and then run the new migrations manually.

  • Like 3
Link to comment
Share on other sites

Ivan's post about deployer really motivates me to leave ftp for what it is and setup a virtual machine with linux.

Probably antiX-13.2 (debian) because it is so fast and light.

After some digging with google I found a real good and clear tuto about deployer for beginners:

https://codereviewvideos.com/course/deployer-easy-php-deployment/video/introduction-to-deployer
https://codereviewvideos.com/course/deployer-easy-php-deployment/video/installing-deployer

After the first two video's you have to subscribe to see the rest of the video's but the tuto text goes on until the end.

But I am happy to subscribe there as codereviewvideos made a good impression on me. Site is very easy to navigate,

easy to read, clear layout/design/font. Easy to follow video's with clear spoken voice. (no I am not affiliated)

I saw also video's there about gulp, vagrant, restfulAPI, composer, phpstorm and a Blog.

  • Like 1
Link to comment
Share on other sites

Deployment over ftp just doesn't make sense as you cannot access the db via ftp. Also ftp can upload files, but not execute them, so it's really a lot less useful in that context.

Hhm, this is right, in general. - But, if you use FTP from within a php script, you can use it for deploying. To execute scripts, you can A) upload individual scripts to the server (via FTP). and after upload, you can trigger the execution via HTTP. Accessing DBs also is easy.

I have used php for a long time for syncing files on live and local servers. Scanning local project directory and collect last-modified + crc32 checksums, than do the same on the live server. - Hhm, I found an old script, - tested it and - surprise - it is still running! :)

(I will upload some screenshots.)

It originally was created in that times when webdev often was writing and deploying static html files, or maybe some php files but without a CMS, etc. (around 1998/99, for me) :)

So, this is only in the context of historical interest. :lol:

post-1041-0-60593500-1449097555_thumb.jp

post-1041-0-57395400-1449097571_thumb.jp

post-1041-0-09775600-1449097645_thumb.jp

  • Like 5
Link to comment
Share on other sites

  • 7 months later...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...