Git has become the standard of collaborative code development. Using the built-in version management tools and the unique deployment system that comprises pulling the latest version of the code to any deployment platform, developers could make sure that the project deadlines are achieved by the distributed team.
The clone module permits clients to form a duplicate of an existing item of site content (a hub) and then edit that copy. The creation is set to the current user, the menu and URL aliases are reset, and the words “Clone of” are embedded into the title to remind you merely are not altering the first content.
In this tutorial, I am going to walk you through the steps needed to pull the code of a Drupal website from the Git and deploy it on the Cloudways servers.
- Launch Drupal 8 on Cloudways
- Prepare the Server for the Drupal Website
- Remove all Files and Folders in the Application
- Delete the existing Database
- Start the Cloning Process
- Installing the Required Dependencies
- Import Data from the existing Website
- Create a new settings.php file
- Change Permissions
- Installation of the new website
Pre-Requisites
- You will need a software like PuTTy to connect to CW server
- A Cloudways account with Drupal 8 installed on Server
- A Git account
Launch Drupal 8 on Cloudways
You will need to launch a Drupal 8 application on your Cloudways server. This allows you to take full advantage of the caching and server configuration that Cloudways specifically offers for Drupal websites.
Prepare the Server for the Drupal Website
Next, you need to connect to the website you have already launched by using a CLI software of your choice (I recommend using PuTTY)
Remove All Files and Folders in the Application
Before you clone your existing site to your Drupal server on Cloudways, you will need to remove all files and folders already present in the application’s public_html folder through the following command
cd applications/<application name>/public_html
Since the application name is similar to the database name, you could use the following command to remove all the files in it:
rm -Rf *.*
Delete the Existing Database
In addition to removing all files and folders, you also need to remove the existing database. Launch the database manager in your Cloudways application and select information_schema from the dropdown list. Then, use the following command to delete the database:
drop database <database_name>
Now, create a new database with the same name as the one you deleted by using the following command:
create database <database_name>
Note: The name has to be the same or the app won’t read the database.
Stop Wasting Time on Servers
Cloudways handle server management for you so you can focus on creating great apps and keeping your clients happy.
Start the Cloning Process
Next, use the following command to clone your Git repository from Git
git clone <your URL>
Example: git clone https://github.com/username/name.git
Installing the Required Dependencies
Run the following command to install the required dependencies for Drupal 8.
cd name composer install
Import Database From the Existing Website
Next, go to the Cloudways database manager and import your existing website’s database.
Once the import process finishes, truncate all the cache tables in the database. Use the commands in the following screenshot.
Create a New settings.php
Now, navigate to your Drupal’s sites/default folder using the cd directory_name command. Using the rm file_name command, delete the settings.php file if it is present in the directory.
Next, create a new settings.php file using the following command
touch settings.php
Change Permissions
An important step at this point is to change the file permissions of the .htaccess file to 604. You will find this file in the sites/default/files/ directory. Navigate to this directory and change the permissions using the following command:
chmod 604 .htaccess
Installation of the Website
The preparations are now over and it is time to launch the application using the staging URL provided in the Application Access Detail tab.
Once the URL has been launched, the Drupal Installation page would come up. Just follow the prompts of the wizard and the process finishes in several minutes.
During the installation process, the wizard will ask you for the database. When prompted, enter your Cloudways application database credentials.
Once it has finished, the setup will indicate that the website is already installed. Just click view the button and the website will be launched.
You will now see the installed Drupal website.
Conclusion
Cloning your Drupal site from Git is a pretty straight-forward procedure. If you face an issue in the process or would like to contribute to the discussion, do leave a comment below.
If you are looking to improve your Drupal website’s performance, do read this blog post by us on, How To Improve Drupal’s Performance Through Cloudways.
Shahzeb Ahmed
Shahzeb is a Digital Marketer with a Software Engineering background, works as a Community Manager — PHP Community at Cloudways. He is growth ambitious and aims to learn & share information about PHP & Laravel Development through practice and experimentation. He loves to travel and explore new ideas whenever he finds time. Get in touch with him at [email protected]