phpdrupalxamppcontent-management-systemcyberduck

Trying to work on a client's Drupal site from my local machine


I have a client who wants me to update their Drupal site. I've never done this before, and I want to work on it from my local machine just in case something goes wrong. I have no idea where to even start!

First off, how do I access my client's site files so I can get them onto my computer? I've tried entering the information the client gave me into Cyberduck, but it won't give me access. Is there another way to get access?

Also, how do I host it locally? I have XAMPP, but I'm not sure how to use it.

That being said, I have found a few forums that should help me set up the local server. I just don't know how to get the files from the live server to my computer.

I know this is a super noob problem, but I could use the help. Thank you!


Solution

  • Well, for the basic question, you have to get the correct credentials from your client. There's no alternative, really :D

    While you're at it, you'll want a copy of the site's database too.

    For the question "how do I host it locally?" Here's how I would go about it.

    Get the site into version control.

    Given that you were given (S)FTP credentials, I'm guessing the site is not version-controlled. If that's correct, then that is probably the very first thing you want to do. This will allow you to keep track of the changes you've made on your local site that are different to the production version.

    1. Create an empty directory on your computer.
    2. Navigate to the directory in a terminal and run git init.
    3. Add a .gitignore file to that folder (you can create your own, or use one customized for Drupal).
    4. Download the site's files into the directory created in step 1.
    5. Add the files from the in the directory to the git repository by running this command in a terminal: git commit -am "First commit of Drupal files to repository."

    There's a good help page about working with Drupal in git on drupal.org.

    Create and populate your database.

    1. Get a database dump from the live site.
    2. Create a new database and database user on your machine.
    3. Import the database dump into your new database.
    4. Record the database credentials in settings.php or settings.local.php and store them somewhere safe, preferably in a password manager.
    5. Change the database credentials in settings.php or settings.local.php to match the credentials of the database you've just created.

      (For safety and to avoid confusion, I always create local databases with a different name, user, and password than the live site has. This means if your local credentials are compromised, the live site isn't, and it means you can't connect to and change the live site's database by accident.)

    Set up the webserver in XAMPP

    1. Create a new site in XAMPP called e.g. example.local that points to the directory that contains the file index.php
    2. Add the following line the file called /etc/hosts on your computer:

      127.0.0.1 example.local

    3. Test that this works in a browser by visiting e.g. http://example.local or http://example.local/robots.txt.

    Move your local changes to the Production site

    How you will be able to do this depends to some extent on your client's web-hosting infrastructure, and what version of Drupal your client uses. but in any case, you will have three separate concerns for changes you make:

    1. Code changes

      You will need to deploy changes you make to the code back to the server. Ideally you would probably do this via Git either by cloning directly into the live site or (far better!) as part of an automated build process. By the sound of it, you may just have to FTP the changes back up.

      Be careful not to re-upload your modified settings.php or settings.local.php file!

    2. Content changes

      You probably have to test some/all of your content changes locally and then recreate them on the live site. Because your client may have made changes to the live site while you were working, you can't risk importing your local database into the live site.

    3. Configuration changes

      Changes to configuration should be managed in code (i.e. as part of 1. Code changes above) if that's possible. In Drupal 7, the Features module is usually the best way to accomplish this (here's an answer I wrote describing the Features workflow). Drupal 8 has the Configuration Manager. Be aware that these two tools can both be tricky to use well.