Skip to content

How to setup a development environment

AIZAWA Hina edited this page Jul 16, 2016 · 33 revisions

Setup a Virtual Machine

  1. Install Oracle VM VirtualBox or other virtual machine software.
  2. Download Minimal ISO from CentOS Website.
  3. Run VirtualBox and create new virtual machine.
  • Name: "CentOS 7" or something
  • Type: Linux
  • Version: Red Hat (64 bit)
  • Memory: 1024 MB
  • Disk: Create new VDI, 15 GB
  1. Start it and "insert" downloaded ISO file.
  2. Choice "Install CentOS 7"
  3. Install CentOS 7 system. (use Google if needed)

(After this step, I recommend you use a terminal-emulator software like PuTTY.)

Setup

  1. (Re-)boot the machine and login as root.
  2. Run some commands to install and update basic packages: (# is a prompt, run as root)
  • # yum update -y : update installed packages
  • # yum install -y @base @core : install basic packages
  • # yum install -y centos-release-scl-rh epel-release scl-utils
  • # yum-config-manager --enable epel
  1. Setup Remi-safe RPM repository:
  • # yum install -y http://rpms.famillecollet.com/enterprise/7/safe/x86_64/remi-release-7.2-1.el7.remi.noarch.rpm
  • # yum-config-manager --enable remi-safe
  1. Setup JP3CKI (AIZAWA Hina) RPM repository:
  • # curl -sL https://rpm.fetus.jp/jp3cki.repo -o /etc/yum.repos.d/jp3cki.repo
  • # yum-config-manager --enable jp3cki jp3cki-h2o-2.1
  1. Install packages:
  • # yum install -y ImageMagick brotli git h2o jpegoptim php70-php-cli php70-php-fpm php70-php-gd php70-php-intl php70-php-json php70-php-mbstring php70-php-mcrypt php70-php-opcache php70-php-pdo php70-php-pecl-msgpack php70-php-pecl-zip php70-php-pgsql php70-php-xml php70-runtime pngcrush rh-nodejs4-npm rh-postgresql95-postgresql rh-postgresql95-postgresql-server

Create and switch user

  1. Create user: (Skip this step if already created at install-time.)
  • # useradd alice (alice should replaced to your name)
  1. Change home directory's permission: (If not, H2O web server returns 403 forbidden later.)
  • # chmod 701 /home/alice
  1. Switch user to alice:
  • # su - alice
    • The prompt will be changed to $.

Setup user's account and the project

  1. Setup user's environment to use some application:
  • $ echo 'source /opt/remi/php70/enable' >> .bashrc
  • $ echo 'source /opt/rh/rh-nodejs4/enable' >> .bashrc
  • $ echo 'source /opt/rh/rh-postgresql95/enable' >> .bashrc
  1. Reload user's environment:
  • $ source .bashrc
  1. Test it:
  • $ php -v ("PHP 7.0.8 (cli)" or something will be display.)
  • $ node -v ("v4.4.2" or something will be display.)
  • $ psql --version ("psql (PostgreSQL) 9.5.2" or something will be display.)
  1. Clone the source:
  • $ git clone https://github.com/fetus-hina/stat.ink.git (This URL can replace to your forked project URL)
  1. Initialize the project:
  • $ cd stat.ink
  • $ make init (May take a VERY LONG TIME)
  1. Get the DB password: (The password is auto-generated in previous step)
  • $ cat config/db.php
    • The db configuration will be displayed. Find the password and memorize it.
  1. Back to root account:
  • $ exit

Setup database

  1. Initialize DB structure:
  • # sudo -u postgres scl enable rh-postgresql95 -- initdb --pgdata=/var/opt/rh/rh-postgresql95/lib/pgsql/data --encoding=UNICODE --locale=en_US.UTF8
  1. Edit client-authentication settings:
  • # echo 'local all all peer' > /var/opt/rh/rh-postgresql95/lib/pgsql/data/pg_hba.conf
  • # echo 'host all all 127.0.0.1/32 md5' >> /var/opt/rh/rh-postgresql95/lib/pgsql/data/pg_hba.conf
  • # echo 'host all all ::1/128 md5' >> /var/opt/rh/rh-postgresql95/lib/pgsql/data/pg_hba.conf
    • Note: First command has > and other commands have >>. THIS IS A IMPORTANT THING. (First one is overwrite the file. Second one is append to the file.)
  1. Start the db server:
  • # systemctl enable rh-postgresql95-postgresql.service (Mark as an auto-started daemon)
  • # systemctl start rh-postgresql95-postgresql.service (Start it)
  1. Create a db user ("role"):
  • # sudo -u postgres scl enable rh-postgresql95 -- createuser -DRSP statink
    • The prompt Enter password for new role: will be displayed. You should input the DB password that memorized previous section.
  1. Create a db:
  • # sudo -u postgres scl enable rh-postgresql95 -- createdb -E UNICODE -O statink -T template0 statink

Setup the project, again

  1. Switch to the user:
  • # su - alice
  1. Change "current" directory to project's directory.
  • $ cd stat.ink
  1. Run make command:
  • $ make
  1. DB test: (Update stages information)
  • $ ./yii splapi/map-update
    • If the db works, it will be display like below:

      regular...
      Querying http://splapi.retrorocket.biz/regular ...
      count(new_data) = 1875
      Converting to insert data...
      inserting...
      done.
      gachi...
      Querying http://splapi.retrorocket.biz/gachi ...
      count(new_data) = 1875
      Converting to insert data...
      inserting...
      done.
      splatfest...
      Querying http://splapi.retrorocket.biz/fes ...
      new data for [ボケ vs ツッコミ]
      new data for [イカ vs タコ]
      new data for [愛 vs おカネ]
      new data for [山の幸 vs 海の幸]
      new data for [赤いきつね vs 緑のたぬき]
      new data for [カンペキなカラダ vs カンペキな頭脳]
      new data for [ポケットモンスター 赤vs緑]
      new data for [ガンガンいこうぜ vs いのちだいじに]
      new data for [ツナマヨネーズ vs 紅しゃけ]
      new data for [オシャレなパーティー vs コスプレパーティー]
      new data for [きのこの山 vs たけのこの里]
      
  1. Back to root user and say "Yay!"
  • $ exit

Setup PHP (PHP-FPM; FastCGI Process Manager)

  1. Change directory to /etc/opt/remi/php70/php-fpm.d:
  • # cd /etc/opt/remi/php70/php-fpm.d
  1. Edit the config file: (Replace process owner name, "apache" to "alice" (i.e. your account name))
  • # perl -i -pe 's/^user = apache/user = alice/' www.conf
  1. Start it:
  • # systemctl enable php70-php-fpm
  • # systemctl start php70-php-fpm
  1. Check running:
  • # ps aux | grep php-fpm
    • Some lines will be displayed, start with "alice(your account name)" and end with "php-fpm: pool www" like alice 13968 0.0 0.6 403688 7116 ? S 04:53 0:00 php-fpm: pool www
  • # netstat -ln | grep ':9000'
    • A line will be displayed like tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN

Setup H2O web server

  1. Copy configuration file from the project:
  • # cp -n /home/alice/stat.ink/docker/h2o/h2o.conf /etc/h2o/h2o.conf
  1. Adjust directory name: (/home/statink to /home/alice(your home directory))
  • # perl -i -pe 's#/home/statink#/home/alice#g' /etc/h2o/h2o.conf
  1. Start it:
  • # systemctl enable h2o
  • # systemctl start h2o

Test running

  1. Switch user to alice: (optional, but recommended)
  • # su - alice
  1. Request to server:
  • $ curl http://127.0.0.1/
    • Raw HTML document will be displayed.