[{"data":1,"prerenderedAt":1522},["ShallowReactive",2],{"\u002Fblog\u002Fdeploy-drupal-to-cloudways-with-github-actions":3},{"id":4,"title":5,"body":6,"date":1509,"description":1510,"extension":1511,"meta":1512,"navigation":264,"path":1513,"seo":1514,"stem":1515,"tags":1516,"updated":1520,"__hash__":1521},"blog\u002Fblog\u002Fdeploy-drupal-to-cloudways-with-github-actions.md","Deploying Drupal to Cloudways with Git and GitHub Actions",{"type":7,"value":8,"toc":1494},"minimark",[9,13,30,37,62,69,74,83,107,111,156,162,185,206,210,217,330,344,514,520,538,542,545,579,589,592,608,615,619,630,707,717,720,724,730,1243,1248,1314,1318,1321,1355,1359,1373,1390,1402,1410,1448,1452,1463,1477,1490],[10,11,12],"p",{},"Cloudways is a popular, reasonably priced way to host Drupal. It runs your site on a managed server from DigitalOcean, Vultr, AWS or Google Cloud, without you having to look after the server. What it doesn't give you is a proper Drupal deployment pipeline.",[10,14,15,16,20,21,25,26,29],{},"Its built-in ",[17,18,19],"strong",{},"Deployment via Git"," feature does a ",[22,23,24],"code",{},"git pull"," into your application folder, and that's all it does. A modern Drupal site also needs ",[22,27,28],{},"composer install",", database updates, a config import and a cache rebuild after the code changes. Run those by hand over SSH and, sooner or later, someone forgets one.",[10,31,32,33,36],{},"This guide sets up a workflow where a push to ",[22,34,35],{},"main"," deploys the site with no manual steps:",[38,39,40,47,50,56],"ol",{},[41,42,43,44,46],"li",{},"GitHub Actions checks out the code and runs ",[22,45,28],{},".",[41,48,49],{},"It takes a database backup on the server.",[41,51,52,53,46],{},"It uploads the built code to Cloudways with ",[22,54,55],{},"rsync",[41,57,58,59,46],{},"It runs ",[22,60,61],{},"drush deploy",[10,63,64,65,68],{},"The full ",[22,66,67],{},"deploy.yml"," is further down.",[70,71,73],"h2",{"id":72},"why-build-in-github-actions-instead-of-on-the-server","Why build in GitHub Actions instead of on the server?",[10,75,76,77,79,80,82],{},"The common alternative is to SSH in, ",[22,78,24],{},", then run ",[22,81,28],{}," on the server. That works, but building in CI has some real advantages:",[84,85,86,92,101],"ul",{},[41,87,88,91],{},[17,89,90],{},"The server never needs access to your Git repository."," You don't need deploy keys on the server, and nothing breaks when a token expires.",[41,93,94,97,98,100],{},[17,95,96],{},"Composer runs in CI",", not on a small server with a PHP memory limit, which is where ",[22,99,28],{}," likes to fail.",[41,102,103,106],{},[17,104,105],{},"If the build fails, nothing reaches production."," A broken dependency stops the workflow before any files are copied.",[70,108,110],{"id":109},"what-you-need","What you need",[84,112,113,135,144,150],{},[41,114,115,116,119,120,123,124,127,128,131,132,46],{},"A ",[17,117,118],{},"Composer-based Drupal site"," (the standard ",[22,121,122],{},"drupal\u002Frecommended-project"," layout, with the web root in ",[22,125,126],{},"web\u002F","), with ",[22,129,130],{},"drush\u002Fdrush"," in ",[22,133,134],{},"composer.json",[41,136,137,140,141,46],{},[17,138,139],{},"Config exported to Git",", for example in ",[22,142,143],{},"config\u002Fsync",[41,145,115,146,149],{},[17,147,148],{},"Cloudways server"," with a PHP application, set to the PHP version your site needs: 8.3 or newer for Drupal 11.",[41,151,152,155],{},[17,153,154],{},"SSH access"," to the Cloudways server.",[70,157,159,160],{"id":158},"step-1-point-the-cloudways-web-root-at-web","Step 1: Point the Cloudways web root at ",[22,161,126],{},[10,163,164,165,168,169,172,173,176,177,179,180,184],{},"Cloudways serves each application from ",[22,166,167],{},"public_html",". A Composer-based Drupal site keeps ",[22,170,171],{},"vendor\u002F",", ",[22,174,175],{},"config\u002F"," and ",[22,178,134],{}," ",[181,182,183],"em",{},"above"," the public web root, and that is exactly where they should stay.",[10,186,187,188,191,192,195,196,199,200,202,203,205],{},"In the Cloudways dashboard, go to ",[17,189,190],{},"Application Settings → General"," and set the ",[17,193,194],{},"Webroot"," to ",[22,197,198],{},"public_html\u002Fweb",". After that, the whole project lives in ",[22,201,167],{},", but only ",[22,204,198],{}," is reachable from the internet.",[70,207,209],{"id":208},"step-2-keep-secrets-out-of-git","Step 2: Keep secrets out of Git",[10,211,212,213,216],{},"Database credentials and the hash salt must never be committed. The pattern I use: commit ",[22,214,215],{},"settings.php"," with everything that's the same on every environment, and have it include a server-only file:",[218,219,224],"pre",{"className":220,"code":221,"language":222,"meta":223,"style":223},"language-php shiki shiki-themes github-dark","\u002F\u002F web\u002Fsites\u002Fdefault\u002Fsettings.php (committed)\n$settings['config_sync_directory'] = '..\u002Fconfig\u002Fsync';\n\nif (file_exists($app_root . '\u002F' . $site_path . '\u002Fsettings.cloudways.php')) {\n  include $app_root . '\u002F' . $site_path . '\u002Fsettings.cloudways.php';\n}\n","php","",[22,225,226,235,259,266,301,324],{"__ignoreMap":223},[227,228,231],"span",{"class":229,"line":230},"line",1,[227,232,234],{"class":233},"sAwPA","\u002F\u002F web\u002Fsites\u002Fdefault\u002Fsettings.php (committed)\n",[227,236,238,242,246,249,253,256],{"class":229,"line":237},2,[227,239,241],{"class":240},"s95oV","$settings[",[227,243,245],{"class":244},"sU2Wk","'config_sync_directory'",[227,247,248],{"class":240},"] ",[227,250,252],{"class":251},"snl16","=",[227,254,255],{"class":244}," '..\u002Fconfig\u002Fsync'",[227,257,258],{"class":240},";\n",[227,260,262],{"class":229,"line":261},3,[227,263,265],{"emptyLinePlaceholder":264},true,"\n",[227,267,269,272,275,279,282,284,287,290,293,295,298],{"class":229,"line":268},4,[227,270,271],{"class":251},"if",[227,273,274],{"class":240}," (",[227,276,278],{"class":277},"sDLfK","file_exists",[227,280,281],{"class":240},"($app_root ",[227,283,46],{"class":251},[227,285,286],{"class":244}," '\u002F'",[227,288,289],{"class":251}," .",[227,291,292],{"class":240}," $site_path ",[227,294,46],{"class":251},[227,296,297],{"class":244}," '\u002Fsettings.cloudways.php'",[227,299,300],{"class":240},")) {\n",[227,302,304,307,310,312,314,316,318,320,322],{"class":229,"line":303},5,[227,305,306],{"class":251},"  include",[227,308,309],{"class":240}," $app_root ",[227,311,46],{"class":251},[227,313,286],{"class":244},[227,315,289],{"class":251},[227,317,292],{"class":240},[227,319,46],{"class":251},[227,321,297],{"class":244},[227,323,258],{"class":240},[227,325,327],{"class":229,"line":326},6,[227,328,329],{"class":240},"}\n",[10,331,332,333,179,336,339,340,343],{},"Then create ",[22,334,335],{},"web\u002Fsites\u002Fdefault\u002Fsettings.cloudways.php",[17,337,338],{},"on the server only",", using the database details from ",[17,341,342],{},"Application Management → Access Details",":",[218,345,347],{"className":220,"code":346,"language":222,"meta":223,"style":223},"\u003C?php\n$databases['default']['default'] = [\n  'database' => 'your_db_name',\n  'username' => 'your_db_user',\n  'password' => 'your_db_password',\n  'host' => 'localhost',\n  'port' => '3306',\n  'driver' => 'mysql',\n  'prefix' => '',\n];\n$settings['hash_salt'] = 'a-long-random-string';\n$settings['trusted_host_patterns'] = ['^www\\.example\\.co\\.uk$', '^example\\.co\\.uk$'];\n",[22,348,349,357,377,391,403,415,427,440,453,466,472,489],{"__ignoreMap":223},[227,350,351,354],{"class":229,"line":230},[227,352,353],{"class":251},"\u003C?",[227,355,356],{"class":277},"php\n",[227,358,359,362,365,368,370,372,374],{"class":229,"line":237},[227,360,361],{"class":240},"$databases[",[227,363,364],{"class":244},"'default'",[227,366,367],{"class":240},"][",[227,369,364],{"class":244},[227,371,248],{"class":240},[227,373,252],{"class":251},[227,375,376],{"class":240}," [\n",[227,378,379,382,385,388],{"class":229,"line":261},[227,380,381],{"class":244},"  'database'",[227,383,384],{"class":251}," =>",[227,386,387],{"class":244}," 'your_db_name'",[227,389,390],{"class":240},",\n",[227,392,393,396,398,401],{"class":229,"line":268},[227,394,395],{"class":244},"  'username'",[227,397,384],{"class":251},[227,399,400],{"class":244}," 'your_db_user'",[227,402,390],{"class":240},[227,404,405,408,410,413],{"class":229,"line":303},[227,406,407],{"class":244},"  'password'",[227,409,384],{"class":251},[227,411,412],{"class":244}," 'your_db_password'",[227,414,390],{"class":240},[227,416,417,420,422,425],{"class":229,"line":326},[227,418,419],{"class":244},"  'host'",[227,421,384],{"class":251},[227,423,424],{"class":244}," 'localhost'",[227,426,390],{"class":240},[227,428,430,433,435,438],{"class":229,"line":429},7,[227,431,432],{"class":244},"  'port'",[227,434,384],{"class":251},[227,436,437],{"class":244}," '3306'",[227,439,390],{"class":240},[227,441,443,446,448,451],{"class":229,"line":442},8,[227,444,445],{"class":244},"  'driver'",[227,447,384],{"class":251},[227,449,450],{"class":244}," 'mysql'",[227,452,390],{"class":240},[227,454,456,459,461,464],{"class":229,"line":455},9,[227,457,458],{"class":244},"  'prefix'",[227,460,384],{"class":251},[227,462,463],{"class":244}," ''",[227,465,390],{"class":240},[227,467,469],{"class":229,"line":468},10,[227,470,471],{"class":240},"];\n",[227,473,475,477,480,482,484,487],{"class":229,"line":474},11,[227,476,241],{"class":240},[227,478,479],{"class":244},"'hash_salt'",[227,481,248],{"class":240},[227,483,252],{"class":251},[227,485,486],{"class":244}," 'a-long-random-string'",[227,488,258],{"class":240},[227,490,492,494,497,499,501,504,507,509,512],{"class":229,"line":491},12,[227,493,241],{"class":240},[227,495,496],{"class":244},"'trusted_host_patterns'",[227,498,248],{"class":240},[227,500,252],{"class":251},[227,502,503],{"class":240}," [",[227,505,506],{"class":244},"'^www\\.example\\.co\\.uk$'",[227,508,172],{"class":240},[227,510,511],{"class":244},"'^example\\.co\\.uk$'",[227,513,471],{"class":240},[10,515,516,517,343],{},"Add both the server-only file and the uploaded files directory to ",[22,518,519],{},".gitignore",[218,521,525],{"className":522,"code":523,"language":524,"meta":223,"style":223},"language-bash shiki shiki-themes github-dark","\u002Fweb\u002Fsites\u002F*\u002Fsettings.cloudways.php\n\u002Fweb\u002Fsites\u002F*\u002Ffiles\u002F\n","bash",[22,526,527,533],{"__ignoreMap":223},[227,528,529],{"class":229,"line":230},[227,530,532],{"class":531},"svObZ","\u002Fweb\u002Fsites\u002F*\u002Fsettings.cloudways.php\n",[227,534,535],{"class":229,"line":237},[227,536,537],{"class":531},"\u002Fweb\u002Fsites\u002F*\u002Ffiles\u002F\n",[70,539,541],{"id":540},"step-3-create-an-ssh-key-for-github-actions","Step 3: Create an SSH key for GitHub Actions",[10,543,544],{},"Generate a key pair just for deployments, with no passphrase:",[218,546,548],{"className":522,"code":547,"language":524,"meta":223,"style":223},"ssh-keygen -t ed25519 -C \"github-actions-deploy\" -f cloudways_deploy -N \"\"\n",[22,549,550],{"__ignoreMap":223},[227,551,552,555,558,561,564,567,570,573,576],{"class":229,"line":230},[227,553,554],{"class":531},"ssh-keygen",[227,556,557],{"class":277}," -t",[227,559,560],{"class":244}," ed25519",[227,562,563],{"class":277}," -C",[227,565,566],{"class":244}," \"github-actions-deploy\"",[227,568,569],{"class":277}," -f",[227,571,572],{"class":244}," cloudways_deploy",[227,574,575],{"class":277}," -N",[227,577,578],{"class":244}," \"\"\n",[10,580,581,582,585,586,46],{},"In Cloudways, open ",[17,583,584],{},"Server Management → Master Credentials → SSH Public Keys"," and add the contents of ",[22,587,588],{},"cloudways_deploy.pub",[10,590,591],{},"Next, record the server's host key, so GitHub Actions can verify that it's really talking to your server:",[218,593,595],{"className":522,"code":594,"language":524,"meta":223,"style":223},"ssh-keyscan -H YOUR_SERVER_IP\n",[22,596,597],{"__ignoreMap":223},[227,598,599,602,605],{"class":229,"line":230},[227,600,601],{"class":531},"ssh-keyscan",[227,603,604],{"class":277}," -H",[227,606,607],{"class":244}," YOUR_SERVER_IP\n",[10,609,610,611,614],{},"Don't skip this and use ",[22,612,613],{},"StrictHostKeyChecking=no"," instead. That turns off the check that protects your deploy key from a man-in-the-middle attack.",[70,616,618],{"id":617},"step-4-add-github-secrets","Step 4: Add GitHub secrets",[10,620,621,622,625,626,629],{},"In your repository, go to ",[17,623,624],{},"Settings → Environments",", create an environment called ",[22,627,628],{},"production",", and add these secrets:",[631,632,633,646],"table",{},[634,635,636],"thead",{},[637,638,639,643],"tr",{},[640,641,642],"th",{},"Secret",[640,644,645],{},"Value",[647,648,649,660,670,682,695],"tbody",{},[637,650,651,657],{},[652,653,654],"td",{},[22,655,656],{},"CLOUDWAYS_HOST",[652,658,659],{},"Your server's public IP",[637,661,662,667],{},[652,663,664],{},[22,665,666],{},"CLOUDWAYS_USER",[652,668,669],{},"The master SSH username",[637,671,672,677],{},[652,673,674],{},[22,675,676],{},"CLOUDWAYS_PATH",[652,678,679],{},[22,680,681],{},"\u002Fhome\u002Fmaster\u002Fapplications\u002FAPP_FOLDER\u002Fpublic_html",[637,683,684,689],{},[652,685,686],{},[22,687,688],{},"CLOUDWAYS_SSH_KEY",[652,690,691,692],{},"The contents of the private key file ",[22,693,694],{},"cloudways_deploy",[637,696,697,702],{},[652,698,699],{},[22,700,701],{},"CLOUDWAYS_KNOWN_HOSTS",[652,703,704,705],{},"The output of ",[22,706,601],{},[10,708,709,712,713,716],{},[22,710,711],{},"APP_FOLDER"," is a random-looking name that Cloudways gives each application, not your domain. You'll find it in the application's details in the dashboard, or by running ",[22,714,715],{},"ls \u002Fhome\u002Fmaster\u002Fapplications\u002F"," over SSH.",[10,718,719],{},"Using an environment, rather than plain repository secrets, also lets you add protection rules, such as requiring an approval before production deploys.",[70,721,723],{"id":722},"step-5-add-the-workflow","Step 5: Add the workflow",[10,725,726,727,343],{},"Save this as ",[22,728,729],{},".github\u002Fworkflows\u002Fdeploy.yml",[218,731,735],{"className":732,"code":733,"language":734,"meta":223,"style":223},"language-yaml shiki shiki-themes github-dark","name: Deploy to Cloudways\n\non:\n  push:\n    branches: [main]\n  workflow_dispatch: # allows a manual \"Run workflow\" button\n\n# Never run two deployments at the same time\nconcurrency:\n  group: deploy-production\n  cancel-in-progress: false\n\njobs:\n  deploy:\n    runs-on: ubuntu-latest\n    environment: production\n    env:\n      HOST: ${{ secrets.CLOUDWAYS_HOST }}\n      USER: ${{ secrets.CLOUDWAYS_USER }}\n      APP_PATH: ${{ secrets.CLOUDWAYS_PATH }}\n\n    steps:\n      - name: Check out code\n        uses: actions\u002Fcheckout@v4\n\n      - name: Set up PHP\n        uses: shivammathur\u002Fsetup-php@v2\n        with:\n          php-version: '8.3' # match your Cloudways server\n          tools: composer:v2\n\n      - name: Install Composer dependencies\n        run: composer install --no-dev --no-interaction --prefer-dist --optimize-autoloader\n\n      - name: Set up SSH\n        run: |\n          mkdir -p ~\u002F.ssh\n          printf '%s\\n' \"${{ secrets.CLOUDWAYS_SSH_KEY }}\" > ~\u002F.ssh\u002Fid_ed25519\n          printf '%s\\n' \"${{ secrets.CLOUDWAYS_KNOWN_HOSTS }}\" > ~\u002F.ssh\u002Fknown_hosts\n          chmod 600 ~\u002F.ssh\u002Fid_ed25519 ~\u002F.ssh\u002Fknown_hosts\n\n      - name: Back up the database\n        run: |\n          STAMP=$(date -u +%Y%m%d-%H%M%S)\n          # Skipped on the very first deploy, before Drush exists on the server\n          ssh \"$USER@$HOST\" \"cd $APP_PATH && if [ -x vendor\u002Fbin\u002Fdrush ]; then \\\n            mkdir -p ..\u002Fprivate_html\u002Fbackups && \\\n            vendor\u002Fbin\u002Fdrush sql:dump --gzip \\\n              --result-file=$APP_PATH\u002F..\u002Fprivate_html\u002Fbackups\u002Fpre-deploy-$STAMP.sql; fi\"\n\n      - name: Upload code\n        run: |\n          rsync -az --delete \\\n            --exclude='.git\u002F' \\\n            --exclude='.github\u002F' \\\n            --exclude='.ddev\u002F' \\\n            --exclude='web\u002Fsites\u002F*\u002Ffiles\u002F' \\\n            --exclude='web\u002Fsites\u002F*\u002Fsettings.cloudways.php' \\\n            .\u002F \"$USER@$HOST:$APP_PATH\u002F\"\n\n      - name: Run drush deploy\n        run: ssh \"$USER@$HOST\" \"cd $APP_PATH && vendor\u002Fbin\u002Fdrush deploy -y\"\n","yaml",[22,736,737,749,753,761,768,781,791,795,800,807,817,827,831,839,847,858,869,877,888,899,910,915,923,936,947,952,964,974,982,996,1007,1012,1024,1035,1040,1052,1062,1068,1074,1080,1086,1091,1103,1112,1118,1124,1130,1136,1142,1148,1153,1165,1174,1180,1186,1192,1198,1204,1210,1216,1221,1233],{"__ignoreMap":223},[227,738,739,743,746],{"class":229,"line":230},[227,740,742],{"class":741},"s4JwU","name",[227,744,745],{"class":240},": ",[227,747,748],{"class":244},"Deploy to Cloudways\n",[227,750,751],{"class":229,"line":237},[227,752,265],{"emptyLinePlaceholder":264},[227,754,755,758],{"class":229,"line":261},[227,756,757],{"class":277},"on",[227,759,760],{"class":240},":\n",[227,762,763,766],{"class":229,"line":268},[227,764,765],{"class":741},"  push",[227,767,760],{"class":240},[227,769,770,773,776,778],{"class":229,"line":303},[227,771,772],{"class":741},"    branches",[227,774,775],{"class":240},": [",[227,777,35],{"class":244},[227,779,780],{"class":240},"]\n",[227,782,783,786,788],{"class":229,"line":326},[227,784,785],{"class":741},"  workflow_dispatch",[227,787,745],{"class":240},[227,789,790],{"class":233},"# allows a manual \"Run workflow\" button\n",[227,792,793],{"class":229,"line":429},[227,794,265],{"emptyLinePlaceholder":264},[227,796,797],{"class":229,"line":442},[227,798,799],{"class":233},"# Never run two deployments at the same time\n",[227,801,802,805],{"class":229,"line":455},[227,803,804],{"class":741},"concurrency",[227,806,760],{"class":240},[227,808,809,812,814],{"class":229,"line":468},[227,810,811],{"class":741},"  group",[227,813,745],{"class":240},[227,815,816],{"class":244},"deploy-production\n",[227,818,819,822,824],{"class":229,"line":474},[227,820,821],{"class":741},"  cancel-in-progress",[227,823,745],{"class":240},[227,825,826],{"class":277},"false\n",[227,828,829],{"class":229,"line":491},[227,830,265],{"emptyLinePlaceholder":264},[227,832,834,837],{"class":229,"line":833},13,[227,835,836],{"class":741},"jobs",[227,838,760],{"class":240},[227,840,842,845],{"class":229,"line":841},14,[227,843,844],{"class":741},"  deploy",[227,846,760],{"class":240},[227,848,850,853,855],{"class":229,"line":849},15,[227,851,852],{"class":741},"    runs-on",[227,854,745],{"class":240},[227,856,857],{"class":244},"ubuntu-latest\n",[227,859,861,864,866],{"class":229,"line":860},16,[227,862,863],{"class":741},"    environment",[227,865,745],{"class":240},[227,867,868],{"class":244},"production\n",[227,870,872,875],{"class":229,"line":871},17,[227,873,874],{"class":741},"    env",[227,876,760],{"class":240},[227,878,880,883,885],{"class":229,"line":879},18,[227,881,882],{"class":741},"      HOST",[227,884,745],{"class":240},[227,886,887],{"class":244},"${{ secrets.CLOUDWAYS_HOST }}\n",[227,889,891,894,896],{"class":229,"line":890},19,[227,892,893],{"class":741},"      USER",[227,895,745],{"class":240},[227,897,898],{"class":244},"${{ secrets.CLOUDWAYS_USER }}\n",[227,900,902,905,907],{"class":229,"line":901},20,[227,903,904],{"class":741},"      APP_PATH",[227,906,745],{"class":240},[227,908,909],{"class":244},"${{ secrets.CLOUDWAYS_PATH }}\n",[227,911,913],{"class":229,"line":912},21,[227,914,265],{"emptyLinePlaceholder":264},[227,916,918,921],{"class":229,"line":917},22,[227,919,920],{"class":741},"    steps",[227,922,760],{"class":240},[227,924,926,929,931,933],{"class":229,"line":925},23,[227,927,928],{"class":240},"      - ",[227,930,742],{"class":741},[227,932,745],{"class":240},[227,934,935],{"class":244},"Check out code\n",[227,937,939,942,944],{"class":229,"line":938},24,[227,940,941],{"class":741},"        uses",[227,943,745],{"class":240},[227,945,946],{"class":244},"actions\u002Fcheckout@v4\n",[227,948,950],{"class":229,"line":949},25,[227,951,265],{"emptyLinePlaceholder":264},[227,953,955,957,959,961],{"class":229,"line":954},26,[227,956,928],{"class":240},[227,958,742],{"class":741},[227,960,745],{"class":240},[227,962,963],{"class":244},"Set up PHP\n",[227,965,967,969,971],{"class":229,"line":966},27,[227,968,941],{"class":741},[227,970,745],{"class":240},[227,972,973],{"class":244},"shivammathur\u002Fsetup-php@v2\n",[227,975,977,980],{"class":229,"line":976},28,[227,978,979],{"class":741},"        with",[227,981,760],{"class":240},[227,983,985,988,990,993],{"class":229,"line":984},29,[227,986,987],{"class":741},"          php-version",[227,989,745],{"class":240},[227,991,992],{"class":244},"'8.3'",[227,994,995],{"class":233}," # match your Cloudways server\n",[227,997,999,1002,1004],{"class":229,"line":998},30,[227,1000,1001],{"class":741},"          tools",[227,1003,745],{"class":240},[227,1005,1006],{"class":244},"composer:v2\n",[227,1008,1010],{"class":229,"line":1009},31,[227,1011,265],{"emptyLinePlaceholder":264},[227,1013,1015,1017,1019,1021],{"class":229,"line":1014},32,[227,1016,928],{"class":240},[227,1018,742],{"class":741},[227,1020,745],{"class":240},[227,1022,1023],{"class":244},"Install Composer dependencies\n",[227,1025,1027,1030,1032],{"class":229,"line":1026},33,[227,1028,1029],{"class":741},"        run",[227,1031,745],{"class":240},[227,1033,1034],{"class":244},"composer install --no-dev --no-interaction --prefer-dist --optimize-autoloader\n",[227,1036,1038],{"class":229,"line":1037},34,[227,1039,265],{"emptyLinePlaceholder":264},[227,1041,1043,1045,1047,1049],{"class":229,"line":1042},35,[227,1044,928],{"class":240},[227,1046,742],{"class":741},[227,1048,745],{"class":240},[227,1050,1051],{"class":244},"Set up SSH\n",[227,1053,1055,1057,1059],{"class":229,"line":1054},36,[227,1056,1029],{"class":741},[227,1058,745],{"class":240},[227,1060,1061],{"class":251},"|\n",[227,1063,1065],{"class":229,"line":1064},37,[227,1066,1067],{"class":244},"          mkdir -p ~\u002F.ssh\n",[227,1069,1071],{"class":229,"line":1070},38,[227,1072,1073],{"class":244},"          printf '%s\\n' \"${{ secrets.CLOUDWAYS_SSH_KEY }}\" > ~\u002F.ssh\u002Fid_ed25519\n",[227,1075,1077],{"class":229,"line":1076},39,[227,1078,1079],{"class":244},"          printf '%s\\n' \"${{ secrets.CLOUDWAYS_KNOWN_HOSTS }}\" > ~\u002F.ssh\u002Fknown_hosts\n",[227,1081,1083],{"class":229,"line":1082},40,[227,1084,1085],{"class":244},"          chmod 600 ~\u002F.ssh\u002Fid_ed25519 ~\u002F.ssh\u002Fknown_hosts\n",[227,1087,1089],{"class":229,"line":1088},41,[227,1090,265],{"emptyLinePlaceholder":264},[227,1092,1094,1096,1098,1100],{"class":229,"line":1093},42,[227,1095,928],{"class":240},[227,1097,742],{"class":741},[227,1099,745],{"class":240},[227,1101,1102],{"class":244},"Back up the database\n",[227,1104,1106,1108,1110],{"class":229,"line":1105},43,[227,1107,1029],{"class":741},[227,1109,745],{"class":240},[227,1111,1061],{"class":251},[227,1113,1115],{"class":229,"line":1114},44,[227,1116,1117],{"class":244},"          STAMP=$(date -u +%Y%m%d-%H%M%S)\n",[227,1119,1121],{"class":229,"line":1120},45,[227,1122,1123],{"class":244},"          # Skipped on the very first deploy, before Drush exists on the server\n",[227,1125,1127],{"class":229,"line":1126},46,[227,1128,1129],{"class":244},"          ssh \"$USER@$HOST\" \"cd $APP_PATH && if [ -x vendor\u002Fbin\u002Fdrush ]; then \\\n",[227,1131,1133],{"class":229,"line":1132},47,[227,1134,1135],{"class":244},"            mkdir -p ..\u002Fprivate_html\u002Fbackups && \\\n",[227,1137,1139],{"class":229,"line":1138},48,[227,1140,1141],{"class":244},"            vendor\u002Fbin\u002Fdrush sql:dump --gzip \\\n",[227,1143,1145],{"class":229,"line":1144},49,[227,1146,1147],{"class":244},"              --result-file=$APP_PATH\u002F..\u002Fprivate_html\u002Fbackups\u002Fpre-deploy-$STAMP.sql; fi\"\n",[227,1149,1151],{"class":229,"line":1150},50,[227,1152,265],{"emptyLinePlaceholder":264},[227,1154,1156,1158,1160,1162],{"class":229,"line":1155},51,[227,1157,928],{"class":240},[227,1159,742],{"class":741},[227,1161,745],{"class":240},[227,1163,1164],{"class":244},"Upload code\n",[227,1166,1168,1170,1172],{"class":229,"line":1167},52,[227,1169,1029],{"class":741},[227,1171,745],{"class":240},[227,1173,1061],{"class":251},[227,1175,1177],{"class":229,"line":1176},53,[227,1178,1179],{"class":244},"          rsync -az --delete \\\n",[227,1181,1183],{"class":229,"line":1182},54,[227,1184,1185],{"class":244},"            --exclude='.git\u002F' \\\n",[227,1187,1189],{"class":229,"line":1188},55,[227,1190,1191],{"class":244},"            --exclude='.github\u002F' \\\n",[227,1193,1195],{"class":229,"line":1194},56,[227,1196,1197],{"class":244},"            --exclude='.ddev\u002F' \\\n",[227,1199,1201],{"class":229,"line":1200},57,[227,1202,1203],{"class":244},"            --exclude='web\u002Fsites\u002F*\u002Ffiles\u002F' \\\n",[227,1205,1207],{"class":229,"line":1206},58,[227,1208,1209],{"class":244},"            --exclude='web\u002Fsites\u002F*\u002Fsettings.cloudways.php' \\\n",[227,1211,1213],{"class":229,"line":1212},59,[227,1214,1215],{"class":244},"            .\u002F \"$USER@$HOST:$APP_PATH\u002F\"\n",[227,1217,1219],{"class":229,"line":1218},60,[227,1220,265],{"emptyLinePlaceholder":264},[227,1222,1224,1226,1228,1230],{"class":229,"line":1223},61,[227,1225,928],{"class":240},[227,1227,742],{"class":741},[227,1229,745],{"class":240},[227,1231,1232],{"class":244},"Run drush deploy\n",[227,1234,1236,1238,1240],{"class":229,"line":1235},62,[227,1237,1029],{"class":741},[227,1239,745],{"class":240},[227,1241,1242],{"class":244},"ssh \"$USER@$HOST\" \"cd $APP_PATH && vendor\u002Fbin\u002Fdrush deploy -y\"\n",[1244,1245,1247],"h3",{"id":1246},"what-each-step-does","What each step does",[84,1249,1250,1257,1269,1283,1295],{},[41,1251,1252,1256],{},[17,1253,1254],{},[22,1255,804],{}," stops two pushes in quick succession from deploying on top of each other. The second one waits.",[41,1258,1259,1264,1265,1268],{},[17,1260,1261],{},[22,1262,1263],{},"composer install --no-dev"," leaves development tools out of production, and ",[22,1266,1267],{},"--optimize-autoloader"," makes the class loader a little faster.",[41,1270,1271,1274,1275,1278,1279,1282],{},[17,1272,1273],{},"The backup step"," runs ",[181,1276,1277],{},"before"," any code changes, using the Drush already on the server. The dumps go into ",[22,1280,1281],{},"private_html",", which Cloudways keeps outside the web root, so they can't be downloaded. On the very first deploy there's no Drush on the server yet, so the step skips itself.",[41,1284,1285,1290,1291,1294],{},[17,1286,1287],{},[22,1288,1289],{},"rsync --delete"," makes the server match the repository exactly, so files you deleted in Git are deleted on the server too. The ",[22,1292,1293],{},"--exclude"," rules also protect paths from deletion, which is why the uploaded files directory and your server-only settings file survive every deploy.",[41,1296,1297,1301,1302,1305,1306,1309,1310,1313],{},[17,1298,1299],{},[22,1300,61],{}," runs, in the right order: database updates (",[22,1303,1304],{},"updatedb","), a cache rebuild, the config import (",[22,1307,1308],{},"config:import",") and any ",[22,1311,1312],{},"hook_deploy_NAME()"," functions. That's the standard Drupal deployment sequence in one command.",[70,1315,1317],{"id":1316},"step-6-test-it","Step 6: Test it",[10,1319,1320],{},"Before you point it at a live site:",[38,1322,1323,1329,1338,1349],{},[41,1324,1325,1328],{},[17,1326,1327],{},"Back up the application"," in the Cloudways dashboard.",[41,1330,1331,1332,1334,1335,1337],{},"Make sure ",[22,1333,167],{}," contains only what you expect. On the first run, ",[22,1336,1289],{}," removes anything that isn't in your repository or excluded.",[41,1339,1340,1341,1344,1345,1348],{},"Run the workflow manually from the ",[17,1342,1343],{},"Actions"," tab, using the ",[22,1346,1347],{},"workflow_dispatch"," button, and watch the logs.",[41,1350,1351,1352,46],{},"Visit the site, log in, and check ",[17,1353,1354],{},"Reports → Recent log messages",[70,1356,1358],{"id":1357},"common-problems-on-cloudways","Common problems on Cloudways",[10,1360,1361,1364,1365,1368,1369,1372],{},[17,1362,1363],{},"Permission errors after deploying."," Files uploaded by the master user can end up owned differently from files the application writes itself. If Drupal can't write to ",[22,1366,1367],{},"sites\u002Fdefault\u002Ffiles",", use ",[17,1370,1371],{},"Application Settings → Reset Permission"," in the dashboard.",[10,1374,1375,1378,1379,1381,1382,1389],{},[17,1376,1377],{},"Changes not showing for logged-out visitors."," Cloudways puts Varnish in front of your site. ",[22,1380,61],{}," clears Drupal's caches but not Varnish, so purge it from the dashboard after a deploy that changes the front end. You can also add the ",[1383,1384,1388],"a",{"href":1385,"rel":1386},"https:\u002F\u002Fwww.drupal.org\u002Fproject\u002Fpurge",[1387],"nofollow","Purge"," module with a Varnish purger to do it automatically.",[10,1391,1392,1397,1398,1401],{},[17,1393,1394,46],{},[22,1395,1396],{},"drush: command not found"," Always call ",[22,1399,1400],{},"vendor\u002Fbin\u002Fdrush"," from the project root, as the workflow does. Don't rely on a global Drush on the server.",[10,1403,1404,1407,1408,343],{},[17,1405,1406],{},"Composer platform mismatch."," If CI runs a newer PHP than the server, Composer can install packages the server can't run. Pin the server's version in ",[22,1409,134],{},[218,1411,1415],{"className":1412,"code":1413,"language":1414,"meta":223,"style":223},"language-json shiki shiki-themes github-dark","\"config\": {\n  \"platform\": { \"php\": \"8.3\" }\n}\n","json",[22,1416,1417,1425,1444],{"__ignoreMap":223},[227,1418,1419,1422],{"class":229,"line":230},[227,1420,1421],{"class":244},"\"config\"",[227,1423,1424],{"class":240},": {\n",[227,1426,1427,1430,1433,1436,1438,1441],{"class":229,"line":237},[227,1428,1429],{"class":277},"  \"platform\"",[227,1431,1432],{"class":240},": { ",[227,1434,1435],{"class":277},"\"php\"",[227,1437,745],{"class":240},[227,1439,1440],{"class":244},"\"8.3\"",[227,1442,1443],{"class":240}," }\n",[227,1445,1446],{"class":229,"line":261},[227,1447,329],{"class":240},[70,1449,1451],{"id":1450},"where-to-go-from-here","Where to go from here",[10,1453,1454,1455,1458,1459,1462],{},"The same workflow works for a staging site. Copy the job, trigger it on a ",[22,1456,1457],{},"develop"," branch, and point it at a second Cloudways application with its own ",[22,1460,1461],{},"staging"," environment secrets.",[10,1464,1465,1466,1469,1470,1472,1473,1476],{},"You can also add a test job before ",[22,1467,1468],{},"deploy",", running PHPUnit or end-to-end tests with Playwright, and make ",[22,1471,1468],{}," depend on it with ",[22,1474,1475],{},"needs: test",". Then a push that breaks your contact form never reaches production.",[10,1478,1479,1480,1484,1485,1489],{},"Need a hand setting up deployments for your Drupal site, or for your agency's clients? ",[1383,1481,1483],{"href":1482},"\u002Fcontact","Get in touch",". It's the kind of work I do for ",[1383,1486,1488],{"href":1487},"\u002Fagencies","agencies"," regularly.",[1491,1492,1493],"style",{},"html pre.shiki code .sAwPA, html code.shiki .sAwPA{--shiki-default:#6A737D}html pre.shiki code .s95oV, html code.shiki .s95oV{--shiki-default:#E1E4E8}html pre.shiki code .sU2Wk, html code.shiki .sU2Wk{--shiki-default:#9ECBFF}html pre.shiki code .snl16, html code.shiki .snl16{--shiki-default:#F97583}html pre.shiki code .sDLfK, html code.shiki .sDLfK{--shiki-default:#79B8FF}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html pre.shiki code .svObZ, html code.shiki .svObZ{--shiki-default:#B392F0}html pre.shiki code .s4JwU, html code.shiki .s4JwU{--shiki-default:#85E89D}",{"title":223,"searchDepth":237,"depth":237,"links":1495},[1496,1497,1498,1500,1501,1502,1503,1506,1507,1508],{"id":72,"depth":237,"text":73},{"id":109,"depth":237,"text":110},{"id":158,"depth":237,"text":1499},"Step 1: Point the Cloudways web root at web\u002F",{"id":208,"depth":237,"text":209},{"id":540,"depth":237,"text":541},{"id":617,"depth":237,"text":618},{"id":722,"depth":237,"text":723,"children":1504},[1505],{"id":1246,"depth":261,"text":1247},{"id":1316,"depth":237,"text":1317},{"id":1357,"depth":237,"text":1358},{"id":1450,"depth":237,"text":1451},"2026-11-30","A complete, copy-and-paste GitHub Actions workflow that deploys a Composer-based Drupal site to Cloudways on every push: build, upload, database backup and drush deploy.","md",{},"\u002Fblog\u002Fdeploy-drupal-to-cloudways-with-github-actions",{"title":5,"description":1510},"blog\u002Fdeploy-drupal-to-cloudways-with-github-actions",[1517,1518,1519],"Drupal","DevOps","Cloudways",null,"XONeT9FXRAD3dr-lGlB8J1PrbSm035o48tBNfwmvO7Q",1796058883515]