{"id":4274,"date":"2020-07-21T20:21:05","date_gmt":"2020-07-21T08:21:05","guid":{"rendered":"http:\/\/www.zoyinc.com\/?p=4274"},"modified":"2020-08-16T21:10:59","modified_gmt":"2020-08-16T09:10:59","slug":"download-failed-curl-error-2","status":"publish","type":"post","link":"http:\/\/www.zoyinc.com\/?p=4274","title":{"rendered":"Download failed.: cURL error 2:"},"content":{"rendered":"\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4277\" src=\"http:\/\/www.zoyinc.com\/wp-content\/uploads\/2020\/07\/CurlError2_01.jpg\" alt=\"\" width=\"922\" height=\"265\" srcset=\"http:\/\/www.zoyinc.com\/wp-content\/uploads\/2020\/07\/CurlError2_01.jpg 922w, http:\/\/www.zoyinc.com\/wp-content\/uploads\/2020\/07\/CurlError2_01-300x86.jpg 300w, http:\/\/www.zoyinc.com\/wp-content\/uploads\/2020\/07\/CurlError2_01-150x43.jpg 150w, http:\/\/www.zoyinc.com\/wp-content\/uploads\/2020\/07\/CurlError2_01-768x221.jpg 768w, http:\/\/www.zoyinc.com\/wp-content\/uploads\/2020\/07\/CurlError2_01-500x144.jpg 500w\" sizes=\"auto, (max-width: 922px) 100vw, 922px\" \/><\/p>\n<p>I upgraded my WordPress host to CentOS7 with PHP7.3 and everything seemed fine until I went to upgrade and I got:<\/p>\n<p style=\"padding-left: 40px;\">Update WordPress<br \/>Downloading update from https:\/\/downloads.wordpress.org\/release\/en_NZ\/wordpress-5.4.2.zip\u2026<br \/>Download failed.: cURL error 2:<br \/>Installation Failed<\/p>\n<p>Also from Health check<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4304\" src=\"http:\/\/www.zoyinc.com\/wp-content\/uploads\/2020\/07\/CurlError2_05.jpg\" alt=\"\" width=\"1104\" height=\"476\" srcset=\"http:\/\/www.zoyinc.com\/wp-content\/uploads\/2020\/07\/CurlError2_05.jpg 1104w, http:\/\/www.zoyinc.com\/wp-content\/uploads\/2020\/07\/CurlError2_05-300x129.jpg 300w, http:\/\/www.zoyinc.com\/wp-content\/uploads\/2020\/07\/CurlError2_05-150x65.jpg 150w, http:\/\/www.zoyinc.com\/wp-content\/uploads\/2020\/07\/CurlError2_05-768x331.jpg 768w, http:\/\/www.zoyinc.com\/wp-content\/uploads\/2020\/07\/CurlError2_05-500x216.jpg 500w\" sizes=\"auto, (max-width: 1104px) 100vw, 1104px\" \/><\/p>\n<p style=\"padding-left: 40px;\">Communicating with the WordPress servers is used to check for new versions, and to both install and update WordPress core, themes or plugins.<\/p>\n<p style=\"padding-left: 40px;\">our site is unable to reach WordPress.org at 198.143.164.251, and returned the error: cURL error 2:<\/p>\n<p>Also<\/p>\n<p style=\"padding-left: 40px;\"><span class=\"nroffip\">CURLE_FAILED_INIT (2)<\/span><\/p>\n<p style=\"padding-left: 40px;\">Very early initialization code failed. This is likely to be an internal error or problem, or a resource problem where something fundamental couldn&#8217;t get done at init time.<\/p>\n<h1>Its not a WordPress problem<\/h1>\n<p>The more I dug into this, the more I realized the problems I had were a symptom of a bigger problem. For example I tried running a straight curl command and it worked fine.<\/p>\n<p>Because WordPress runs curl from within PHP I created a test script:<\/p>\n<pre role=\"textbox\" aria-multiline=\"true\" aria-label=\"Write preformatted text\u2026\" class=\"rich-text block-editor-rich-text__editable wp-block-preformatted crayon:false;\" contenteditable=\"true\">&lt;?php<br \/>   $url = \"https:\/\/www.google.com\/\";<br \/>   $ch = curl_init();<br \/>   curl_setopt($ch, CURLOPT_URL, $url);<br \/>   curl_setopt($ch, CURLOPT_VERBOSE, 1);<br \/>   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);<br \/>   curl_setopt($ch, CURLOPT_AUTOREFERER, false);<br \/>   curl_setopt($ch, CURLOPT_REFERER, \"http:\/\/www.xcontest.org\");<br \/>   curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);<br \/>   curl_setopt($ch, CURLOPT_HEADER, 0);<br \/>   $result = curl_exec($ch);<br \/>   echo $result;<br \/>   echo \"Curl error: \".curl_errno($ch).\"&lt;\/br&gt;\";<br \/>   echo \"URL: \".$url; curl_close($ch);<br \/>?&gt;<\/pre>\n<p>This script ran fine if I ran it from the command line using<\/p>\n<p style=\"padding-left: 40px;\">php -f test.php<\/p>\n<p>but if I called the same script from Apache, httpd24, I got the<\/p>\n<p style=\"padding-left: 40px;\">Curl error: 2<br \/>URL: https:\/\/www.google.com\/<\/p>\n<p>I tried adding every type of debug option I could but I got not detail about what was going on.<\/p>\n<h1>Solution was fpm<\/h1>\n<p>When I did the setup of this host I was aware that PHP&#8217;s preferred, faster, way of running PHP on a website was using &#8220;fpm&#8221;. However I felt that since my site was small and not too busy it was unnecessary work, so didn&#8217;t use it.<\/p>\n<p>My lack of success and frustration encouraged me to try out fpm.<\/p>\n<p>First thing I had to erase rh-php72-php using:<\/p>\n<p style=\"padding-left: 40px;\">yum erase rh-php72-php<\/p>\n<p>Then I needed to install rh-php72-php-fpm using<\/p>\n<p style=\"padding-left: 40px;\">yum install rh-php72-php-fpm<\/p>\n<h2>Configure Apache<\/h2>\n<p>At this point PHP is not being executed by Apache. If you were to restart Apache it would simply return the text of the test.php file.<\/p>\n<p>We need to edit the httpd.conf so:<\/p>\n<p style=\"padding-left: 40px;\">nano \/opt\/rh\/httpd24\/root\/etc\/httpd\/conf\/httpd.conf<\/p>\n<p>In the VirtualHost add:<\/p>\n<p style=\"padding-left: 40px;\">ProxyPassMatch ^\/(.*\\.php)$ fcgi:\/\/127.0.0.1:9000\/srv\/www\/zoyinc\/$1<\/p>\n<p>You will note that &#8220;\/srv\/www\/zoyinc&#8221; is the root folder, or &#8220;DocumentRoot&#8221;, for this VirtualHost.<\/p>\n<p>For my config this resulted in:<\/p>\n<pre class=\"crayon:false;\">&lt;VirtualHost *:80&gt;<br \/>    <span style=\"background-color: #ffff00;\">ProxyPassMatch ^\/(.*\\.php)$ fcgi:\/\/127.0.0.1:9000\/srv\/www\/zoyinc\/$1<\/span><br \/>    ServerAdmin webmaster@zoyinc.com<br \/>    DocumentRoot \/srv\/www\/zoyinc<br \/>    ServerName www.zoyinc.com<br \/>    ServerAlias 192.168.204.38<br \/>    ServerAlias zoyinc.com<br \/>    ServerAlias www.cantabrian.co.nz<br \/>    ServerAlias cantabrian.co.nz<br \/>    ErrorLog logs\/www.zoyinc.com-error_log<br \/>    CustomLog logs\/www.zoyinc.com-access_log combined<br \/>    <span style=\"background-color: #ffff00;\">DirectoryIndex index.php<\/span><\/pre>\n<p>Note the addition of &#8220;DirectoryIndex index.php&#8221;. This is very important for WordPress in particular.<\/p>\n<p>You need to make the same change for the Apache ssl config:<\/p>\n<p style=\"padding-left: 40px;\">nano \/opt\/rh\/httpd24\/root\/etc\/httpd\/conf.d\/ssl.conf<\/p>\n<p>So the ssl.conf should have a VirtualHost similar to:<\/p>\n<pre class=\"crayon:false;\">&lt;VirtualHost _default_:443&gt;<br \/>    <span style=\"background-color: #ffff00;\">ProxyPassMatch ^\/(.*\\.php)$ fcgi:\/\/127.0.0.1:9000\/srv\/www\/zoyinc\/$1<\/span><br \/>    ServerAdmin webmaster@zoyinc.com<br \/>    DocumentRoot \/srv\/www\/zoyinc<br \/>    ServerName www.zoyinc.com<br \/>    ServerAlias wordpress<br \/>    ServerAlias 192.168.204.38<br \/>    ServerAlias zoyinc.com<br \/>    ServerAlias www.cantabrian.co.nz<br \/>    ServerAlias cantabrian.co.nz<br \/>    ErrorLog logs\/www.zoyinc.com-error_log<br \/>    CustomLog logs\/www.zoyinc.com-access_log combined<br \/>    <span style=\"background-color: #ffff00;\">DirectoryIndex index.php<\/span><\/pre>\n<p>We now need to enable and then start the fpm service:<\/p>\n<p style=\"padding-left: 40px;\">systemctl enable rh-php72-php-fpm.service<br \/>service rh-php72-php-fpm start<\/p>\n<p>Finally restart Apache:<\/p>\n<p style=\"padding-left: 40px;\">service httpd24-httpd restart<\/p>\n<h3>Alternative Apache changes<\/h3>\n<p>I had a similar problem with MythWeb which is the web based frontend for MythTV. This also runs on PHP. However in this case I had it running under &#8220;\/mysthweb&#8221; not at the root.<\/p>\n<p>My changes were to:<\/p>\n<p>\/opt\/rh\/httpd24\/root\/etc\/httpd\/conf.d\/mythweb.conf<\/p>\n<pre class=\"crayon:false; \"># \nAlias \/mythweb \"\/usr\/share\/mythweb\" <br \/><span style=\"background-color: #ffff00;\">ProxyPassMatch \"^\/mythweb\/.*\\.php(\/.*)?$\" \"fcgi:\/\/127.0.0.1:9000\/usr\/share\/\" enablereuse=on<\/span><br \/>&lt;Directory \"\/usr\/share\/mythweb\"&gt;<br \/>    &lt;IfModule mod_authz_core.c&gt;<\/pre>\n<p>Unfortunately this broke MythWeb and it transpires this was because the sections under &#8220;Directory ..&#8221; were not recognized specifically the section:<\/p>\n<pre class=\"crayon:false; \">&lt;Files mythweb.*&gt;\n#<br \/># Use the following environment ...<br \/># look to connect to the databa ...<br \/># the authentication info to us ...<br \/># fine unless you've changed my ...<br \/># a different server from your  ...<br \/>#<br \/>    setenv db_server \"localhost\"<br \/>    setenv db_name \"mythconverg\"<br \/>    setenv db_login \"mythtv\"<br \/>    setenv db_password \"secret DB password\"<\/pre>\n<p>I had to move the setenv commands about &#8220;&lt;Directory&#8230;&#8221; and then mythweb worked again.<\/p>\n<p>During this exercise I found another option that also worked for mythweb and didn&#8217;t involve ProxyPass and DIDN&#8217;T involve moving the setenv commands:<\/p>\n<pre class=\"crayon:false;\">#<br \/>Alias \/mythweb \"\/usr\/share\/mythweb\"<br \/>&lt;Directory \"\/usr\/share\/mythweb\"&gt;<br \/>    <span style=\"background-color: #ffff00;\">Require all granted<\/span><br \/><span style=\"background-color: #ffff00;\">    RewriteEngine On<\/span><br \/><span style=\"background-color: #ffff00;\">    RewriteCond %{REQUEST_FILENAME} ^\/((.*\\.php)(\/.*)?)$<\/span><br \/><span style=\"background-color: #ffff00;\">    RewriteCond %2 -f<\/span><br \/><span style=\"background-color: #ffff00;\">    RewriteRule . fcgi:\/\/127.0.0.1:9000\/%1 [L,P]<\/span><br \/><span style=\"background-color: #ffff00;\">    RewriteOptions Inherit<\/span><br \/>    &lt;IfModule mod_authz_core.c&gt;<\/pre>\n<p>This also seemed to work quite well. This was found at: <a  href=\"https:\/\/serverfault.com\/questions\/633096\/php-htaccess-environment-variables-php-fpm-mod-proxy-fcgi-apache-2-4\">https:\/\/serverfault.com\/questions\/633096\/php-htaccess-environment-variables-php-fpm-mod-proxy-fcgi-apache-2-4<\/a>\u00a0 from user134840.<\/p>\n<h2>Misc<\/h2>\n<p>Log folder:<br \/>\/var\/opt\/rh\/rh-php72\/log\/php-fpm<\/p>\n\n\n\n<p><span class=\"error\"><span class=\"screen-reader-text\">Err<\/span><\/span><\/p>\n\n\n","protected":false},"excerpt":{"rendered":"<p>Err<\/p>\n","protected":false},"author":2,"featured_media":4305,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[553,552,10],"tags":[305,555,643,644,558,295,251,554,6,642,94,560,160,297],"class_list":["post-4274","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-centos","category-redhat","category-wordpress","tag-apache","tag-centos","tag-curl","tag-error-2","tag-install","tag-linux","tag-php","tag-red-hat","tag-redhat","tag-rhel","tag-setup","tag-software-collections","tag-upgrade","tag-wordpress"],"_links":{"self":[{"href":"http:\/\/www.zoyinc.com\/index.php?rest_route=\/wp\/v2\/posts\/4274","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.zoyinc.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.zoyinc.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.zoyinc.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.zoyinc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4274"}],"version-history":[{"count":37,"href":"http:\/\/www.zoyinc.com\/index.php?rest_route=\/wp\/v2\/posts\/4274\/revisions"}],"predecessor-version":[{"id":4328,"href":"http:\/\/www.zoyinc.com\/index.php?rest_route=\/wp\/v2\/posts\/4274\/revisions\/4328"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.zoyinc.com\/index.php?rest_route=\/wp\/v2\/media\/4305"}],"wp:attachment":[{"href":"http:\/\/www.zoyinc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4274"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.zoyinc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4274"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.zoyinc.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4274"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}