Conexão PHP com o PostgreSQL (e o MySQL) no CentOS 7

Após a instalação do PHP, PostgreSQL e MySQL no CentOS 7, ao tentar fazer um simples teste de conexão do PHP com o PostgreSQL, estava recebendo a seguinte mensagem de erro:

Warning: pg_connect(): Unable to connect to PostgreSQL server: could not connect to server: Permission denied Is the server running on host “localhost” (127.0.0.1) and accepting TCP/IP connections on port 5432?

O código de teste foi o seguinte:

<?php

 $casa = "localhost";
 $banco = "nome_do_banco";
 $porta = 5432;
 $usuario = "nome_do_usuario";
 $senha = "senha_do_usuario";

 $conexao = pg_connect("host=$casa dbname=$banco port=$porta user=$usuario password=$senha");

 if (! $conexao ) {
 print "<h3>Não foi possível conectar ao PostgreSQL.</h3><br />";
 pg_errormessage();
 } else {
 pg_close($conexao);
 print "<h3>Conexão OK.</h3>";
 }

?>

Eu já tinha ajustado as configurações do pg_hba.conf e postgresql.conf e, mesmo assim, o PHP não conseguia estabelecer uma conexão com o PostgreSQL. Por segurança, chequei as regras do firewall e estavam todas corretas também.

Aí me lembrei: o SELinux! Será que o SELinux estaria bloqueando por padrão as conexões ao banco de dados? Bem, o comando abaixo (como root) retorna as configurações do SELinux para os servidores web:

# getsebool -a | grep httpd
httpd_anon_write --> off
httpd_builtin_scripting --> on
httpd_can_check_spam --> off
httpd_can_connect_ftp --> off
httpd_can_connect_ldap --> off
httpd_can_connect_mythtv --> off
httpd_can_connect_zabbix --> off
httpd_can_network_connect --> off
httpd_can_network_connect_cobbler --> off
httpd_can_network_connect_db --> off
httpd_can_network_memcache --> off
httpd_can_network_relay --> off
httpd_can_sendmail --> off
httpd_dbus_avahi --> off
httpd_dbus_sssd --> off
httpd_dontaudit_search_dirs --> off
httpd_enable_cgi --> on
httpd_enable_ftp_server --> off
httpd_enable_homedirs --> off
httpd_execmem --> off
httpd_graceful_shutdown --> on
httpd_manage_ipa --> off
httpd_mod_auth_ntlm_winbind --> off
httpd_mod_auth_pam --> off
httpd_read_user_content --> off
httpd_run_preupgrade --> off
httpd_run_stickshift --> off
httpd_serve_cobbler_files --> off
httpd_setrlimit --> off
httpd_ssi_exec --> off
httpd_sys_script_anon_write --> off
httpd_tmp_exec --> off
httpd_tty_comm --> off
httpd_unified --> off
httpd_use_cifs --> off
httpd_use_fusefs --> off
httpd_use_gpg --> off
httpd_use_nfs --> off
httpd_use_openstack --> off
httpd_use_sasl --> off
httpd_verify_dns --> off

Pronto, identificamos o problema! A propriedade httpd_can_network_connect_db está em “off” (e a httpd_can_network_connect também) e o SELinux está impedindo a conexão do PHP com o PostgreSQL. Para permitir que o SELinux deixe o PHP se conectar ao PostgreSQL (e ao MySQL), faça o seguinte (como root):

setsebool -P httpd_can_network_connect_db on
setsebool -P httpd_can_network_connect on

Agora o Apache/PHP já consegue se conectar aos bancos de dados!

