ラベル MySQL の投稿を表示しています。 すべての投稿を表示
ラベル MySQL の投稿を表示しています。 すべての投稿を表示

2012年8月5日日曜日

VirtualBoxで開発環境構築 アプリケーションのインストール

Apacheのインストール

  • Apacheのインストールコマンド
    • yum -y install httpd
  • Apacheの設定
    • ランレベルの設定
    •  /sbin/chkconfig httpd on
    •  /sbin/chkconfig --list httpd

MySqlのインストール

  • MySqlのインストールコマンド
    • yum -y install mysql-server
  • MySqlの設定
    • vi /etc/my.cnf
  • [mysqld] に追加
    • default-character-set = utf8
    • skip-character-set-client-handshake
    • character-set-server = utf8
    • collation-server = utf8_general_ci
    • init-connect = SET NAMES utf8
  • [mysqld_safe]の後に以下を書き込む
  • [client]
    • default-character-set = utf8
  • [mysql]
    • default-character-set = utf8
  • [mysqldump]
    • default-character-set = utf8
  • 自動起動設定
    • /sbin/chkconfig mysqld on
    • /sbin/chkconfig --list mysqld
  • 起動を確認
    • /etc/init.d/mysqld start

PHPのインストール

  • 取得先のGPG-KEY 取得
    • rpm –import http://www.jasonlitka.com/media/RPM-GPG-KEY-jlitka
  • 設定ファイルを作成
    • vi /etc/yum.repos.d/utterramblings.repo
[utterramblings]
name=Jason’s Utter Ramblings Repo
baseurl=http://www.jasonlitka.com/media/EL$releasever/$basearch/
enabled=1
gpgcheck=1
gpgkey=http://www.jasonlitka.com/media/RPM-GPG-KEY-jlitka
  • 取得先のGPG-KEY 取得
    • yum install php
    • yum install php-devel
    • yum install php-common
    • yum install php-gd php-mbstring php-pdo php-mcrypt php-mysql php-ncurses php-xml
  • バージョンの確認コマンド
    • php -v

Pearのインストール

  • Pearをインストール
    • yum -y install php-pear

Symfonyのインストール

  • symfonyのチャネルを登録
    • pear channel-discover pear.symfony-project.com
  • symfonyのチャネルを登録
    • pear channel-discover pear.symfony-project.com
  • Pearでsymfonyをインストール
    • pear install symfony/symfony-1.0.20
  • バージョンの確認コマンド
    • symfony -V

vsftpdのインストール

2012年6月25日月曜日

2012年06月25日 講義086日目

2012年06月25日
講義086日目
------------------------------1H------------------------------
★職場体験
●コンバート
・コンバートの流れ
公開したいデータ
入力したいデータ
↓インポート
コンバートシステム
↓エクスポート↓
サイトA、サイトB……
・目的:記述の異なる二つの沿線情報をマッピングするためのマッピングテーブルの作成
  サイトによって違う情報をすり合わせるためにマッピングテーブルを作成
  コンバートするサイトによってデータの形式が違う
●sqlファイルをデータベースにインポート
・mysql> create database work_experience;
データベースを作る
・FFFTPで
homeディレクトリにコピー
mysql -u nishi -p データベース名 < インポートしたいsqlファイル.sql
・myphpadminで
インポートの項目からインポートする
------------------------------2H------------------------------
★職場体験
●テーブルの作成
・mappingテーブルの作成
ensen_id : char(4)
eki_id : char(3)
line_cd : char(5)
station_cd : char(7)
☆line_cdとstation_cdがユニークなキー
------------------------------3H------------------------------
★職場体験
●phpプロジェクトの作成
・VM内にディレクトリを作成
・vhostとかhostsとか色々設定
・以前使ったmyUtilでDBに接続→パスワードが間違っててハマる
  echo ini_set("display_errors","1");
  でエラーを表示させて、解決
・とりあえずprint_r()でDBの中身を表示
------------------------------4H------------------------------
★職場体験
●DBにcsvファイルをインポートする
・四苦八苦するなど
・結局カラムの型を適当にintに設定してたのが原因だった
  charと緯度経度はdoubleに変更して正常にインポートすることができた
