CentOS in VirtualBox セットアップメモ

CentOS6.6 minimalインストール後にrootでログイン

```shell-session:shell

useradd revin
passwd revin

visudo

```

```vim:visudo

- %wheel ALL=(ALL) ALL
+ wheel ALL=(ALL) ALL

```

```shell-session:shell

usermod -G wheel revin
sudo vi /etc/login.defs

```

```vim:/etc/login.defs

+ SU_WHEEL_ONLY yes

```

```shell-session:shell

sudo vi /etc/ssh/sshd_config

```

```vim:/etc/ssh/sshd_config

- #PermitRootLogin yes
+ #PermitRootLogin no

```

```shell-session:shell

exit

```

revinでログイン

```shell-session:shell

sudo vi /etc/sysconfig/network-scripts/ifcfg-eth0

```

```vim:/etc/sysconfig/network-scripts/ifcfg-eth0

- ONBOOT=no
+ ONBOOT=yes

```

```shell-session:shell

sudo vi /etc/sysconfig/network-scripts/ifcfg-eth1

```

```vim:/etc/sysconfig/network-scripts/ifcfg-eth1

DEVICE=eth1
HWADDR=08:00:27:A7:BB:7D　//←VirtualBoxのアダプタ2（ホストオンリー）のMACアドレス
TYPE=Ethernet
UUID=ca53a4be-2934-4a0d-9bf5-1ccbf58b136d
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=dhcp
BROADCAST=192.168.56.255
IPADDR=192.168.56.101
NETMASK=255.255.255.0
NETWORK=192.168.56.0

```

```shell-session:shell

sudo ifdown eth0
sudo ifup eth0
sudo ifup eth1

exit

```

めんどくせえんでselinuxとiptablesは切っとく
テスト用VM以外で切るのは危険なのでやっちゃダメ～ン

```shell-session:shell

sudo setenforce 0
sudo service iptables stop

sudo chkconfig iptables off

sudo vi /etc/selinux/config

```

```vim:/etc/selinux/config

- SELINUX=enforcing
+ SELINUX=disabled

```


ホストOSからTeraTermとかで192.168.56.101に接続

```shell-session:shell

su -

rpm -Uvh https://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
rpm -Uvh http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm
rpm -Uvh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm

yum upgrade

yum install mlocate
yum --enablerepo=nginx install nginx
yum --enablerepo=epel,remi install vim
yum --enablerepo=epel,remi install php
yum --enablerepo=epel,remi install php-fpm
yum --enablerepo=epel,remi install mysql
yum --enablerepo=epel,remi install mysql-server
yum --enablerepo=epel,remi install phpmyadmin

cp /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.bak

vim /etc/php.ini

```


```vim:/etc/php.ini


- ;date.timezone =
+ date.timezone = "Asia/Tokyo"
- ;session.save_path = "/tmp"
+ session.save_path = "/var/lib/php/session"

```

諸グループにユーザ追加しとく

```shell-session:shell

usermod -G wheel,nginx,mysql revin

mkdir /log
mkdir /log/mysql
mkdir /log/nginx
chown mysql /log/mysql
chown nginx /log/nginx

```

クエリログ出す

```vim:/etc/my.cnf

+ log=/log/mysql/query.log　　　//←[mysqld]のところに書く

```

これで「tail -f /log/mysql/query.log」でクエリログを監視できる


```shell-session:shell

service mysqld start

```

mysqlのユーザ作成

```shell-session:shell

mysql

```

```mysql:mysql_console

GRANT ALL PRIVILEGES ON *.* TO revin IDENTIFIED BY 'revin' WITH GRANT OPTION;
FLUSH PRIVILEGES;

```

web公開用ディレクトリとか設定

```shell-session:shell

mkdir /web
mkdir /web/test
mkdir /web/test/public_html
chown -R nginx /web
chown -R root.nginx /var/lib/php/session
vim /web/test/public_html/index.html
vim /web/test/public_html/index.php

```

```html:/web/test/public_html/index.html

hello html5

```

```php:/web/test/public_html/index.php
<?php
phpinfo();
?>

```

```shell-session:shell

mv /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.bak
vim /etc/php-fpm.d/www.conf
vim /etc/nginx/conf.d/test.conf
vim /etc/nginx/conf.d/phpmyadmin.conf

```

```vim:/etc/php-fpm.d/www.conf

- user = apache
- group = apache
+ user = nginx
+ group = nginx

```

```vim:/etc/nginx/conf.d/test.conf

server {
    listen       80;
    server_name  local.vm;

    error_log /log/nginx/error.log

    location / {
        root   /web/test/public_html;
        index  index.html index.htm;
    }
    location ~ \.php$ {
        root           /web/test/public_html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}

```

```vim:/etc/nginx/conf.d/phpmyadmin.conf

server {
       listen 80;
       server_name  phpmyadmin.local.vm;

       location / {
                root /usr/share/phpMyAdmin;
                index index.php;
                }

        location ~ \.php$ {
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME /usr/share/phpMyAdmin/$fastcgi_script_name;
                include fastcgi_params;
        }
}

```


```shell-session:shell

service nginx start
service php-fpm start
service mysqld restart

chkconfig mysqld on
chkconfig nginx on
chkconfig php-fpm on

```

ホストOSのhostsを変更
WindowsならC:\Windows\System32\drivers\etc\hosts
これでlocal.vmでゲストOSに繋げる

```vim:hosts

+ 192.168.56.101 local.vm
+ 192.168.56.101 phpmyadmin.local.vm
+ 
```

これで
http://local.vm/index.html
http://local.vm/index.php
で、上の方で編集したhtmlとphpが見れるはず
http://phpmyadmin.local.vm/
でphpmyadminも使える

Guest Additionsのインストール

```shell-session:shell

yum install gcc
yum install make
//kernelバージョンの違いでインストールがコケるので合わせる
yum remove kernel-devel
yum install kernel-devel-2.6.32-504.el6.x86_64

mkdir /mnt/cdrom
mount -r /dev/cdrom /mnt/cdrom
cd /mnt/cdrom
./VBoxLinuxAdditions.run

yum install kernel-devel　　　//kernelを最新に戻す

```

目的はホストOSの共有フォルダのマウント

```shell-session:shell

mkdir /web/clickrogue　　//新しいプロジェクトの名前なので気にしないで
mount -t vboxsf clickrogue /web/clickrogue　//マウント

```

今後、マウントを有効にする場合、rebootするたびに以下を実行する

```shell-session:shell

mount -t vboxsf clickrogue /web/clickrogue

```

もしNo Such Device的なことを言われる場合、もう一回Guest Additionsを入れるくだりをやってみよう