• ベストアンサー

Internal Server Error になってしまいます。

とある書籍を元にperlを学んでいます。まだ初心者で少々わかりずらい質問になってしまっているかもしれませんが、よろしくお願いします。 下記のコードがある事で Internal Server Error になってしまいます。 open(FILE,">>$logfile") or die("エラー:ログファイルが開けませんでした。"); $logfileの変数値には本日の日付 + .dat が入ります。 自分なりにいろいろ原因を探してみて、$logfileの変数値と同名のファイルをあらかじめ用意してやればエラーにはならない事がわかりました。 それから >> と書けば「対象ファイルが存在しない場合は新規作成される」と書籍には説明があるのですが、新規ファイルは作成されていませんが、>>はそのような動作にはならないものなのでしょうか? それから、or die 以降を削除してしまえば エラーは起きませんでした。 上記コードがあるとなぜ Internal Server Error になってしまうのでしょうか? アドバイスやご教授をよろしくお願いします。

  • CGI
  • 回答数2
  • ありがとう数2

質問者が選んだベストアンサー

  • ベストアンサー
  • maura
  • ベストアンサー率46% (48/104)
回答No.2

ディレクトリィには書き込み権限と言うのがあります。 書き込み権限には、owner、group、otherがあり otherに書き込み権限が無いとWebから実行しても ファイルは作成出来ない場合があります。 ”同名のファイルをあらかじめ用意”とありますが これの書き込み権限には、otherに書き込み権限があったんでは ないのでしょうか?

thank001
質問者

お礼

