PHP開発環境を作成する
vagrantの仮想環境にphp開発環境を整えてみました。
用意するのは、PHP、Git、Apacheです。
gitをインストールします。
# yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel
gitの設定を変更します。
# git config --list fatal: error processing config file(s) # git config --global user.name hoge # git config --list user.name=hoge # git config --global user.email fuga@gmail.com # git config --list user.name=hoge user.email=fuga@gmail.com # exit exit $ git config --list fatal: error processing config file(s) $ su Password: # git config --global --unset user.name # git config --global --unset user.email # git config --list # exit exit $ git config --global user.name hoge $ git config --global user.email fuga@gmail.com $ git config --list user.name=hoge user.email=fuga@gmail.com
sshのキーを作成し、githubに登録します。
$ ssh-keygen -t rsa -C "fuga@gmail.com" Generating public/private rsa key pair. Enter file in which to save the key (/home/vagrant/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: $ ls -la total 16 drwx------. 2 vagrant vagrant 4096 2015-04-05 08:45 . drwx------. 4 vagrant vagrant 4096 2015-04-05 08:43 .. -rw------- 1 vagrant vagrant 1675 2015-04-05 08:45 id_rsa -rw-r--r-- 1 vagrant vagrant 404 2015-04-05 08:45 id_rsa.pub $ cat id_rsa.pub ssh-rsa XXX fuga@gmail.com
sshしてみます。
$ ssh git@github.com The authenticity of host 'github.com (192.xxx.yyy.zzz)' can't be established. RSA key fingerprint is XXX Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'github.com,192.xxx.yyy.zzz' (RSA) to the list of known hosts. PTY allocation request failed on channel 0 Hi hoge! You've successfully authenticated, but GitHub does not provide shell access. Connection to github.com closed.
git cloneしてみます。
$ git clone https://github.com/hoge/xxx.git Initialized empty Git repository in /home/vagrant/.ssh/xxx/.git/ remote: Counting objects: 15, done. remote: Total 15 (delta 0), reused 0 (delta 0), pack-reused 15 Unpacking objects: 100% (15/15), done. $ ls -la total 24 drwx------. 3 vagrant vagrant 4096 2015-04-05 09:02 . drwx------. 4 vagrant vagrant 4096 2015-04-05 08:43 .. drwxr-xr-x 3 vagrant vagrant 4096 2015-04-05 09:02 xxx -rw------- 1 vagrant vagrant 1675 2015-04-05 08:45 id_rsa -rw-r--r-- 1 vagrant vagrant 404 2015-04-05 08:45 id_rsa.pub -rw-r--r-- 1 vagrant vagrant 407 2015-04-05 08:47 known_hosts
PHPをインストールします。
# yum install php php-mbstring php-pear php-pgsql # php -v PHP 5.3.3 (cli) (built: Oct 30 2014 20:12:53) Copyright (c) 1997-2010 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies # chkconfig --list httpd httpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off # chkconfig httpd on # chkconfig --list httpd httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
ドキュメントルート以下にphpスクリプトを作成して、ブラウザからアクセスします。
# cd /var/www/html # vim index.php <?php echo 'Hi !'; ?>
今後、PHPで色々開発していこうと思います。
- 作者: 小川雄大,柄沢聡太郎,橋口誠
- 出版社/メーカー: 技術評論社
- 発売日: 2014/10/31
- メディア: Kindle版
- この商品を含むブログを見る