------------------------------5H------------------------------
★職場体験
●SQL文を復習するとか
------------------------------6H------------------------------
★職場体験
●SQL文の入れ子
・IN()などで二つのDBのカラム名の比較が実現可能らしい
・master_ensen_abstractDBのline_nameと
  m_stationDBのensen_name|ensen_name_short
・master_ensen_abstractDBのstation_name
  m_stationDBのeki_name|eki_name_short
  がそれっぽく一致したレコードに
  m_stationDBのline_cd,station_cd
  master_ensen_abstractDBのensen_id,eki_id
  をレコードに入れる
  的なロジックを作る感じのアプローチかな
・なんとなく一致してるロジックは正規表現?がスキル的に無理かなーとか
-----------------------------memo------------------------------

2012年4月27日金曜日

2012年04月26日 講義056日目

2012年04月26日
講義056日目
------------------------------1H------------------------------
★サーバ設定の復習
●SELinux
・firewallの設定
ポートを空けたりとかする
●色々とインストールする
・yumコマンド
インストールするためのコマンド
・ランレベルの設定
Linuxの動作モード
動作モードによって起動されるプログラムを設定する。基本2-5
・service --status-all
実行中のプログラムを全部表示させる
httpdとmysqldとvsftpdが動いている事を確認
・文字コードの設定
・symfonyのインストール
●NTP(Network Time Protocol)
・cron登録用のシェルを作成
・ファイル権限設定
・自動起動設定
●シェルスクリプト
サーバを自動で動かしたい時に書いておくもの
------------------------------2H------------------------------
★サーバ設定の復習
------------------------------3H------------------------------
★サーバにPHPで作ったwebサイトを移植する
●PHPファイル
・BBSをzipで圧縮
・FFFTPで圧縮したBBS.zipをサーバに上げる
●mysqlファイル
・コマンドプロンプトでデータベース.sqlをローカルにコピーする
・FFFTPでDBごとサーバに上げる
------------------------------4H------------------------------
★サーバにPHPで作ったwebサイトを移植する
●PHPファイルの解凍
・unzip bbs.zip
zipファイルを解凍する
・mysql -u ユーザ名 -p DB名 < ファイル名.sql
mysqlにDBをインポートする
●eclipseでリモート接続
eclipseのリモートシステムエクスプローラを使い、PHPファイルを編集する
------------------------------5H------------------------------
★サーバ上のPHPファイルを編集する
●修正
・localhostにとばされる部分をブラウザに紐付けたサーバ名に変更する
------------------------------6H------------------------------
★移行デバック
●ini_set("display_errors","On");
でエラーを出すようにしてデバック
★symfonyの準備
[nishi@localhost ~]$ mkdir sftest
[nishi@localhost sftest]$ symfony -V
symfony version 1.0.20
[nishi@localhost sftest]$ symfony init-project sftest
>> dir+      /home/nishi/sftest/plugins
>> dir+      /home/nishi/sftest/apps
>> dir+      /home/nishi/sftest/config
>> file+     /home/nishi/sftest/config/properties.ini
>> file+     /home/nishi/sftest/config/schema.yml
>> file+     /home/nishi/sftest/config/config.php
>> file+     /home/nishi/sftest/config/propel.ini
>> file+     /home/nishi/sftest/config/databases.yml
>> file+     /home/nishi/sftest/config/rsync_exclude.txt
>> dir+      /home/nishi/sftest/batch
>> dir+      /home/nishi/sftest/web
>> dir+      /home/nishi/sftest/web/uploads
>> dir+      /home/nishi/sftest/web/uploads/assets
>> file+     /home/nishi/sftest/web/.htaccess
>> dir+      /home/nishi/sftest/web/js
>> dir+      /home/nishi/sftest/web/css
>> file+     /home/nishi/sftest/web/css/main.css
>> dir+      /home/nishi/sftest/web/images
>> file+     /home/nishi/sftest/web/robots.txt
>> file+     /home/nishi/sftest/symfony
>> dir+      /home/nishi/sftest/cache
>> dir+      /home/nishi/sftest/data
>> dir+      /home/nishi/sftest/data/model
>> dir+      /home/nishi/sftest/data/sql
>> dir+      /home/nishi/sftest/lib
>> dir+      /home/nishi/sftest/lib/model
>> dir+      /home/nishi/sftest/doc
>> dir+      /home/nishi/sftest/log
>> dir+      /home/nishi/sftest/test
>> dir+      /home/nishi/sftest/test/bootstrap
>> file+     /home/nishi/sftest/test/bootstrap/unit.php
>> file+     /home/nishi/sftest/test/bootstrap/functional.php
>> dir+      /home/nishi/sftest/test/unit
>> dir+      /home/nishi/sftest/test/functional
>> tokens    /home/nishi/sftest/config/properties.ini
>> tokens    /home/nishi/sftest/config/propel.ini
>> tokens    /home/nishi/sftest/config/propel.ini
>> tokens    /home/nishi/sftest/config/config.php
>> chmod 777 /home/nishi/sftest/cache
>> chmod 777 /home/nishi/sftest/log
>> chmod 777 /home/nishi/sftest/web/uploads
>> chmod 777 /home/nishi/sftest/symfony
>> chmod 777 web/uploads/assets
-----------------------------memo------------------------------


