{"id":839,"date":"2024-03-20T16:38:39","date_gmt":"2024-03-21T00:38:39","guid":{"rendered":"https:\/\/www.raveloxprojects.com\/blog\/?p=839"},"modified":"2024-03-20T16:38:39","modified_gmt":"2024-03-21T00:38:39","slug":"getting-php-mysqli_connect-to-work-under-httpd","status":"publish","type":"post","link":"https:\/\/www.raveloxprojects.com\/blog\/?p=839","title":{"rendered":"Getting php mysqli_connect to work under httpd"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Documenting this because I know I&#8217;m going to forget it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I was playing around with some older PHP code in preparation for a new project and tried setting it up on Fedora 20.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Part of the code makes a connection to a MariaDB database and I kept getting a HTTP 500 error when I ran the code. If I ran it from the command line, it worked without a problem.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The error I was seeing was:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>PHP Fatal error:  Uncaught mysqli_sql_exception: Permission denied in \/var\/www\/html\/w\/php\/_database.php:5<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">It turns out that I&#8217;d forgotten selinux kicks in and prevents httpd from making outbound network connections. It&#8217;s actually logged in \/var\/log\/messages:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Mar 20 17:26:48 vmfedora setroubleshoot&#91;314730]: SELinux is preventing php-fpm from name_connect access on the tcp_socket port 3306.<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This can be remedied, if you still want selinux enabled, by doing the following:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>setsebool -P httpd_can_network_connect 1<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">I restarted httpd for good measure and now it&#8217;s working.<\/p>\n","protected":false},"excerpt":{"rendered":"<p> Documenting this because I know I&#8217;m going to forget it. I was playing around with some older PHP code in preparation for a new project and tried setting it up on Fedora 20. Part of the code makes a connection to a MariaDB database and I kept getting a HTTP 500 error when I ran &#8230; <a class=\"read-more meta-nav\" href=\"https:\/\/www.raveloxprojects.com\/blog\/?p=839\">Read more &raquo;<\/a><\/p>","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[47,36],"tags":[],"class_list":["post-839","post","type-post","status-publish","format-standard","hentry","category-linux","category-software"],"jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8tHuw-dx","jetpack_likes_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.raveloxprojects.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/839","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.raveloxprojects.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.raveloxprojects.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.raveloxprojects.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.raveloxprojects.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=839"}],"version-history":[{"count":1,"href":"https:\/\/www.raveloxprojects.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/839\/revisions"}],"predecessor-version":[{"id":840,"href":"https:\/\/www.raveloxprojects.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/839\/revisions\/840"}],"wp:attachment":[{"href":"https:\/\/www.raveloxprojects.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=839"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.raveloxprojects.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=839"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.raveloxprojects.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=839"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}