Apacheでユーザー毎にディレクトリを公開する
はまったのでメモ。
環境はCentOS6.4付属のApache 2.2.15。
httpd.conf の修正
httpd.conf を開いて、
- userdir_moduleモジュールをロードする
LoadModule userdir_module modules/mod_userdir.so
<IfModule mod_userdir.c> # # UserDir is disabled by default since it can confirm the presence # of a username on the system (depending on home directory # permissions). # # UserDir disabled # # To enable requests to /~user/ to serve the user's public_html # directory, remove the "UserDir disabled" line above, and uncomment # the following line instead: # UserDir public_html </IfModule>
#service httpd restart
ローカル変数のスタックメモリの使われ方
こんな 感じに
char a = 0; char b = 1; char c = 2; short int d = 0x1234; short int e = 0x5678; short int f = 0x9abc; int x = 0xf0e1d2c3;
C言語でローカル変数を定義すると、下記の表の通りのイメージでスタックメモリに配置される。
アドレス | 型 | 値 |
---|---|---|
66949040 | int x | c3 |
66949041 | d2 | |
66949042 | e1 | |
66949043 | f0 | |
66949044 | 未使用 | 00 |
66949045 | 未使用 | 00 |
66949046 | short int f | bc |
66949047 | 9a | |
66949048 | short int e | 78 |
66949049 | 56 | |
6694904a | short int d | 34 |
6694904b | 12 | |
6694904c | 未使用 | 00 |
6694904d | char c | 02 |
6694904e | char b | 01 |
6694904f | char a | 00 |
CentOS 6.4 に gcc をインストール
使おうと思ったら無かったのでインストール。
[root@localhost ~]# yum install gcc
これだけ。
[root@localhost ~]# yum install gcc Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: ftp.iij.ad.jp * extras: centos.ustc.edu.cn * updates: ftp.iij.ad.jp Setting up Install Process Resolving Dependencies --> Running transaction check ---> Package gcc.x86_64 0:4.4.7-3.el6 will be installed --> Processing Dependency: libgomp = 4.4.7-3.el6 for package: gcc-4.4.7-3.el6.x86_64 --> Processing Dependency: cpp = 4.4.7-3.el6 for package: gcc-4.4.7-3.el6.x86_64 --> Processing Dependency: glibc-devel >= 2.2.90-12 for package: gcc-4.4.7-3.el6.x86_64 --> Processing Dependency: cloog-ppl >= 0.15 for package: gcc-4.4.7-3.el6.x86_64 --> Processing Dependency: libgomp.so.1()(64bit) for package: gcc-4.4.7-3.el6.x86_64 --> Running transaction check ---> Package cloog-ppl.x86_64 0:0.15.7-1.2.el6 will be installed --> Processing Dependency: libppl_c.so.2()(64bit) for package: cloog-ppl-0.15.7-1.2.el6.x86_64 --> Processing Dependency: libppl.so.7()(64bit) for package: cloog-ppl-0.15.7-1.2.el6.x86_64 ---> Package cpp.x86_64 0:4.4.7-3.el6 will be installed --> Processing Dependency: libmpfr.so.1()(64bit) for package: cpp-4.4.7-3.el6.x86_64 ---> Package glibc-devel.x86_64 0:2.12-1.107.el6_4.2 will be installed --> Processing Dependency: glibc-headers = 2.12-1.107.el6_4.2 for package: glibc-devel-2.12-1.107.el6_4.2.x86_64 --> Processing Dependency: glibc = 2.12-1.107.el6_4.2 for package: glibc-devel-2.12-1.107.el6_4.2.x86_64 --> Processing Dependency: glibc-headers for package: glibc-devel-2.12-1.107.el6_4.2.x86_64 ---> Package libgomp.x86_64 0:4.4.7-3.el6 will be installed --> Running transaction check ---> Package glibc.x86_64 0:2.12-1.107.el6 will be updated --> Processing Dependency: glibc = 2.12-1.107.el6 for package: glibc-common-2.12-1.107.el6.x86_64 ---> Package glibc.x86_64 0:2.12-1.107.el6_4.2 will be an update ---> Package glibc-headers.x86_64 0:2.12-1.107.el6_4.2 will be installed --> Processing Dependency: kernel-headers >= 2.2.1 for package: glibc-headers-2.12-1.107.el6_4.2.x86_64 --> Processing Dependency: kernel-headers for package: glibc-headers-2.12-1.107.el6_4.2.x86_64 ---> Package mpfr.x86_64 0:2.4.1-6.el6 will be installed ---> Package ppl.x86_64 0:0.10.2-11.el6 will be installed --> Running transaction check ---> Package glibc-common.x86_64 0:2.12-1.107.el6 will be updated ---> Package glibc-common.x86_64 0:2.12-1.107.el6_4.2 will be an update ---> Package kernel-headers.x86_64 0:2.6.32-358.14.1.el6 will be installed --> Finished Dependency Resolution Dependencies Resolved ============================================================================================================================================================ Package Arch Version Repository Size ============================================================================================================================================================ Installing: gcc x86_64 4.4.7-3.el6 base 10 M Installing for dependencies: cloog-ppl x86_64 0.15.7-1.2.el6 base 93 k cpp x86_64 4.4.7-3.el6 base 3.7 M glibc-devel x86_64 2.12-1.107.el6_4.2 updates 974 k glibc-headers x86_64 2.12-1.107.el6_4.2 updates 605 k kernel-headers x86_64 2.6.32-358.14.1.el6 updates 2.3 M libgomp x86_64 4.4.7-3.el6 base 118 k mpfr x86_64 2.4.1-6.el6 base 157 k ppl x86_64 0.10.2-11.el6 base 1.3 M Updating for dependencies: glibc x86_64 2.12-1.107.el6_4.2 updates 3.8 M glibc-common x86_64 2.12-1.107.el6_4.2 updates 14 M Transaction Summary ============================================================================================================================================================ Install 9 Package(s) Upgrade 2 Package(s) Total size: 37 M Total download size: 20 M Is this ok [y/N]: y Downloading Packages: (1/7): glibc-common-2.12-1.107.el6_4.2.x86_64.rpm | 14 MB 00:39 (2/7): glibc-devel-2.12-1.107.el6_4.2.x86_64.rpm | 974 kB 00:04 (3/7): glibc-headers-2.12-1.107.el6_4.2.x86_64.rpm | 605 kB 00:03 (4/7): kernel-headers-2.6.32-358.14.1.el6.x86_64.rpm | 2.3 MB 00:16 (5/7): libgomp-4.4.7-3.el6.x86_64.rpm | 118 kB 00:00 (6/7): mpfr-2.4.1-6.el6.x86_64.rpm | 157 kB 00:00 (7/7): ppl-0.10.2-11.el6.x86_64.rpm | 1.3 MB 00:11 ------------------------------------------------------------------------------------------------------------------------------------------------------------ Total 262 kB/s | 20 MB 01:16 Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Updating : glibc-2.12-1.107.el6_4.2.x86_64 1/13 Updating : glibc-common-2.12-1.107.el6_4.2.x86_64 2/13 Installing : mpfr-2.4.1-6.el6.x86_64 3/13 Installing : cpp-4.4.7-3.el6.x86_64 4/13 Installing : libgomp-4.4.7-3.el6.x86_64 5/13 Installing : ppl-0.10.2-11.el6.x86_64 6/13 Installing : cloog-ppl-0.15.7-1.2.el6.x86_64 7/13 Installing : kernel-headers-2.6.32-358.14.1.el6.x86_64 8/13 Installing : glibc-headers-2.12-1.107.el6_4.2.x86_64 9/13 Installing : glibc-devel-2.12-1.107.el6_4.2.x86_64 10/13 Installing : gcc-4.4.7-3.el6.x86_64 11/13 Cleanup : glibc-2.12-1.107.el6.x86_64 12/13 Cleanup : glibc-common-2.12-1.107.el6.x86_64 13/13 Verifying : glibc-common-2.12-1.107.el6_4.2.x86_64 1/13 Verifying : glibc-2.12-1.107.el6_4.2.x86_64 2/13 Verifying : glibc-devel-2.12-1.107.el6_4.2.x86_64 3/13 Verifying : gcc-4.4.7-3.el6.x86_64 4/13 Verifying : mpfr-2.4.1-6.el6.x86_64 5/13 Verifying : libgomp-4.4.7-3.el6.x86_64 6/13 Verifying : kernel-headers-2.6.32-358.14.1.el6.x86_64 7/13 Verifying : cpp-4.4.7-3.el6.x86_64 8/13 Verifying : glibc-headers-2.12-1.107.el6_4.2.x86_64 9/13 Verifying : ppl-0.10.2-11.el6.x86_64 10/13 Verifying : cloog-ppl-0.15.7-1.2.el6.x86_64 11/13 Verifying : glibc-2.12-1.107.el6.x86_64 12/13 Verifying : glibc-common-2.12-1.107.el6.x86_64 13/13 Installed: gcc.x86_64 0:4.4.7-3.el6 Dependency Installed: cloog-ppl.x86_64 0:0.15.7-1.2.el6 cpp.x86_64 0:4.4.7-3.el6 glibc-devel.x86_64 0:2.12-1.107.el6_4.2 glibc-headers.x86_64 0:2.12-1.107.el6_4.2 kernel-headers.x86_64 0:2.6.32-358.14.1.el6 libgomp.x86_64 0:4.4.7-3.el6 mpfr.x86_64 0:2.4.1-6.el6 ppl.x86_64 0:0.10.2-11.el6 Dependency Updated: glibc.x86_64 0:2.12-1.107.el6_4.2 glibc-common.x86_64 0:2.12-1.107.el6_4.2 Complete! [root@localhost ~]# [root@localhost ~]# [root@localhost ~]# which gcc /usr/bin/gcc [root@localhost ~]#
man のセクション一覧
セクション | 名前 |
---|---|
1 | だれもが実行できるユーザコマンド |
2 | システムコール、つまり、カーネルが提供する関数 |
3 | サブルーチン、つまり、ライブラリ関数 |
4 | デバイス、つまり、/dev ディレクトリのスペシャルファイル |
5 | ファイルフォーマットの説明、例 /etc/passwd |
6 | ゲーム(説明不要だろうネ) |
7 | その他 例: マクロパッケージや取り決め的な文書 |
8 | システム管理者だけが実行できるシステム管理用のツール |
9 | Linux 独自のカーネルルーチン用のドキュメンテーション |
n | 新しいドキュメンテーション:よりふさわしい場所に移動されるだろう |
o | 古いドキュメンテーション 猶予期間として保存されているもの |
l | 独自のシステムについてのローカルなドキュメンテーション |
CentOSのバージョンを確認するコマンド
$cat /etc/redhat-release CentOS release 6.4 (Final)
Python入門3
忘れるので制御構造とか。
if文
if x<0: # statement elif x==0: # statement elif x==1: # statement else # statement
for文
- カウンタでまわすのではなく、リストのデータ分繰り返す
list = ['A', 'B', 'C', 'D'] for v in list: print(v)
- カウンタでまわすのも可能
for i in Range(5): print(i) # この場合、0 1 2 3 4 と出力される
- forのelse は for分のリストがなくなったら実行される
- break した場合は実行されない
for i in range(5): print(i) else: print('end of for')
break
- 一番内側の for 文 / while 文を抜ける
for i in range(5): if i==2: break print(i) else: print('end of for')
continue
- 一番内側の for 文 / while 文の残りの処理をスキップし、次回のループを処理する
while 文
i = 0 while i<10: print(i) i+=1
pass
- 何もしない
class MyClass: pass
関数の定義
- 引数は任意。デフォルト値も与えられる。*で可変引数。
- 戻り値も任意だが、return のみや return しない場合は、None が返る
def func1(v, v2='ABC', *v3): return v
ディクショナリ
- ハッシュ、連想配列
- キー:値 でデータを持つ
#!/usr/bin/env python3.2 # -*- coding : utf-8 -*- def main(): site = {'google' : 'www.google.com', 'yahoo' : 'www.yahoo.com'} site['amazon'] = 'www.amazon.com' print(site) del site['yahoo'] print(site) if 'google' in site: print(site['google']) if 'yahoo' not in site: print("'yahoo' not in site") if __name__ == "__main__": main()
例外処理
- try - except - else 。else は 例外発生しなかったら最後に実行される。else は任意。
- raise で例外再送出。
#!/usr/bin/env python3.2 # -*- coding : utf-8 -*- import sys def main(): try: f = open('a') except IOError as err: print(err) # 複数書くことも可能 # except (RuntimeError, TypeError): except: raise else: print("end of try") if __name__ == "__main__": main()
Python 入門2
環境が出来たので、FizzBuzz書いてみます。
ソース
MacBook:python ymaru$ cat FizzBuzz.py #!/usr/bin/env python3.2 def main() : for i in range(1, 101) : value = i if i % 15 == 0 : value = "FizzBuzz" elif i % 3 == 0 : value = "Fizz" elif i % 5 == 0 : value = "Buzz" print("{0:3d}: {1}".format(i, value) ) if __name__ == "__main__" : main()
実行
出来たので実行
MacBook:python ymaru$ python3.2 FizzBuzz.py 1: 1 2: 2 3: Fizz 4: 4 5: Buzz 6: Fizz 7: 7 8: 8 9: Fizz 10: Buzz ・・略・・