mauraさん、書き込みありがとうございます。 ご指摘いただいた、フォルダのパーミッションの設定を 707 としotherにも書き込み権限を与える設定にしたところ、問題を解決する事ができました(^0^。 ありがとうございました。 大変助かりました。

その他の回答 (1)

  • leap_day
  • ベストアンサー率60% (338/561)
回答No.1

こんにちは 試してみたのですがエラーにはなりませんでした open(FILE,">>log.txt") or die("エラー:ログファイルが開けませんでした。"); とするとメモ帳アイコンで「log.txt」が作られていました open(FILE,">>$logfile") or die("エラー:ログファイルが開けませんでした。"); または open(FILE,"log.txt") or die("エラー:ログファイルが開けませんでした。"); とすればor dieが利きプログラム終了して何も表示されませんでした どれか実行できるソースで<body>内にこの1行のみで試してみてください それでもエラーになります? ならないようなら$logfileの定義がおかしいか、別の箇所かと思います この1行の前に $logfile = "***.dat"; というのは入れていますよね?

thank001
質問者

お礼

leap_dayさん、書き込みありがとうございます。 no.2さんにご指摘いただいたパーミッションの設定で、問題を解決することができました。 leap_dayさんの書き込みも参考にさせていただきました。 ご教授いただきありがとうございました。

関連するQ&A

  • 500 Internal Server Error

    500 Internal Server Errorが出ます。 サーバ:CentOS6.4 サーバ側の文字コード:UTF-8 perlのパス:/usr/bin/perl index.cgiの文字コード:LF (サーバ上で直接作成) index.cgiのパーミッション:777 (パーミッションの問題を避けるためわざと、777に設定) ここで、サーバ上で直接実行 perl /var/www/html/index.cgi すると、正しく処理の結果が返ってきてエラーは出ません。 しかし、クライアントのブラウザでindex.cgiにアクセスすると、500 Internal Server Errorが出ます。 なお、index.cgiを設置するディレクトリはApacheで以下のように設定しcgiスクリプトを有効にしています。 <Directory “/var/www/html”> Options FollowSymLinks ExecCGI </Directory> AddHandler cgi-script .cgi .pl #AddDefaultCharset UTF-8 ******************************************************* 【/var/www/html/index.cgi】 #!/usr/bin/perl print "Content-type: text/html"; print "<html>"; print "<body>"; print "<p>"; print "CGI"; print "</p>"; print "</body>"; print "</html>"; スクリプトの文法に問題があれば、サーバ上で直接実行させた時点でエラーを吐きそうですし、 パーミッションは777にしていますし、Apacheの設定もcgiを有効にしているので 他に500 Internal Server Errorが出る原因が掴めません。 Apacheの設定で、#AddDefaultCharset UTF-8 として文字セットを無効にした場合は CGIスクリプトの方で何か追加してやらないと、文字化け以前の問題で必ず500 Internal Server Errorを吐くんですかね? ご指導のほどよろしくお願い致します。

    • ベストアンサー
    • CGI
  • 500 Internal Server Error

    http://iboard3.to/ で始まるURLのどのサイトでも 500 Internal Server Error Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request. Please contact the server administrator, info@iboard2.to and inform them of the time the error occurred, and anything you might have done that may have caused the error. More information about this error may be available in the server error log. と表示され、見ることができません。 どうしたらよいですか?

  • Internal Server Error

    Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request. 上記のメッセージがでます。シンタックチェックはOKです。パーミッションはcgiフォルダは:705 cgiファイルは:700 他のパーミッションも確認しています。-wオプションをつけてもそれ以上のものは表示しません。原因場所が判らないので仕方なく読み込んだところで表示するサブルーチンを設定し、原因場所を特定しようとしました。サブルーチンの部分が読み込まれ表示されれば、そこまでは正常と判る様にしてあります。しかし、プログラムの最初の部分においても、上記のエラーがでます。こういう時の原因を教えてください。

    • ベストアンサー
    • Perl
  • Internal Server Errorについて

    最近頻繁に下記のエラーが表示されます。 どういう原因が考えられますか? ----- Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request. Please contact the server administrator at root@itmidcgi.itmedia.jp to inform them of the time this error occurred, and the actions you performed just before this error. More information about this error may be available in the server error log. -----

  • Internal Server Errorって何で?!

    某ホームページのメール入力フォームからメールと画像データーを送ろうとしました。でも何回やってもInternal Server Errorと出て送れません。 Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request. Please contact the server administrator, *****@www.*****.co.jp and inform them of the time the error occurred, and anything you might have done that may have caused the error. More information about this error may be available in the server error log. と出てきます。なんで?!(*****は一応伏せました) それで画像データーをやめて、文字だけ送ったら送れました。でも画像を添付すると送れなくなるんです! 画像の上限は300kbyte以内なんですが、私の画像は172kbなんで大丈夫なはずなんです。ファイアーウォールも切ってみたんですが変わりありませんでした。

  • Internal Server Error???

    こんにちは。 CGIを作ったのですが、 【Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request. Please contact the server administrator, webmaster@life-web.com and inform them of the time the error occurred, and anything you might have done that may have caused the error. More information about this error may be available in the server error log. 】 と言うエラーが出て動きません. もう一つ同じようなcgiを作ったのですが、そちらは普通に動きます.すみませんが、このエラーの場合はどうしたらいいですか? CGIはメールフォームからのメールを送信するものです。

    • ベストアンサー
    • CGI
  • エラー処理について

    $fp = fopen($logfile, "r+") or die("File Open Error!\n"); 上記のコードの方法で、エラー文字の装飾をしたいです。 die関数が言語構造なので、やはりif else的な処理で分けechoなどで表示する方法しかないでしょうか? $fp = fopen($logfile, "r+") or die("<p><font size=7 color=#00ff00>File Open Error!</font></p>");

    • ベストアンサー
    • PHP
  • Internal Server Errorについて

    今まで閲覧できたサイトのページで、Internal Server Error が発生し突然閲覧できなくなりました。 詳細は以下になります。 Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request. Please contact the server administrator, webmaster@supercarsdubai.com and inform them of the time the error occurred, and anything you might have done that may have caused the error. More information about this error may be available in the server error log. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request. -------------------------------------------------------------------------------- Apache/1.3.41 Server at www.supercarsdubai.com Port 80 そのサイトのトップページは開くのですが、特定のページのみ開きません。ただ、そのサイトは、書き込みなどを行うフォームのサイトなのですが、閲覧できないページは更新されており、原因がサーバというよりは、自分側にあるのかと思っております。 Gooleなどで調べましたが、原因がまったくわからず困っております。 どなたか、詳しい方がいらっしゃいましたら、ご教授よろしくお願い致します。

  • Internal Server Errorについて

    いつもご丁寧なご回答本当にありがとうございます。 postmailをサーバーに転送し、メールの送信を試してみたところ下記のエラーが出てしまいました。 パーミッションの確認、センドメールのパス、CGIのパス、メールアドレスの確認もしましたが、間違っていないようです。 サーバーはセンドメール自作CGIが使えるサーバーです。 入力ソースのformもpostmail-cgiで記載しています。 良い、アドバイスがありましたら是非、宜しくお願いいたします。 Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request. Please contact the server administrator, info@stepserver.jp and inform them of the time the error occurred, and anything you might have done that may have caused the error. More information about this error may be available in the server error log. -------------------------------------------------------------------------------- Apache/1.3.41 Server at sss002.kix.ad.jp Port 443

    • 締切済み
    • CGI
  • 500 Internal Server Errorで見れなくなった

    はじめまして。 友人の会社のホームページの更新を頼まれて、ホームページを更新してアップロードしたら急に 「500 Internal Server Error」 となり、いろいろ英文でエラーが出てホームページが表示されません。 アップロード時に「log」関係のファイルについて「パーミッションがdeny~」のようなことが書かれていたので、「アップロード」しなかったのですが・・・ 原因と解決方法がわかる方はどうかよろしくお願いいたします。

専門家に質問してみよう