postgresqlとPHPにて以下のような現象が起きています。
##設定手順について
OS:centOS7にて
Apache2.4.6を導入しました。
POstgresql9.2.23にてデータベース及びテーブルの作成を実施しました。
データベース名=testdb、user=sasaki、password=password
PHP5.4.16を導入しました。
php-pgsqlを導入しました。
/var/www/html/index2.phpに以下のソースを作成し
<?php phpinfo(); ?>
※Apache及びPHPが動作している事を確認しました。
##Apache+PHP+postgresqlの連携
/var/www/html/
index.phpのソース部分を追記しました。記述を以下のようにしていたところ
5 $conn=pg_connect("host=127.0.0.1,port=5432,dbname=testdb,user=sasaki,password=password");
以下のエラーが発生しました。
■エラー1■
Warning: pg_connect():
Unable to connect to PostgreSQL server:
could not translate host name "127.0.0.1," to address:
Name or service not known in /var/www/html/index.php on line 5
database not found
翻訳
警告:pg_connect():
PostgreSQLサーバに接続できません:
ホスト名 "127.0.0.1"を次のアドレスに変換できませんでした:
/var/www/html/index.php 5行目で知られていない名前またはサービス
データベースが見つかりません
##修正手順1
当初はデータベースの接続ができてないと思いましたが
調べるとpg_connect関数のデータベース指定はカンマ区切りではなく
半角スペース区切りだと言うことが調査して分かりました。
index.phpのソース部分の記述を以下のよう変更しました。
5 $conn=pg_connect("host=127.0.0.1 port=5432 dbname=testdb user=sasaki password=password");
以下のエラーが発生しました。
エラー内容が変わりましたので上記エラーは解決したと判断しました。
■エラー2■
Warning: pg_connect():
Unable to connect to PostgreSQL server:
could not connect to server: Permission denied Is the server running on host "127.0.0.1"
and accepting TCP/IP connections on port 5432? in /var/www/html/index.php on line 5
database not found
翻訳
警告:pg_connect():
PostgreSQLサーバに接続できません:
サーバーに接続できませんでした:アクセスが拒否されましたサーバーがホスト "127.0.0.1"
ポート5432でTCP / IP接続を受け入れる? /var/www/html/index.php on line 5
データベースが見つかりません
##修正手順2
1./var/lib/pgsql/data/postgresql.confのコメントアウト部分を削除しました。
コメント部分port=5432
を
port=5432
に修正しました。
2.又、以下のファイルも追記しました。/var/lib/pgsql/data/pg_hba.conf
IPv4 local connections:
host testdb sasaki 127.0.0.1/32 md5
3.ファイアウォールのポートを開放
firewall-cmd --permanent --add-service=postgresql firewall-cmd --permanent --add-port=5432/tcp firewall-cmd --reload firewall-cmd --list-all systemctl restart firewalld
としましたが「修正手順1の■エラー2」のエラーまだ発生します。
ここで今の所詰まっています。
ご助言よろしくお願いいたします。
seteonforce=0にすることで解決致しました。
ご回答された方々有難うございました。
また補足ですが
vi /etc/selinux/config
の
SELINUX=disabled
にする事で再起動しても問題なく起動致しました。
回答3件
あなたの回答
tips
プレビュー