{"id":565,"date":"2020-01-14T04:49:03","date_gmt":"2020-01-14T04:49:03","guid":{"rendered":"https:\/\/digitalchild.info\/?p=565"},"modified":"2020-01-14T04:49:03","modified_gmt":"2020-01-14T04:49:03","slug":"fix-undefined-index-http_x_forwarded_proto-with-wp-cli","status":"publish","type":"post","link":"https:\/\/randomadult.local\/fix-undefined-index-http_x_forwarded_proto-with-wp-cli\/","title":{"rendered":"Fix Undefined index: HTTP_X_FORWARDED_PROTO with WP-CLI"},"content":{"rendered":"\n
\"Undefined<\/figure>\n\n\n\n

Are you running your WordPress install behind an SSL proxy or load balancer like HAProxy<\/a>? You may also be running WP-CLI on the internal site. <\/p>\n\n\n\n

To get SSL to pass-through correctly a lot of sites<\/a> have outlined that you need to add the following code to your wp-config.php<\/strong> <\/p>\n\n\n

\ndefine('FORCE_SSL_ADMIN', true);\ndefine('FORCE_SSL_LOGIN', true);\nif ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')\n$_SERVER['HTTPS']='on';\n<\/pre><\/div>\n\n\n

Although this is almost correct, the HTTP_X_FORWARDED_PROTO line is incorrect. If you use this code your WordPress site will work correctly with your SSL certificate on your proxy\/load balancer. But if you try and run a WP-CLI command you’ll get the following error. <\/p>\n\n\n

\nPHP Notice:  Undefined index: HTTP_X_FORWARDED_PROTO in phar:\/\/\/usr\/local\/bin\/wp\/vendor\/wp-cli\/wp-cli\/php\/WP_CLI\/Runner.php(1197) : eval()'d code on line 71\n\n<\/pre><\/div>\n\n\n

After some searching, I found this closed <\/a>issue in the WP-CLI GitHub issues. It has a reply from Daniel Bachhuber<\/a> the previous WP-CLI maintainer with an easy fix. <\/p>\n\n\n\n

The Fix<\/h2>\n\n\n\n

The fix is pretty straight forward and all you have to do is check that the index exists and then set it as required. Updated your wp-config.php<\/strong> file to look like this. <\/p>\n\n\n

\ndefine('FORCE_SSL_ADMIN', true);\ndefine('FORCE_SSL_LOGIN', true);\nif (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https'){ $_SERVER['HTTPS']='on'; }\n<\/pre><\/div>\n\n\n

Once you have added the array key check it’ll work correctly both for the site itself and for wp-cli. <\/p>\n","protected":false},"excerpt":{"rendered":"

Are you running your WordPress install behind an SSL proxy or load balancer like HAProxy? You may also be running WP-CLI on the internal site. To get SSL to pass-through correctly a lot of sites have outlined that you need to add the following code to your wp-config.php Although this …<\/p>\n

Fix Undefined index: HTTP_X_FORWARDED_PROTO with WP-CLI<\/span> Read More \u00bb<\/a><\/p>\n","protected":false},"author":1,"featured_media":567,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":""},"categories":[5],"tags":[83,110,189,224,226],"yoast_head":"\nFix Undefined index: HTTP_X_FORWARDED_PROTO with WP-CLI - Random Adult<\/title>\n<meta name=\"description\" content=\"Running WordPress behind an SSL proxy. Use this fix for the following Undefined index: HTTP_X_FORWARDED_PROTO issue.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/randomadult.local\/fix-undefined-index-http_x_forwarded_proto-with-wp-cli\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Fix Undefined index: HTTP_X_FORWARDED_PROTO with WP-CLI\" \/>\n<meta property=\"og:description\" content=\"Running WordPress behind an SSL proxy. Use this fix for the following Undefined index: HTTP_X_FORWARDED_PROTO issue.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/randomadult.local\/fix-undefined-index-http_x_forwarded_proto-with-wp-cli\/\" \/>\n<meta property=\"og:site_name\" content=\"Random Adult\" \/>\n<meta property=\"article:published_time\" content=\"2020-01-14T04:49:03+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/randomadult.local\/wp-content\/uploads\/2020\/01\/wp-cli-errors.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1016\" \/>\n\t<meta property=\"og:image:height\" content=\"206\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"digitalchild\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@dcwhatwhat\" \/>\n<meta name=\"twitter:site\" content=\"@dcwhatwhat\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"digitalchild\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/randomadult.local\/fix-undefined-index-http_x_forwarded_proto-with-wp-cli\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/randomadult.local\/fix-undefined-index-http_x_forwarded_proto-with-wp-cli\/\"},\"author\":{\"name\":\"digitalchild\",\"@id\":\"https:\/\/randomadult.local\/#\/schema\/person\/b0b954202434291ace51b4e7a0a81c04\"},\"headline\":\"Fix Undefined index: HTTP_X_FORWARDED_PROTO with WP-CLI\",\"datePublished\":\"2020-01-14T04:49:03+00:00\",\"dateModified\":\"2020-01-14T04:49:03+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/randomadult.local\/fix-undefined-index-http_x_forwarded_proto-with-wp-cli\/\"},\"wordCount\":189,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/randomadult.local\/#organization\"},\"keywords\":[\"haproxy\",\"lets encrypt\",\"SSL\",\"wordpress\",\"wp-cli\"],\"articleSection\":[\"Geek\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/randomadult.local\/fix-undefined-index-http_x_forwarded_proto-with-wp-cli\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/randomadult.local\/fix-undefined-index-http_x_forwarded_proto-with-wp-cli\/\",\"url\":\"https:\/\/randomadult.local\/fix-undefined-index-http_x_forwarded_proto-with-wp-cli\/\",\"name\":\"Fix Undefined index: HTTP_X_FORWARDED_PROTO with WP-CLI - Random Adult\",\"isPartOf\":{\"@id\":\"https:\/\/randomadult.local\/#website\"},\"datePublished\":\"2020-01-14T04:49:03+00:00\",\"dateModified\":\"2020-01-14T04:49:03+00:00\",\"description\":\"Running WordPress behind an SSL proxy. Use this fix for the following Undefined index: HTTP_X_FORWARDED_PROTO issue.\",\"breadcrumb\":{\"@id\":\"https:\/\/randomadult.local\/fix-undefined-index-http_x_forwarded_proto-with-wp-cli\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/randomadult.local\/fix-undefined-index-http_x_forwarded_proto-with-wp-cli\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/randomadult.local\/fix-undefined-index-http_x_forwarded_proto-with-wp-cli\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/randomadult.local\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Fix Undefined index: HTTP_X_FORWARDED_PROTO with WP-CLI\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/randomadult.local\/#website\",\"url\":\"https:\/\/randomadult.local\/\",\"name\":\"Random Adult\",\"description\":\"Ramblings of a random adult\",\"publisher\":{\"@id\":\"https:\/\/randomadult.local\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/randomadult.local\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/randomadult.local\/#organization\",\"name\":\"Random Adult\",\"url\":\"https:\/\/randomadult.local\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/randomadult.local\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/randomadult.local\/wp-content\/uploads\/2020\/01\/logo.png\",\"contentUrl\":\"https:\/\/randomadult.local\/wp-content\/uploads\/2020\/01\/logo.png\",\"width\":320,\"height\":134,\"caption\":\"Random Adult\"},\"image\":{\"@id\":\"https:\/\/randomadult.local\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/twitter.com\/dcwhatwhat\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/randomadult.local\/#\/schema\/person\/b0b954202434291ace51b4e7a0a81c04\",\"name\":\"digitalchild\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/randomadult.local\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/e0331079f6730910bc7760cb8f781237?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/e0331079f6730910bc7760cb8f781237?s=96&d=mm&r=g\",\"caption\":\"digitalchild\"},\"url\":\"https:\/\/randomadult.local\/author\/digitalchild\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Fix Undefined index: HTTP_X_FORWARDED_PROTO with WP-CLI - Random Adult","description":"Running WordPress behind an SSL proxy. Use this fix for the following Undefined index: HTTP_X_FORWARDED_PROTO issue.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/randomadult.local\/fix-undefined-index-http_x_forwarded_proto-with-wp-cli\/","og_locale":"en_US","og_type":"article","og_title":"Fix Undefined index: HTTP_X_FORWARDED_PROTO with WP-CLI","og_description":"Running WordPress behind an SSL proxy. Use this fix for the following Undefined index: HTTP_X_FORWARDED_PROTO issue.","og_url":"https:\/\/randomadult.local\/fix-undefined-index-http_x_forwarded_proto-with-wp-cli\/","og_site_name":"Random Adult","article_published_time":"2020-01-14T04:49:03+00:00","og_image":[{"width":1016,"height":206,"url":"https:\/\/randomadult.local\/wp-content\/uploads\/2020\/01\/wp-cli-errors.png","type":"image\/png"}],"author":"digitalchild","twitter_card":"summary_large_image","twitter_creator":"@dcwhatwhat","twitter_site":"@dcwhatwhat","twitter_misc":{"Written by":"digitalchild","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/randomadult.local\/fix-undefined-index-http_x_forwarded_proto-with-wp-cli\/#article","isPartOf":{"@id":"https:\/\/randomadult.local\/fix-undefined-index-http_x_forwarded_proto-with-wp-cli\/"},"author":{"name":"digitalchild","@id":"https:\/\/randomadult.local\/#\/schema\/person\/b0b954202434291ace51b4e7a0a81c04"},"headline":"Fix Undefined index: HTTP_X_FORWARDED_PROTO with WP-CLI","datePublished":"2020-01-14T04:49:03+00:00","dateModified":"2020-01-14T04:49:03+00:00","mainEntityOfPage":{"@id":"https:\/\/randomadult.local\/fix-undefined-index-http_x_forwarded_proto-with-wp-cli\/"},"wordCount":189,"commentCount":0,"publisher":{"@id":"https:\/\/randomadult.local\/#organization"},"keywords":["haproxy","lets encrypt","SSL","wordpress","wp-cli"],"articleSection":["Geek"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/randomadult.local\/fix-undefined-index-http_x_forwarded_proto-with-wp-cli\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/randomadult.local\/fix-undefined-index-http_x_forwarded_proto-with-wp-cli\/","url":"https:\/\/randomadult.local\/fix-undefined-index-http_x_forwarded_proto-with-wp-cli\/","name":"Fix Undefined index: HTTP_X_FORWARDED_PROTO with WP-CLI - Random Adult","isPartOf":{"@id":"https:\/\/randomadult.local\/#website"},"datePublished":"2020-01-14T04:49:03+00:00","dateModified":"2020-01-14T04:49:03+00:00","description":"Running WordPress behind an SSL proxy. Use this fix for the following Undefined index: HTTP_X_FORWARDED_PROTO issue.","breadcrumb":{"@id":"https:\/\/randomadult.local\/fix-undefined-index-http_x_forwarded_proto-with-wp-cli\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/randomadult.local\/fix-undefined-index-http_x_forwarded_proto-with-wp-cli\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/randomadult.local\/fix-undefined-index-http_x_forwarded_proto-with-wp-cli\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/randomadult.local\/"},{"@type":"ListItem","position":2,"name":"Fix Undefined index: HTTP_X_FORWARDED_PROTO with WP-CLI"}]},{"@type":"WebSite","@id":"https:\/\/randomadult.local\/#website","url":"https:\/\/randomadult.local\/","name":"Random Adult","description":"Ramblings of a random adult","publisher":{"@id":"https:\/\/randomadult.local\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/randomadult.local\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/randomadult.local\/#organization","name":"Random Adult","url":"https:\/\/randomadult.local\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/randomadult.local\/#\/schema\/logo\/image\/","url":"https:\/\/randomadult.local\/wp-content\/uploads\/2020\/01\/logo.png","contentUrl":"https:\/\/randomadult.local\/wp-content\/uploads\/2020\/01\/logo.png","width":320,"height":134,"caption":"Random Adult"},"image":{"@id":"https:\/\/randomadult.local\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/twitter.com\/dcwhatwhat"]},{"@type":"Person","@id":"https:\/\/randomadult.local\/#\/schema\/person\/b0b954202434291ace51b4e7a0a81c04","name":"digitalchild","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/randomadult.local\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/e0331079f6730910bc7760cb8f781237?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e0331079f6730910bc7760cb8f781237?s=96&d=mm&r=g","caption":"digitalchild"},"url":"https:\/\/randomadult.local\/author\/digitalchild\/"}]}},"_links":{"self":[{"href":"https:\/\/randomadult.local\/wp-json\/wp\/v2\/posts\/565"}],"collection":[{"href":"https:\/\/randomadult.local\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/randomadult.local\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/randomadult.local\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/randomadult.local\/wp-json\/wp\/v2\/comments?post=565"}],"version-history":[{"count":0,"href":"https:\/\/randomadult.local\/wp-json\/wp\/v2\/posts\/565\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomadult.local\/wp-json\/wp\/v2\/media\/567"}],"wp:attachment":[{"href":"https:\/\/randomadult.local\/wp-json\/wp\/v2\/media?parent=565"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomadult.local\/wp-json\/wp\/v2\/categories?post=565"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomadult.local\/wp-json\/wp\/v2\/tags?post=565"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}