apacheにおいて、ブラウザにエラー画面が表示された場合
apacheにおいて、ブラウザにエラー画面が表示された場合
Forbidden You don't have permission to access /hoge/hoge.html on this server. Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request.
アパッチの実行ユーザ確認
まずは、設定ファイルから確認
# less /etc/httpd/conf/httpd.conf User apache Group apache
実際にプロセスを見て確認
# ps aux root 3632 0.0 1.5 8800 3836 ? Ss Jul11 0:00 /usr/sbin/httpd apache 13835 0.0 1.6 8940 4172 ? S 00:02 0:01 /usr/sbin/httpd .......
user apacheで動いていることがわかる
ちなみに、apacheのグループはapacheだけであることも確認
# groups apache apache : apache
ここで、ディレクトリのパーミッションを確認
該当するディレクトリは、apacheユーザが見れない権限であった
# ls -al /hoge/ drwxrws--- 8 hoge webmaster 4096 7月 13 09:56 hoge/
対応方法1
group webmasterに、ユーザapacheを追加する
# vi /etc/group webmaster:x:900:.....,apache # groups apache (アパッチユーザが所由するgroup) apache : apache webmaster [変更したので、アパッチの再起動が必要(gracefulでok) ] # /etc/rc.d/init.d/httpd graceful
[参考] /etc/groupはグループにどのユーザーが所属しているかを定義するファイル 1行に1エントリずつ書かれ、各行の形式は以下のとおりである。 group_name:passwd:GID:user_list groups [user] - [user]がもつ、現在のグループ名の表示
# /etc/rc.d/init.d/httpd graceful
< |
# chmod -R 775 hoge ls -al /hoge/ drwxrwxr-x 8 hoge webmaster 4096 7月 13 09:56 hoge/
php5
$ cd /usr/local/src $ tar xfvz php-5.2.3.tar.gz $ vi CONFIGURE.sh #!/bin/sh ./configure \ --prefix=/usr/local/php5 \ --with-apxs2=/usr/local/apache2/bin/apxs \ --enable-mbstring \ --enable-memory-limit \ --with-zlib \ --with-openssl \ $ sh CONFIGURE.sh $ make $ su # make install [カスタマイズ] # vi /usr/local/apache2/conf/httpd.conf LoadModule php5_module modules/libphp5.so AddType application/x-httpd-php .php .phtml....... # # For php # AddType application/x-httpd-php .php .phtml # /usr/local/apache2/bin/apachectl stop # /usr/local/apache2/bin/apachectl start # vi /usr/local/apache2/htdocs/info.php http://localhost:88/info.php [アンインストール方法] # /usr/local/src 配下を削除 # /usr/local/php5 を削除
apacheを別portで動かす
$ /usr/local/src $ tar xfvz httpd-2.2.4.tar.gz $ vi CONFIGURE.sh #!/bin/sh ./configure --prefix=/usr/local/apache2.2 \ --enable-so \ --enable-rewrite \ --enable-deflate \ --enable-dav=yes \ $ sh CONFIGURE.sh $ make $ su # make install # cd /usr/local/ # ln -s apache2.2/ apache2 [カスタマイズ] $ vi /usr/local/apache2/conf/httpd.conf Listen 88 [起動方法] # /usr/local/apache2/bin/apachectl start # /usr/local/apache2/bin/apachectl -k start # vi /usr/local/apache2/htdocs/index.html http://localhost:88/ [アンインストール方法] # /usr/local/src 配下を削除 # /usr/local/apach2 を削除 参考) http://httpd.apache.org/docs/2.2/ja/install.html
OS(Win)が起動しなくなる
PCを立ち上げても下記メッセージがでてOS(WinXP)が起動しなくなったが、
奇跡的にどうにかデータを保存した
=> 個人PCにおいても、データの二重化が必要と感じた
=> 設定はノートなどに保存したり、別サーバに保存したりすることが重要
=> メールは通常から、gmailをつかって、別途メールデータを保存する
データ量が多くなる場合を想定して、別アカウントも用意
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
「SMART Failure Predicated on Hard Disk 0 :
WARNING : Immedeately back-up your data and replace your
hard disk drive. A failure may be imminent.
Press F1 to Continue
> ハードディスクが物理的に逝っている
> 本当なら、Windowsを起動させることさえ避けたほうが賢明
> ましてや、Scandiskなんかしたらとどめを刺すことになる
http://win98.pasokoma.jp/3_lg139
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
【経緯】
DVD shrinkにて、保存後、自動でシャットダウンにした為、
強制的にシャットダウンされ、ハードディスクがおかしくなった
=> ハードディスクのエラーチェック、デフラグをおこなったら、
致命的になり、起動しなくなった
【現象】
自分の場合、F1を押しても起動しなかった
【対応履歴】
破損しているHDDドライブをPC本体からはずし、「IDE/シリアルATA USB変換ケーブル」
HDDドライブをUSB経由で見れるようにするツールをつかって、直接ファイルを参照しよう
としたが、うまくいかない
再度、破損しているHDDドライブをPC本体につないで、起動を試みると、なぜかXPが起動した
なお、起動時間が通常より、大幅にかかってしまう。
(全体的に、もっさりとしている)
Cドライブすべて、バックアップしようとしたが、ブルーウインドウになり、そのまま、停止した
また、起動しようとしたが、立ち上がらなくなる
再度、破損しているHDDドライブをPC本体からはずし、「IDE/シリアルATA USB変換ケーブル」
をつかって、直接ファイルを参照しようとしてから、破損しているHDDドライブをPC本体に
つないで、起動する。
うかつに、破損領域にさわらないように、停止できる常駐ソフトを停止する
重用度の高い順に、外付けハードディスクに保存する
1 メール設定情報(ID,アカウント)
2 FTP設定情報(ID,アカウント)
3 全メールデータ
=> メーラがBeckyの場合は、c:\Becky以下
4 個人のデータ領域
C:\Documents and Settings\User
5 mp3、wmv領域
6 ディスクトップ領域
DVD shrinkにて、保存後、自動でシャットダウンにした為、
その領域は触れないようにする。(ふれるとしても、一番最後に触れる)
php curl sampleプログラム
<?php class curl { var $id = null; var $pw = null; var $url = null; var $fieldsdata = null; var $_result = array(); var $response_code = null; function set_id($id) { $this->id = $id; } function set_pw($pw) { $this->pw = $pw; } function set_url($url) { $this->url = $url; } var $proxy; function set_proxy($proxy) { $this->proxy = $proxy; } var $proxyport; function set_proxyport($proxyport) { $this->proxyport = $proxyport; } function get_url() { return $this->url; } function set_fieldsdata($value) { $this->fieldsdata = $value; } function get_fieldsdata() { return $this->fieldsdata; } function get_result() { return $this->_result; } function do_connect() { $ch = curl_init(); curl_setopt ($ch, CURLOPT_URL, $this->url); curl_setopt ($ch, CURLOPT_HEADER, 1); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_TIMEOUT, 30); curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, false); if($this->proxy) { curl_setopt($ch, CURLOPT_PROXY,$this->proxy); } if($this->proxyport) { curl_setopt($ch, CURLOPT_PROXYPORT,$this->proxyport); } if ($this->fieldsdata) { curl_setopt ($ch, CURLOPT_POST, 1); curl_setopt ($ch, CURLOPT_POSTFIELDS, $this->fieldsdata); } if (!is_null($this->id) && !is_null($this->pw)) { curl_setopt ($ch, CURLOPT_USERPWD, "{$this->id}:{$this->pw}"); } $result = curl_exec ($ch); curl_close ($ch); list($header, $response) = split("(\r\n){2}",$result, 2); $this->_result = $response; $headerline = split("\n",$header); for ($i=0; $i<count($headerline); $i++) { if (ereg("^HTTP", $headerline[$i])) { $headerline[$i] = trim($headerline[$i]); $httpflag = split(" ",$headerline[$i],3); if (!$this->_is_http_200($httpflag)) { return false; } } } return true; } function _is_http_200($httpflag) { $this->set_response_code($httpflag[1]); if (($httpflag[1] == "200") && ($httpflag[2] == "OK")) { return true; } else { return false; } } function set_response_code($code) { $this->response_code = $code; } function get_response_code() { return $this->response_code; } } require_once "curl_ssl.class.php"; $o = new curl; $o->set_url("https://www.hoge.hoge/index.html"); $o->set_id("user"); $o->set_pw("password"); $o->set_proxy("http://proxy.hoge.com:8080"); $o->set_proxyport("8080"); $o->do_connect(); print $response_code = $o->get_response_code(); print $contents = $o->get_result(); ?>
php ldap アクセスサンプルプログラム
<?php // -*- mode:PHP; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*- class LdapAccess { var $hostname = NULL; var $port = NULL; var $ldap_set_option_option = NULL; var $ldap_set_option_newval = NULL; var $link_id = NULL; var $search_result = NULL; // hostnameを設定する。 function setHostname($hostname) { $this->hostname = $hostname; } // portを設定する。 function setPort($port) { $this->port = $port; } function connect_start(){ if(!($this->wrapper_ldap_connect())) { return false; } else if(!($this->wrapper_ldap_set_option())) { return false; } else if(!($this->wrapper_ldap_bind())) { return false; } else { return true; } } // LDAP 接続 function wrapper_ldap_connect() { $this->link_id = ldap_connect($this->hostname,$this->port); if(!$this->link_id) { return false; } else { return true; } } function wrapper_ldap_errno() { return ldap_errno($this->link_id); } function wrapper_ldap_error() { return ldap_error($this->link_id); } function wrapper_ldap_set_option() { return ldap_set_option($this->link_id,$this->ldap_set_option_option,$this->ldap_set_option_newval); } //ldap_set_optionのoptionを設定する。 function setLdap_set_option_option($option) { $this->ldap_set_option_option = $option; } //ldap_set_optionのnewvalを設定する。 function setLdap_set_option_newval($newval) { $this->ldap_set_option_newval = $newval; } // bind_rdnを設定する。 function setBind_rdn($bind_rdn) { $this->bind_rdn = $bind_rdn; } // bind_passwordを設定する。 function setBind_password($bind_password) { $this->bind_password = $bind_password; } //ldap_bind -- LDAP ディレクトリにバインドする function wrapper_ldap_bind() { return ldap_bind($this->link_id,$this->bind_rdn,$this->bind_password); } function wrapper_ldap_search($base_dn,$filter,$justthese=null) { if(is_array($justthese)) { $this->search_result=ldap_search($this->link_id,$base_dn,$filter,$justthese); } else { $this->search_result=ldap_search($this->link_id,$base_dn,$filter); } } function wrapper_ldap_mod_replace($dn,$entry) { return ldap_mod_replace($this->link_id,$dn,$entry); } function wrapper_ldap_add($dn,$entry) { return ldap_add($this->link_id,$dn,$entry); } function wrapper_ldap_count_entries() { return ldap_count_entries($this->link_id,$this->search_result); } function wrapper_ldap_get_entries() { return ldap_get_entries($this->link_id,$this->search_result); } // LDAP 切断 function wrapper_ldap_close() { ldap_close($this->link_id); } } $ldap = new LdapAccess; $ldap->setHostname("ldap://hoge.hoge.com:389"); $ldap->setLdap_set_option_option(LDAP_OPT_PROTOCOL_VERSION); $ldap->setLdap_set_option_newval(3); $ldap->setBind_rdn("cn=hoge,o=ldap,dc=hoge,dc=com"); $ldap->setBind_password("_hoge"); if($ldap->connect_start()) { $ldap->wrapper_ldap_search("o=hoge,dc=hoge,dc=com","(&(objectClass=organizationalUnit)(ou;lang-ja=*))"); print_r($ldap->wrapper_ldap_get_entries()); print $ldap->wrapper_ldap_count_entries(); } else { print $ldap->wrapper_ldap_error(); print $ldap->wrapper_ldap_errno(); } $ldap->wrapper_ldap_close(); ?>
PostgreSQLで設計されたDBを、CSV形式でファイルへドキュメント化
ポストグレースで設計されたDBを、CSV形式でファイルにドキュメント化
Usage : php postgres2txt.php
Usage : php postgres2txt.php
Usage : php postgres2txt.php
Usage : php postgres2txt.php
<?php /* ポストグレースで設計されたDBを、CSV形式でファイルにドキュメント化 Usage : php postgres2txt.php <DATABASE> Usage : php postgres2txt.php <DATABASE> <username> Usage : php postgres2txt.php <DATABASE> <username> <password> Usage : php postgres2txt.php <DATABASE> <username> <password> <host> */ ini_set("error_reporting",E_COMPILE_ERROR|E_ERROR|E_CORE_ERROR); ini_set("display_errors",1); $argv = $_SERVER["argv"]; if ( (count($argv) < 2 ) ||(5 < count($argv) ) ){ print "Usage : php {$argv[0]} <DATABASE> \n"; print "Usage : php {$argv[0]} <DATABASE> <username> \n"; print "Usage : php {$argv[0]} <DATABASE> <username> <password> \n"; print "Usage : php {$argv[0]} <DATABASE> <username> <password> <host>\n"; exit; } $database = $argv[1]; $username = $argv[2]; $password = $argv[3]; $host = $argv[4]; $o = new database; $o->init($database,$username,$password,$host); $table_list = $o->get_table_list(); $meta_columns = $o->get_meta_columns(); $meta_default = $o->get_meta_default(); $meta_key = $o->get_meta_key(); foreach($table_list as $key => $value2) { print $value2["tablename"]; print ","; print "({$value2[tablecomment]})"; print "\n"; print "フィールド,データ型,NOT NULL,デフォルト,コメント\n"; foreach($meta_columns[$value2["tablename"]] as $key1 => $value1) { print $value1["attname"]; print ","; print $value1["type"]; print ","; if($value1["attnotnull"] == "t") { print "NOT NULL"; } print ","; print $value1["adsrc"]; print ","; print $value1["comment"]; print "\n"; } print "\n"; } class database { var $database; function _get_all_data() { $this->table_list = $this->db->do_getall($this->_get_sql_table_list()); foreach($this->table_list as $key => $value) { $this->meta_columns[$value["tablename"]] = $this->db->do_getall($this->_get_sql_meta_columns_sql($value["tablename"])); $this->meta_default[$value["tablename"]] = $this->db->do_getall($this->_get_sql_meta_default_sql($value["tablename"])); $this->meta_key[$value["tablename"]] = $this->db->do_getall($this->_get_sql_meta_key_sql($value["tablename"])); } } var $db; var $table_list; function get_table_list() { return $this->table_list; } var $meta_columns; function get_meta_columns() { return $this->meta_columns; } var $meta_default; function get_meta_default() { return $this->meta_default; } var $meta_key; function get_meta_key() { return $this->meta_key; } function init($database,$username,$password,$host) { $this->database = $database; if(!$username) { $username = "postgres"; } if(!$host) { $host = "localhost"; } $this->db = new db_access; $dsn = "pgsql://{$username}:{$password}@{$host}/{$this->database}"; $this->db->set_dsn($dsn); $this->db->do_connect(); $this->_get_all_data(); } function _get_sql_meta_key_sql($table) { $table = addslashes($table); //------------------------------------------------------------ //metaKeySQL //------------------------------------------------------------ $sql = " SELECT ic.relname AS index_name , a.attname AS column_name , i.indisunique AS unique_key , i.indisprimary AS primary_key FROM pg_class bc , pg_class ic , pg_index i , pg_attribute a WHERE bc.oid = i.indrelid AND ic.oid = i.indexrelid AND ( i.indkey[0] = a.attnum OR i.indkey[1] = a.attnum OR i.indkey[2] = a.attnum OR i.indkey[3] = a.attnum OR i.indkey[4] = a.attnum OR i.indkey[5] = a.attnum OR i.indkey[6] = a.attnum OR i.indkey[7] = a.attnum ) AND a.attrelid = bc.oid AND bc.relname = '{$table}' ; "; return $sql; } function _get_sql_meta_default_sql($table) { $table = addslashes($table); //------------------------------------------------------------ //metaDefaultsSQL //------------------------------------------------------------ $sql = " SELECT d.adnum as num , d.adsrc as def from pg_attrdef d , pg_class c where d.adrelid=c.oid and c.relname='{$table}' order by d.adnum ; "; return $sql; } function _get_sql_meta_columns_sql($table) { $table = addslashes($table); //------------------------------------------------------------ //metaColumnsSQL //------------------------------------------------------------ $sql = " SELECT a.attname, pg_catalog.format_type(a.atttypid, a.atttypmod) as type, a.atttypmod, a.attnotnull, a.atthasdef, adef.adsrc, a.attstattarget, a.attstorage, t.typstorage, ( SELECT 1 FROM pg_catalog.pg_depend pd, pg_catalog.pg_class pc WHERE pd.objid=pc.oid AND pd.classid=pc.tableoid AND pd.refclassid=pc.tableoid AND pd.refobjid=a.attrelid AND pd.refobjsubid=a.attnum AND pd.deptype='i' AND pc.relkind='S' ) IS NOT NULL AS attisserial, pg_catalog.col_description(a.attrelid, a.attnum) AS comment FROM pg_catalog.pg_attribute a LEFT JOIN pg_catalog.pg_attrdef adef ON a.attrelid=adef.adrelid AND a.attnum=adef.adnum LEFT JOIN pg_catalog.pg_type t ON a.atttypid=t.oid WHERE a.attrelid = (SELECT oid FROM pg_catalog.pg_class WHERE relname='{$table}' AND relnamespace = (SELECT oid FROM pg_catalog.pg_namespace WHERE nspname = 'public')) AND a.attnum > 0 AND NOT a.attisdropped ORDER BY a.attnum "; return $sql; } function _get_sql_table_list() { // ------------------------------------------------------------ // table list // ------------------------------------------------------------ $sql = " SELECT c.relname AS tablename , pg_catalog.pg_get_userbyid(c.relowner) AS tableowner , pg_catalog.obj_description(c.oid, 'pg_class') AS tablecomment FROM pg_catalog.pg_class c LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace WHERE c.relkind = 'r' AND nspname='public' ORDER BY c.relname ; "; return $sql; } } class db_access { function set_dsn($dsn) { $this->dsn = $dsn; } var $dsn = null; var $_result = array(); var $conid = null; function do_connect() { require_once("DB.php"); $this->conid = DB::connect($this->dsn); if ( DB::isError($this->conid) ) { die ($this->conid->getMessage()); } } function do_getall($sql) { $result = $this->conid->getAll($sql,DB_FETCHMODE_ASSOC); //DB_FETCHMODE_ASSOC,DB_FETCHMODE_ORDERED if (DB::isError($result)) { die ($result->getDebugInfo($result)); } return $result; } function do_query($sql) { $result = $this->conid->query($sql); if (DB::isError( $result )) { die ( $result->getDebugInfo() ); } } function disconnect() { $this->conid->disconnect(); } } ?>