953 thoughts on “Conexão PHP com o PostgreSQL (e o MySQL) no CentOS 7”

  1. Pingback: adam eve deal
  2. Pingback: adam and eve code
  3. Pingback: Brazilian Hair
  4. Pingback: porn movie
  5. Pingback: porn movie
  6. Pingback: hacking services
  7. Pingback: prediksi bola
  8. Pingback: vibrator
  9. Pingback: Lovehoney
  10. Pingback: the bullet toy
  11. Pingback: kona coffee beans
  12. Pingback: polidomes
  13. Pingback: Email Archiving
  14. Pingback: vibrator
  15. Pingback: best kona coffee
  16. Pingback: lion coffee
  17. Pingback: kegel sex exercise
  18. Pingback: realistic dildo
  19. Pingback: oral sex kit
  20. Pingback: mini hitachi wand
  21. Pingback: mini vibrator sex
  22. Pingback: development
  23. Pingback: adidas官網
  24. Pingback: vibe vibrator
  25. Pingback: Xvideo
  26. Pingback: loja de bebe
  27. Pingback: stockings
  28. Pingback: icicles toys
  29. Pingback: sex toy review
  30. Pingback: Strapons
  31. Pingback: new cryptocurrency
  32. Pingback: kona coffee
  33. Pingback: MSP airport Limo
  34. Pingback: cock ring
  35. Pingback: seo marketing
  36. Pingback: grip tape
  37. Pingback: adult sex toys
  38. Pingback: bullet vibrators
  39. Pingback: top best sex toys
  40. Pingback: Sripatum
  41. Pingback: g spot sex toy
  42. Pingback: sex lube for women
  43. Pingback: RMUTT
  44. Pingback: bondage sex
  45. Pingback: nipple vacuum
  46. Pingback: senegal qatar
  47. Pingback: how to make money
  48. Pingback: Ripoff Report
  49. Pingback: SEO 2018
  50. Pingback: bead vibrator
  51. Pingback: Emperor 7
  52. Pingback: auto injuries
  53. Pingback: really big dildo
  54. Pingback: pc app
  55. Pingback: anal sex vibrator
  56. Pingback: buy and sell
  57. Pingback: sex movie
  58. Pingback: leather strap on
  59. Pingback: mumbai police
  60. Pingback: best vibrator
  61. Pingback: Best Anal Plug
  62. Pingback: clit tickler
  63. Pingback: best kona coffee
  64. Pingback: wand massagers
  65. Pingback: Orlando SEO agency
  66. Pingback: Cracked phone
  67. Pingback: Top dildos
  68. Pingback: vibrating ring use
  69. Pingback: anal vibrator
  70. Pingback: clitoral vibrator
  71. Pingback: Page
  72. Pingback: rhalyns
  73. Pingback: lube for anal sex
  74. Pingback: Penis Extension
  75. Pingback: Less Of Tour
  76. Pingback: water damage
  77. Pingback: vibe rabbit
  78. Pingback: خرید هاست
  79. Pingback: 海美迪
  80. Pingback: 美容外科
  81. Pingback: 100% kona coffee
  82. Pingback: womens clothes
  83. Pingback: his explanation
  84. Pingback: Homepage
  85. Pingback: forex promotions
  86. Pingback: Hariyanvi Song
  87. Pingback: 90's hits
  88. Pingback: 90's R&B
  89. Pingback: Buy Jackets Online
  90. Pingback: خرید vpn
  91. Pingback: Kona Co
  92. Pingback: 100% K coffee
  93. Pingback: vegas packages
  94. Pingback: خدمات سئو
  95. Pingback: best coffee beans
  96. Pingback: خرید vpn
  97. Pingback: خرید vpn
  98. Pingback: 100 kona coffee
  99. Pingback: china logistics
  100. Pingback: coffee machines
  101. Pingback: خرید vpn
  102. Pingback: خرید کریو
  103. Pingback: here
  104. Pingback: خرید vpn
  105. Pingback: persian rugs
  106. Pingback: خرید vpn
  107. Pingback: tam
  108. Pingback: خرید vpn
  109. Pingback: خرید vpn
  110. Pingback: Rbxtrading
  111. Pingback: amazon all offers
  112. Pingback: möbler
  113. Pingback: termeh
  114. Pingback: free games to play
  115. Pingback: گوگل adwords
  116. Pingback: Belize inn
  117. Pingback: گوگل adwords
  118. Pingback: گوگل adwords
  119. Pingback: 脱毛
  120. Pingback: vpn
  121. Pingback: گوگل adwords
  122. Pingback: ile maurice design
  123. Pingback: gymshark
  124. Pingback: گوگل adwords
  125. Pingback: novin marketing
  126. Pingback: persian tar
  127. Pingback: resume
  128. Pingback: گوگل adwords
  129. Pingback: خرید vpn
  130. Pingback: سیستم cctv
  131. Pingback: خرید vpn
  132. Pingback: خرید vpn
  133. Pingback: سیستم cctv
  134. Pingback: خرید vpn
  135. Pingback: سیستم cctv
  136. Pingback: zand game
  137. Pingback: خرید vpn
  138. Pingback: سیستم cctv
  139. Pingback: خرید طلا
  140. Pingback: Global Geeks
  141. Pingback: خرید طلا
  142. Pingback: سیستم cctv
  143. Pingback: خرید vpn
  144. Pingback: 100 kona coffee
  145. Pingback: خرید vpn
  146. Pingback: gratis inserieren
  147. Pingback: nipple play
  148. Pingback: سیستم cctv
  149. Pingback: خرید vpn
  150. Pingback: hp printer drivers
  151. Pingback: kinky sex toy
  152. Pingback: sex toy review
  153. Pingback: blanket
  154. Pingback: home
  155. Pingback: credit report
  156. Pingback: the rabbit toy
  157. Pingback: nipple chains
  158. Pingback: monster dong
  159. Pingback: خرید طلا
  160. Pingback: ebook encounter
  161. Pingback: خرید vpn
  162. Pingback: خرید طلا
  163. Pingback: huge dildos
  164. Pingback: king cock
  165. Pingback: Fülöp Henrik
  166. Pingback: سیستم cctv
  167. Pingback: check out here
  168. Pingback: TripAdvisor
  169. Pingback: خرید vpn
  170. Pingback: womanizer sex toy
  171. Pingback: dildo coupons
  172. Pingback: anal
  173. Pingback: realistic dildo
  174. Pingback: خرید طلا
  175. Pingback: lube sex
  176. Pingback: sex toy butterfly
  177. Pingback: hp drivers
  178. Pingback: سیستم cctv
  179. Pingback: hydroquinone
  180. Pingback: ad boards
  181. Pingback: cockrings
  182. Pingback: best herbal tea
  183. Pingback: clit sex toys
  184. Pingback: Simeon Yahweh
  185. Pingback: bahis siteleri
  186. Pingback: kona coffee beans
  187. Pingback: miniclip
  188. Pingback: bahis siteleri
  189. Pingback: bet online
  190. Pingback: ak yazılı
  191. Pingback: bahis siteleri
  192. Pingback: bahis siteleri
  193. Pingback: bahis siteleri
  194. Pingback: bahis siteleri
  195. Pingback: bahis siteleri
  196. Pingback: goldenbah's
  197. Pingback: penis size
  198. Pingback: Corduroy Jackets
  199. Pingback: bondage -bitcoin
  200. Pingback: finger clit
  201. Pingback: apartamenti varna
  202. Pingback: clash royale hack
  203. Pingback: adam and eve toys
  204. Pingback: Free php scriptp
  205. Pingback: Makrill
  206. Pingback: pegging couple
  207. Pingback: solgar
  208. Pingback: how to use a dildo
  209. Pingback: matka result
  210. Pingback: jageze
  211. Pingback: dating
  212. Pingback: Get free backlinks
  213. Pingback: dental treatments
  214. Pingback: lender
  215. Pingback: garudaqq android
  216. Pingback: clean
  217. Pingback: powh
  218. Pingback: Tatuaje Chile
  219. Pingback: Tablet Repairs
  220. Pingback: Instagram unfollow
  221. Pingback: psychic
  222. Pingback: Computer City
  223. Pingback: Montreal Escorts
  224. Pingback: Africans online
  225. Pingback: gps tracker
  226. Pingback: vse pesni
  227. Pingback: youtube downloader
  228. Pingback: first sex toy
  229. Pingback: golf rankings
  230. Pingback: prayer
  231. Pingback: brazilian hair
  232. Pingback: sexuality
  233. Pingback: remy hair
  234. Pingback: lesbian
  235. Pingback: malaysian hair
  236. Pingback: sexier heat up
  237. Pingback: peruvian hair
  238. Pingback: Bitcoin
  239. Pingback: Sleeveless Dress
  240. Pingback: fantasy novel
  241. Pingback: suction cup dildo
  242. Pingback: travel tips
  243. Pingback: kakoy prazdnik
  244. Pingback: equations
  245. Pingback: pubg shop
  246. Pingback: A to Z
  247. Pingback: men pocket pussy
  248. Pingback: faith movies
  249. Pingback: sportotobet
  250. Pingback: Hydroquinone
  251. Pingback: Hydroquinone
  252. Pingback: Chegg login
  253. Pingback: خرید vpn
  254. Pingback: mermaid videos
  255. Pingback: Las Vegas Escorts
  256. Pingback: web design dundee
  257. Pingback: realistic vibrator
  258. Pingback: Womanizer
  259. Pingback: Master
  260. Pingback: lyrics free
  261. Pingback: Americab.net
  262. Pingback: CARAT SIZE
  263. Pingback: Sports news
  264. Pingback: trah_net_621
  265. Pingback: digital marketing
  266. Pingback: anal training kit
  267. Pingback: huge dick
  268. Pingback: Fight With Deny
  269. Pingback: Rabbit Vibrator
  270. Pingback: kegel balls
  271. Pingback: superpump
  272. Pingback: double ended dildo
  273. Pingback: g spot vibrator
  274. Pingback: Kickstarter
  275. Pingback: film
  276. Pingback: g spot vibrator
  277. Pingback: cheap sex toys
  278. Pingback: Wet Wabbit
  279. Pingback: male sex toys
  280. Pingback: lovehoney
  281. Pingback: fitness trends
  282. Pingback: strapon sex
  283. Pingback: free images
  284. Pingback: here
  285. Pingback: 6 sentyabrya 7593
  286. Pingback: DraftKings NFL
  287. Pingback: last longer in bed
  288. Pingback: Tire Pressure
  289. Pingback: friv
  290. Pingback: Painting Brisbane
  291. Pingback: stim machine
  292. Pingback: NBA DFS
  293. Pingback: College Basketball
  294. Pingback: College Football
  295. Pingback: rabbit dildo
  296. Pingback: DraftKings NBA
  297. Pingback: quizhow
  298. Pingback: سكس
  299. Pingback: Nude cams
  300. Pingback: zavtra prazdnik
  301. Pingback: aflamsex
  302. Pingback: Cryto curency
  303. Pingback: german rottweiler
  304. Pingback: Live cams
  305. Pingback: Funny videos
  306. Pingback: Live sex
  307. Pingback: Jumpstar car
  308. Pingback: read article
  309. Pingback: Sex girls live
  310. Pingback: lesbian sex
  311. Pingback: Freexxx
  312. Pingback: Porno videos
  313. Pingback: Shemale cams
  314. Pingback: Hot babe
  315. Pingback: Iphone deal
  316. Pingback: Cheap iphone case
  317. Pingback: best clit massager
  318. Pingback: Iphone 7 case
  319. Pingback: سكس
  320. Pingback: سكس مترجم
  321. Pingback: strapon
  322. Pingback: Massager
  323. Pingback: the best vibrators
  324. Pingback: anal plugs
  325. Pingback: سكس
  326. Pingback: سكس مترجم
  327. Pingback: MILF
  328. Pingback: 2018 NFL Schedule
  329. Pingback: Garo Kassabian
  330. Pingback: custom
  331. Pingback: kakie prazdnik
  332. Pingback: hacker affidabile
  333. Pingback: lesbian massager
  334. Pingback: mp3 songs
  335. Pingback: lesbian dildo
  336. Pingback: aflampornhd
  337. Pingback: Musicpleer
  338. Pingback: click here
  339. Pingback: click to see more
  340. Pingback: page address
  341. Pingback: visit the page
  342. Pingback: tounge vibrators
  343. Pingback: butterfly vibrator
  344. Pingback: address
  345. Pingback: egg vibrators
  346. Pingback: view more
  347. Pingback: click to see more
  348. Pingback: best lube
  349. Pingback: funny sex
  350. Pingback: chicago house dj
  351. Pingback: Best Anal Vibrator
  352. Pingback: Best Sex Lubricant
  353. Pingback: vaginal tightening
  354. Pingback: poker88
  355. Pingback: best glass dildo
  356. Pingback: sex toy tutorial
  357. Pingback: MILF Porn
  358. Pingback: mp3juices
  359. Pingback: best male stroker
  360. Pingback: tubidy
  361. Pingback: writeaessay
  362. Pingback: ebooks for resale
  363. Pingback: powerful vibrator
  364. Pingback: Buy cialis
  365. Pingback: g spot stimulators
  366. Pingback: Buy cialis
  367. Pingback: adam and eve shop
  368. Pingback: forum znakovstv
  369. Pingback: netflix free
  370. Pingback: iPhone 6 Charger
  371. Pingback: Iphone charger
  372. Pingback: Samsung
  373. Pingback: golfing equipment
  374. Pingback: Generic cialis
  375. Pingback: best blowjob
  376. Pingback: notehub.org
  377. Pingback: read an article
  378. Pingback: هپاش
  379. Pingback: pc games download
  380. Pingback: notehub.org
  381. Pingback: submissive sex
  382. Pingback: visit the source
  383. Pingback: a source
  384. Pingback: this web page
  385. Pingback: segodnya prazdnik
  386. Pingback: notehub.org
  387. Pingback: boston amazon
  388. Pingback: new free games
  389. Pingback: Apple sell
  390. Pingback: سئو سایت
  391. Pingback: butt plug trainer
  392. Pingback: male masturbators
  393. Pingback: auto taxi
  394. Pingback: bullet sex toy
  395. Pingback: twisting vibrator
  396. Pingback: Verbuchen
  397. Pingback: pure coffee
  398. Pingback: malydomeczek
  399. Pingback: interracial porn
  400. Pingback: Freemason Ring
  401. Pingback: Baby Highchair
  402. Pingback: Magnetic Stir Bar
  403. Pingback: realestate
  404. Pingback: strapon female
  405. Pingback: the accomidator
  406. Pingback: Best Magic Wand
  407. Pingback: Penis Pump
  408. Pingback: Anal Plug
  409. Pingback: stimulation gel
  410. Pingback: slovari sinonimov
  411. Pingback: iPad wholesale
  412. Pingback: notehub.org go
  413. Pingback: notehub.org
  414. Pingback: notehub.org
  415. Pingback: read more
  416. Pingback: notehub.org source
  417. Pingback: notehub.org
  418. Pingback: online free course
  419. Pingback: a source
  420. Pingback: Huge Dildo
  421. Pingback: افلام سكس
  422. Pingback: Suction Cup Dildos
  423. Pingback: mp3 download
  424. Pingback: notehub.org
  425. Pingback: g spot porn
  426. Pingback: king cock
  427. Pingback: mega 2" extension
  428. Pingback: huge dildo review
  429. Pingback: xlxx porn
  430. Pingback: Bestecktaschen
  431. Pingback: Cheap Hosting
  432. Pingback: Kona coffee brands
  433. Pingback: Buy kona coffee
  434. Pingback: fulton bail bond
  435. Pingback: junk cars
  436. Pingback: lion coffee beans
  437. Pingback: buy lion coffee
  438. Pingback: buy lion coffee
  439. Pingback: aquarium supplies
  440. Pingback: Abraaj
  441. Pingback: buy hoverboard
  442. Pingback: Travel
  443. Pingback: hosting
  444. Pingback: buy kona coffee
  445. Pingback: hummer hoverboard
  446. Pingback: Cbd
  447. Pingback: beginners bondage
  448. Pingback: ninebot
  449. Pingback: Vanessa Lunnon
  450. Pingback: seo service
  451. Pingback: IT Support
  452. Pingback: free phone cases
  453. Pingback: 8188848400

Comments are closed.