2012年4月25日水曜日

2012年04月25日 講義055日目

2012年04月25日
講義055日目
------------------------------1H------------------------------
★Firewallの設定
●最初に設定
・iptables -P INPUT ACCEPT
外部からのアクセスを許可
・iptables -P FORWARD DROP
次にデータを渡す
・iptables -P OUTPUT ACCEPT
外部にデータを渡す
・iptables -F
上のコマンドiptablesのルールの設定を反映させるためのコマンド
●icmp(ping) と自端末からの入力を許可
・iptables -A INPUT -p icmp -j ACCEPT

・iptables -A INPUT -i lo -j ACCEPT

●Web、FTP、POP、smtp による接続を許可
・iptables -A INPUT -p tcp --dport 80 -j ACCEPT

・iptables -A INPUT -p tcp --dport 21 -j ACCEPT

・iptables -A INPUT -p tcp --dport 110 -j ACCEPT

・iptables -A INPUT -p tcp --dport 25 -j ACCEPT

●ssh による接続を許可
・iptables -A INPUT -p tcp --dport 22 -j ACCEPT

●TCP の接続開始と応答、FTP データなどを許可
・iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

●ルールをセーブする
・/etc/init.d/iptables save
●cat /etc/sysconfig/iptables
設定の確認
●reboot
再起動するコマンド
------------------------------2H------------------------------
★Firewallの設定
●SELinuxを停止させる
他のプロセスに影響を及ぼさないようにする機能
・vi /etc/sysconfig/selinux
SELINUX=enforcing
↓
SELINUX=disabled
書き換える
・reboot
再起動
●アパッチのインストール
・getenforce
先ほどの変更がdisableであることを確認
・yum -y install httpd
httpdはアパッチのこと
●eclipseでサーバにリモート接続する
ウィンドウ→パースペクティブを開く→その他→リモートシステムエクスプローラ
リモートシステムタブの空白を右クリック→新規接続
puttyの設定と同じように、ホスト名にサーバのIPアドレスを入力
接続先の名前を設定して完了
・パスワードやユーザ名の入力を求められるので、CentOSで入力したものを使う
------------------------------3H------------------------------
★各種アプリケーションのインストール
●apache
●mysql
●PHP
●vsftpd
●ntp
------------------------------4H------------------------------
★アプリケーションのインストール
●
・ランレベル
[root@localhost ~]# /sbin/chkconfig httpd on
[root@localhost ~]# /sbin/chkconfig --list httpd
httpd           0:off   1:off   2:on    3:on    4:on    5:on    6:off
0:off   1:off   2:on    3:on    4:on    5:on    6:off
●apacheの起動
☆apacheの設定ファイルを書き換えた後などにも「restart」で使う
[root@localhost ~]# /etc/init.d/httpd start
httpd を起動中:                                            [  OK  ]
☆再起動させたい場合は
/etc/init.d/httpd restart
●Mysqlの起動
マイコンピュータからローカル環境のmysqlのmy.iniの
default-character-set = utf8
skip-character-set-client-handshake
character-set-server = utf8
collation-server = utf8_general_ci
init-connect = SET NAMES utf8
をコピー
・vi /etc/my.cnf
を貼り付け
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

default-character-set = utf8
skip-character-set-client-handshake
character-set-server = utf8
collation-server = utf8_general_ci
init-connect = SET NAMES utf8

# To enable the InnoDB Plugin, uncomment the 2 next lines
#ignore-builtin-innodb
#plugin-load=innodb=ha_innodb_plugin.so

# To enable InnoDB-related INFORMATION_SCHEMA tables
# Join the following options to above directive
  ;innodb_trx=ha_innodb_plugin.so
  ;innodb_locks=ha_innodb_plugin.so
・[mysqld_safe]の後に以下を書き込む
[client]
default-character-set = utf8
[mysql]
default-character-set = utf8
[mysqldump]
default-character-set = utf8
・自動起動設定
[root@localhost ~]# /sbin/chkconfig mysqld on
[root@localhost ~]# /sbin/chkconfig  --list mysqld
mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off
[root@localhost ~]# /etc/init.d/mysqld start
------------------------------5H------------------------------
★アプリケーションのインストール
●コマンド入力でバージョンを確認
[root@localhost ~]# mysql -V
mysql  Ver 14.14 Distrib 5.1.58, for redhat-linux-gnu (i686) using readline 5.1
[root@localhost ~]# php -v
PHP 5.2.17 (cli) (built: Aug 31 2011 17:06:47)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2010 Zend Technologies
[root@localhost ~]# symfony -V
symfony version 1.0.20
●vsftpの起動
・自動起動設定
[root@localhost ~]# /sbin/chkconfig vsftpd on
[root@localhost ~]# /sbin/chkconfig --list vsftpd
vsftpd          0:off   1:off   2:on    3:on    4:on    5:on    6:off
[root@localhost ~]# /etc/init.d/vsftpd start
vsftpd 用の vsftpd を起動中:   
●ntp  (時間合わせ)
/usr/sbin/ntpdate ntp.jst.mfeed.ad.jp
●FFFTPにサーバの登録
puttyを参考に
------------------------------6H------------------------------
★サーバでPHPファイルを実行
●phpファイルを実行
・コマンドラインから直接実行して確認
[nishi@localhost ~]$ /usr/bin/php ./test.php
test
●hostsの編集
・ブラウザから確認
・ローカル側の設定
firefoxのswitchhostでアドレス名とサーバIPアドレスを紐付ける
・サーバ側の設定
[root@localhost ~]# cd /etc/httpd/conf
[root@localhost conf]#
・/etc/httpd/conf.dにファイルを作成
[root@localhost httpd]# cd /etc/httpd/conf.d
[root@localhost conf.d]# vi httpd-vhost.conf

NameVirtualHost *:80

<VirtualHost *:80>
    ServerName www.shonanbbs.com
    DocumentRoot /home/nishi/bbs
    <Directory "/home/nishi/bbs">
        AllowOverride All
        Options -Include -ExecCGI
    </Directory>
</VirtualHost>
・再起動
[root@localhost conf.d]# /etc/init.d/httpd restart
httpd を停止中:                                            [  OK  ]
httpd を起動中: Warning: DocumentRoot [/home/nishi/bbs] does not exist
                                                           [  OK  ]
・eclipse上でbbsフォルダを作成
phpファイルを作成してhostsファイルで設定したサーバ名を入力し、
ブラウザから表示してみる
●mysqlのユーザを作る
・puttyでサーバのmysqlに接続
[root@localhost conf.d]# mysql -u root
・データベースを作成
mysql> create database study;
Query OK, 1 row affected (0.00 sec)
・ユーザ作成
mysql> GRANT ALL ON *.* TO nishi@"localhost" IDENTIFIED BY "password";
Query OK, 0 rows affected (0.01 sec)

-----------------------------memo------------------------------
サーバ面白い

2012年4月5日木曜日

2012年04月05日 講義042日目

2012年04月05日
講義042日目
------------------------------1H------------------------------
★管理画面作成
●コメント編集画面
・comment_list
編集画面のデータ混乱を防ぐためにセッションのクリア
・comment_edit
bbs/tmp/に編集される画像を一時的に保存するためのロジック
・comment_input
最初にこのページに来たのか、戻るボタンで来たのかを分岐
{if $smarty.session.tmpnickname != ""}
    <input type="text" name="nickname" size"20"
           value="{$smarty.session.tmpnickname}">
{else}
    <input type="text" name="nickname" size="20"
           value="{$comment.nickname}">
{/if}

<textarea>内に無用なインデントを入れるとテキストエリア内でインデントが作られる場合がある(smartyのせい?)
・comment_edit_comfirm

------------------------------2H------------------------------
★管理画面作成
●コメント編集画面
関数の中で関数を呼ぶ処理
・myUtil::getFileExt()
ファイルの拡張子を見てる
・getFileExtId()
getimagesize()で拡張子を返す
・エラー制御演算子
関数に@をつけるとエラーを表示しなくなる
ワーニング、ノーティスを出したくないところにつける
エラーをだしてくれないのであまり使用しない方がいい
------------------------------3H------------------------------
★管理画面作成
●コメント編集画面
・confirm/resultでのページ更新を防ぐロジックの実装
input.php
$_SESSION["comment_edit_input_id"] = rand();
input.tpl
  <input type="hidden" name="comment_edit_input_id"
         value="{$smarty.session.comment_edit_input_id}">
comment_edit_confirm.php
//input.phpから来たかどうかを判断する処理
if($_SESSION["comment_edit_input_id"] != $_POST["comment_edit_input_id"]){
    header("Location:http://localhost/bbs/admin/index.php");
}else{
    $_SESSION["comment_edit_input_id"] = rand();
}

//result.phpでconfirm.phpから来たかどうか判断するための処理
$_SESSION["comment_edit_confirm_id"] =rand();
comment_edit_confirm.tpl

・確認
confirmでページ更新
resultでページ更新
confirmに直接URLを打つ
resultに直接URLを打つ
------------------------------4H------------------------------
★管理画面作成
●内部結合と外部結合
comment_delete.php修正
・内部結合
SELECT * FROM comment,reply WHERE comment. id = reply.comment_id;
SELECT * FROM comment INNER JOIN reply
         WHERE comment,id = reply.comment_id;
二つ以上のテーブルで条件と一致するもののみ取得
$sql = "DELETE comment,reply
        FROM comment,reply
        WHERE comment.id =reply.comment_id
        AND comment.id ='".$id."'";
・外部結合
(LEFT JOINで左側基準)
SELECT * FROM comment LEFT JOIN reply
         ON comment.id = reply.comment_id;
(RIGHT JOINで右側基準)
SELECT * FROM reply RIGHT JOIN comment
         ON comment,id = reply.comment_id;
片方のテーブルを基準にして、
そのテーブルの全データを条件に一致するもう片方のテーブルを取得
$sql = "DELETE comment,reply
        FROM comment LEFT JOIN reply
        ON comment.id = reply.comment_id
        WHERE comment.id ='" . $id. "'";
mysql_query($sql);
・完全外部結合
UNIONを使う
------------------------------5H------------------------------
------------------------------6H------------------------------
★管理画面作成
●メンバー編集画面の作成
comment_edit_input
comment_edit_confirm
comment_edit_result
を参考にして
member_edit_input
member_edit_confirm
member_edit_result
の作成
★symfonyを使ったサイト作成の発表会見学
-----------------------------memo------------------------------
セッションの使い方は奥が深そう