Ubuntu16.04(Vagrant) x Python3.5 x Django1.9
Vagrant上のUbuntu 16.04にPython 3.5 + Django 1.9の環境を作ります.
Ubuntu
Vagrant上でUbuntu 16.04を用います.
boxはbento/ubuntu-16.04を使用.
# Vagrantfile Vagrant.configure(2) do |config| # The most common configuration options are documented and commented below. # For a complete reference, please see the online documentation at # https://docs.vagrantup.com. # Every Vagrant development environment requires a box. You can search for # boxes at https://atlas.hashicorp.com/search. config.vm.box = "bento/ubuntu-16.04" # ←変更 # Disable automatic box update checking. If you disable this, then # boxes will only be checked for updates when the user runs # `vagrant box outdated`. This is not recommended. # config.vm.box_check_update = false # Create a forwarded port mapping which allows access to a specific port # within the machine from a port on the host machine. In the example below, # accessing "localhost:8080" will access port 80 on the guest machine. config.vm.network "forwarded_port", guest: 8000, host: 8080 # ←変更(Djangoのrunserverができるように) ......
$ cat /etc/issue
# Ubuntu 16.04 LTS \n \l
Python
インストール
$ sudo apt-get install python3 $ sudo apt-get install python3-pip
virtualenv
インストール
$ sudo pip3 install virtualenv virtualenvwrapper
# ~/.bashrc ### Virtualenvwrapper if [ -f /usr/local/bin/virtualenvwrapper.sh ]; then export WORKON_HOME=$HOME/.virtualenvs source /usr/local/bin/virtualenvwrapper.sh fi
環境設定
$ mkvirtualenv mien # myenvという環境を作る $ mkvirtualenv myenv --python=/usr/bin/python2.6 # Pythonのバージョンを指定したい場合 $ workon myenv # myenvという環境ににうつる $(myenv) python --version Python 3.5.1+ # こうなったら成功 $(myenv) deactivate # 環境を抜ける $ workon # 作成した環境の一覧 $ rmvirtualenv myenv # 作成した環境を削除する
Django
インストール
$(myenv) pip install django umemcache $(myenv) python -c "import django; print(django.get_version())" # 1.9.7
アプリを作る
$(myenv) django-admin startproject project-name $(myenv) cd project-name $(myenv) python manage.py runserver 0.0.0.0:8000
ブラウザからlocalhost:8080にアクセスすると,下の画像のようなページにアクセスできるはず!
LAMP環境(CentOS 7, Apache, MariaDB, PHP 7)を構築する
参考サイトの内容を自分のやりたいことにあわせて詰め込んだまとめ.
やってることは参考元に詳しいです.
目次
Summary
ポイント
- Cent OSの公式リポジトリではPHP 5.4が提供されている
- remiリポジトリから最新バージョンをインストールしましょう
- DB接続はPDOで
- phpMyAdminも導入
- DBのセッティング,Composerの導入など,実用で使う直前まで
OS
Vagrant上でCent OSを動かしました.
boxはbento/centos-7.2を使用.
# Vagrantfile Vagrant.configure(2) do |config| # The most common configuration options are documented and commented below. # For a complete reference, please see the online documentation at # https://docs.vagrantup.com. # Every Vagrant development environment requires a box. You can search for # boxes at https://atlas.hashicorp.com/search. config.vm.box = "bento/centos-7.2" # ←変更 ......
$ cat /etc/redhat-release
# CentOS Linux release 7.2.1511 (Core)
結果
$ httpd -v # Server version: Apache/2.4.6 (CentOS) # Server built: Nov 19 2015 21:43:13 $ mysql --version # mysql Ver 15.1 Distrib 5.5.44-MariaDB, for Linux (x86_64) using readline 5.1 $ php -v # PHP 7.0.4 (cli) (built: Mar 2 2016 18:03:26) ( NTS ) # Copyright (c) 1997-2016 The PHP Group # Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
インストール
とりあえずすべてインストールし,起動や設定を軽く行います.
準備
$ sudo yum upgrade
Apache
$ sudo yum install httpd $ sudo systemctl start httpd
ファイアーウォール
httpdを許可しましょう.
$ sudo firewall-cmd --add-service=http --permanent $ sudo firewall-cmd --reload
……と参考元にあったのですが,私は
# FirewallD is not running
と言われてしまいました.boxでもともと設定してあるのかな.
設定
.htaccessを許可
# /etc/httpd/conf/httpd.conf DocumentRoot "/var/www/html" ...... <Directory "/var/www/html"> AllowOverride FileInfo Options # AllowOverride All でもOK ......
ドキュメントルート変更
# /etc/httpd/conf/httpd.conf # DocumentRoot "/var/www/html" DocumentRoot "/var/www/test/public_html" ...... <Directory "/var/www/test/public_html"> # # Possible values for the Options directive are "None", "All", # or any combination of: # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews ......
設定が終わったら再起動しましょう.
$ sudo systemctl restart httpd
MySQL(MariaDB)
$ sudo yum install mariadb mariadb-server mariadb-devel
設定
# /etc/my.cnf [mysqld] character-set-server=utf8 [client] default-character-set=utf8
起動 & 初期設定
$ sudo systemctl start mariadb
$ mysql_secure_installation
コマンドを打った後は,指示通りにすすめればOKです.
わたしはすべてyesで設定しました.
PHP
MariaDB + PDO使用なので,php-mysqlndを追加.また,一緒にComposerもインストール.
$ sudo rpm --import https://raw.githubusercontent.com/remicollet/remirepo/master/remi-release/RPM-GPG-KEY-remi $ sudo yum install yum-utils http://remi.kazukioishi.net/enterprise/remi-release-7.rpm $ sudo yum-config-manager --enable remi-php70 $ sudo yum install php php-mbstring php-intl php-gmp php-mysqlnd composer
設定
# /etc/php.ini [PHP] error_reporting = E_ALL | E_STRICT display_errors on [Date] date.timezone="Asia/Tokyo" [mbstring] mbstring.language = Japanese mbstring.internal_encoding = UTF-8 mbstring.http_input = auto mbstring.http_output = UTF-8 mbstring.encoding_translation = On mbstring.detect_order = auto
phpMyAdmin
準備
$ sudo yum install yum-plugin-priorities
# /etc/yum.repos.d/remi.repo [remi] priority=100 [remi-test] priority=100
インストール
$ sudo yum-config-manager --enable remi remi-test $ sudo yum install phpMyAdmin
アクセス制限
ローカル以外のブラウザからもアクセス可能にする.
# /etc/httpd/conf.d/phpMyAdmin.conf <Directory /usr/share/phpMyAdmin/> AddDefaultCharset UTF-8 <IfModule mod_authz_core.c> # Apache 2.4 Require all granted # ← 変更 </IfModule> ......
DB
今後つくるであろうアプリケーションやphpMyAdminのため,データベースを作ります.
また,ユーザの追加や権限の変更なども行っていきます.
ログイン
MariaDB [(none)]>から始まるコマンドは,以下のようにMariaDBにログインして実行してください.
$ mysql -u root -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 5 Server version: 5.5.44-MariaDB MariaDB Server Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> ......
phpMyAdmin
アカウント名 | pma |
---|---|
パスワード | pma_pass |
で設定していきます.お好みで変更してください.
phpMyAdmin用データベース・ユーザの作成
-- /usr/share/phpMyAdmin/sql/create_tables.sql -- -------------------------------------------------------- -- -- Privileges -- -- (activate this statement if necessary) GRANT SELECT, INSERT, DELETE, UPDATE, ALTER ON `phpmyadmin`.* TO 'pma'@localhost; -- ↑コメントアウトを外す -- -- --------------------------------------------------------
MariaDB [(none)]> source /usr/share/phpMyAdmin/sql/create_tables.sql MariaDB [(none)]> set password for pma@localhost = password('pma_pass'); MariaDB [(none)]> flush privileges;
設定
<!-- /etc/phpMyAdmin/config.inc.php --> <?php ...... /** * phpMyAdmin configuration storage settings. */ /* User used to manipulate with storage */ // $cfg['Servers'][$i]['controlhost'] = ''; // $cfg['Servers'][$i]['controlport'] = ''; $cfg['Servers'][$i]['controluser'] = 'pma'; $cfg['Servers'][$i]['controlpass'] = 'pma_pass'; /* Storage database and tables */ $cfg['Servers'][$i]['pmadb'] = 'phpmyadmin'; $cfg['Servers'][$i]['bookmarktable'] = 'pma__bookmark'; $cfg['Servers'][$i]['relation'] = 'pma__relation'; $cfg['Servers'][$i]['table_info'] = 'pma__table_info'; $cfg['Servers'][$i]['table_coords'] = 'pma__table_coords'; $cfg['Servers'][$i]['pdf_pages'] = 'pma__pdf_pages'; $cfg['Servers'][$i]['column_info'] = 'pma__column_info'; $cfg['Servers'][$i]['history'] = 'pma__history'; $cfg['Servers'][$i]['table_uiprefs'] = 'pma__table_uiprefs'; $cfg['Servers'][$i]['tracking'] = 'pma__tracking'; $cfg['Servers'][$i]['userconfig'] = 'pma__userconfig'; $cfg['Servers'][$i]['recent'] = 'pma__recent'; $cfg['Servers'][$i]['favorite'] = 'pma__favorite'; $cfg['Servers'][$i]['users'] = 'pma__users'; $cfg['Servers'][$i]['usergroups'] = 'pma__usergroups'; $cfg['Servers'][$i]['navigationhiding'] = 'pma__navigationhiding'; $cfg['Servers'][$i]['savedsearches'] = 'pma__savedsearches'; $cfg['Servers'][$i]['central_columns'] = 'pma__central_columns'; $cfg['Servers'][$i]['designer_settings'] = 'pma__designer_settings'; $cfg['Servers'][$i]['export_templates'] = 'pma__export_templates';
アプリケーション
データベース名 | test |
---|---|
アカウント名 | test_user |
パスワード | test_pass |
で設定していきます.お好みで変更してください.
データベース
-- データベース一覧 MariaDB [(none)]> show databases; -- 作成 MariaDB [(none)]> create database test;
ユーザ
-- ユーザ一覧 MariaDB [(none)]> select user,host,user from mysql.user; -- 作成 MariaDB [(none)]> create user 'test_user'@'localhost' identified by 'test_pass'; -- 権限変更 MariaDB [(none)]> grant select,index on test.* to 'test_user'@'localhost'; -- phpMyAdminのアカウントにも権限を与えておく MariaDB [(none)]> grant all on test.* to 'pma'@'localhost';
権限は以下のページなどを参考にどうぞ.
www.dbonline.jp
蛇足
文字化けするのでロケールを変えてみたものの,治らず諦めました.
LANG=C付きで実行すればとりあえずはいけます!
以下ロケール変更方法.
$ sudo localectl set-locale LANG=en_US.utf8
Gnuplot導入
プログラミングに使える英単語
各単語はweblioへリンクしています.ただ適当にURL自動生成させたのでミスがあるかもしれません.
分類,意味におかしなところがある,綴りが違う,この単語追加して!などなにかあればぜひお知らせ下さい.
なんとなく分類してるのでなんともいえませんが,だいたい
- 変数 : 名詞
- 関数 : 動詞
- 状態 : 形容詞
- 接頭辞 : 前置詞+α
という感じになっているはずです
変数
コンピュータ
- binary : 2進の
- hexadecimal(hex) : 16進の
数学
- number(num) : 数
汎用
その他
- angle : 角度
- burst : 連続的に何かがおこるさま(連写など)
- degree : 度
- comment : 意見,見解
- delay : 遅れ
- identification(id) : 識別子
- index(idx) : 索引,目録
- instruction : 説明書き,命令
- limit : 制限
- navigation : 誘導
- node : 結び目,節点,交点,集合点
- size : 大きさ
- time : 時間
- elapsed (time) : 経過時間
関数
- add ↔ remove(加える / 取り除く)
- begin ↔ end, finish(取り掛かる / 完結,段階的な終わり)
- create ↔ destroy(作る / 壊す,破壊する)
- draw ↔ erase(描く / 消す)
- find ↔ lose(見つける / 失う)
- import ↔ export(中に入れる / 外に出す)
- insert ↔ delete(挿入 / 削除)
- start ↔ stop(動く / 止まる)
- open ↔ close(開く / 閉じる)
- push ↔ pull(押す / 引く)
- read ↔ write(読む / 書く)
- allow : 許可する
- ↔ disallow : 禁ずる
- partial : 部分的な
- count : 数える
- encrypt : 暗号化する
- ↔ decrypt
- exit : 抜け出る,出て行く,出口
- force : 強制的に動作させる
- intercept : 傍受する,妨害する,遮る
- rotate : 回転する
- lookup データのテーブルから特定のデータをさがし出す
- parse : 構文解析する
- run : 実行する
- save : 保存する
- separate : 分ける(結びついていたものを区切って別々にする)
- snap : かちっと(〜の状態に)する
- throttle : 減速する,抑える
- wrap : 包む,くるむ
グループ
送る
管理する
- administer : 会社などの運営,公的業務の管理(製品や価格の管理などには使えない)
- care : 世話,介護,(よりよい状態を保つための)手入れ, 扱い
- control : 強制的に制御する,監視・制御による状態の維持,支配する
- direct : 指揮する(対象に直に接したり関係をもつ)
- manege : 監視・制御する(仕事や活動を責任持ってうまく進めていく,なんとかやり遂げる)
- organize : 組織する,系統立てる(一丸となるように管理する)
- regulate : 調整する,統制する(規約を元に取り締まる,なんらかの制御装置の動作)
- supervise : 監督する(対象が適切な状態でふるまうように調節する,規則を元に人や業務の進行を管理)
探す
- find : 探す(曖昧)
- ↔ lose
- extract : 抽出,抜粋(ある条件にあったもの,目的のものを抽出)
- locate : 探しているものが存在する位置を示す,位置を決定する
- lookfor : 無くした物あるいは要求している物や人や場所を捜す
- recover : 障害を取り除き,回復する
- search : 探す(求めているものか厳格に判断)
- seek : 物理的でなく,形のないものごとを探し求める
- 注意 :
作る
始める
状態
接頭辞
参考
- 対義語・反対語で時間を取らないために | WebSpaceの中の人
- プレフィックス(接頭辞)に使えそうなもの | WebSpaceの中の人
- C言語編 - プログラミングに出る!英単語
- 変数・関数名の命名サンプル - wiki - PCスキルの小技・忘却防止メモ
- ボズウェル, ダスティン・フォシェ, トレバー(2012)『リーダブルコード―より良いコードを書くためのシンプルで実践的なテクニック』(角征典訳)オライリー・ジャパン.
アップデート祭り
たくさん久しぶりなことがあります.
まず休日です.久しぶりの休日です.学校がありません.実に1ヶ月以上ぶりな気がします.
久しぶりの休日で,久しぶりに風邪を引きました.久しぶりの休日ですから仕方ありません.
風邪も引いたので,パソコンで遊んでいました.久しぶりのアップデート祭りです.エラー祭りになりました.
これが今回の主題です.アップデート祭りがエラー祭りになった話.
ところで久しぶりすぎてはてな記法をわすれました.
Ruby
RubyGems
$ sudo update_rubygems
Gem
問題発生
$ sudo gem update ERROR: Loading command: update (LoadError) dlopen(/Users/mssr/.rbenv/versions/2.0.0-p353/lib/ruby/2.0.0/x86_64-darwin13.0.2/openssl.bundle, 9): Symbol not found: _SSLv2_client_method Referenced from: /Users/mssr/.rbenv/versions/2.0.0-p353/lib/ruby/2.0.0/x86_64-darwin13.0.2/openssl.bundle Expected in: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib in /Users/mssr/.rbenv/versions/2.0.0-p353/lib/ruby/2.0.0/x86_64-darwin13.0.2/openssl.bundle - /Users/mssr/.rbenv/versions/2.0.0-p353/lib/ruby/2.0.0/x86_64-darwin13.0.2/openssl.bundle ERROR: While executing gem ... (NoMethodError) undefined method `invoke_with_build_args' for nil:NilClass
解決法
ぐぐった結果,Rubyのバージョンを上げると治りそうだということが判明しました.
$ rbenv install 2.1.2 $ rbenv global 2.1.2 $ gem update
Homebrew
Update & Upgrade
$ brew update $ brew upgrade
Doctor
問題発生
$ brew doctor Please note that these warnings are just used to help the Homebrew maintainers with debugging if you file an issue. If everything you use Homebrew for is working fine: please don't worry and just ignore them. Thanks! Warning: Some directories in /usr/local/share/locale aren't writable. This can happen if you "sudo make install" software that isn't managed by Homebrew. If a brew tries to add locale information to one of these directories, then the install will fail during the link step. You should probably `chown` them: /usr/local/share/locale/da /usr/local/share/locale/da/LC_MESSAGES /usr/local/share/locale/fi /usr/local/share/locale/fi/LC_MESSAGES /usr/local/share/locale/ga /usr/local/share/locale/ga/LC_MESSAGES /usr/local/share/locale/id /usr/local/share/locale/id/LC_MESSAGES /usr/local/share/locale/nl /usr/local/share/locale/nl/LC_MESSAGES /usr/local/share/locale/pt_BR /usr/local/share/locale/pt_BR/LC_MESSAGES /usr/local/share/locale/ro /usr/local/share/locale/ro/LC_MESSAGES /usr/local/share/locale/rw /usr/local/share/locale/rw/LC_MESSAGES /usr/local/share/locale/sv /usr/local/share/locale/sv/LC_MESSAGES /usr/local/share/locale/tr /usr/local/share/locale/tr/LC_MESSAGES Warning: Unbrewed header files were found in /usr/local/include. If you didn't put them there on purpose they could cause problems when building Homebrew formulae, and may need to be deleted. Unexpected header files: /usr/local/include/ansidecl.h /usr/local/include/bfd.h /usr/local/include/bfdlink.h /usr/local/include/dis-asm.h /usr/local/include/gdb/jit-reader.h /usr/local/include/symcat.h Warning: Unbrewed .la files were found in /usr/local/lib. If you didn't put them there on purpose they could cause problems when building Homebrew formulae, and may need to be deleted. Unexpected .la files: /usr/local/lib/libbfd.la /usr/local/lib/libopcodes.la Warning: Unbrewed static libraries were found in /usr/local/lib. If you didn't put them there on purpose they could cause problems when building Homebrew formulae, and may need to be deleted. Unexpected static libraries: /usr/local/lib/libbfd.a /usr/local/lib/libopcodes.a Warning: Some installed formula are missing dependencies. You should `brew install` the missing dependencies: brew install cairo glib gobject-introspection harfbuzz icu4c libffi libtool pango pixman Run `brew missing` for more details.
解決法
アクセス権修復
$ sudo chown -R $USER:admin /usr/local/share
依存ツールファイルをインストール
$ brew install cairo glib gobject-introspection harfbuzz icu4c libffi libtool pango pixman
あとのはファイルを消せって書いてある気もしますが,よくわからないのでとりあえず放置で.
Vagrant × Ruby
いろいろできずに困っていたものが,理由もわからずできるようになったのでまとめ.
Vagrantなんかは相当前に入れたのでどうやって自分が導入したのかいまいち記憶にありませんがそこはいろいろで補いつつ.
目次
- Vagrant
- 導入
- Vagrantのコマンドたち
- Ruby + Ruby on Rails
- 参考
Vagrant
導入
とりあえず上の2つをインストール.
boxはvagrantbox.esから.私が入れたのは,CentOS 6.5 x86_64.
list出力してきちんと出てくれば完了です.
(私はコピペした際にうっかりcentos65-x86_64-20140116のままにしちゃいましたが短くしといたほうがあとで便利な気がします)
$ vagrant box add centos65-x86_64-20140116 https://github.com/2creatives/vagrant-centos/releases/download/v6.5.3/centos65-x86_64-20140116.box $ vagrant box list
作業ディレクトリを作成し,そこに移動後以下を行います.
$ vagrant init centos65-x86_64-20140116 $ vagrant up $ vagrant ssh
こんな感じで起動,SSH接続でシェルにアクセスできました.
Vagrantのコマンドたち
$ vagrant -h $ vagrant status // ステータス表示,以下は起動しているとき Current machine states: default running (virtualbox) The VM is running. To stop this VM, you can run `vagrant halt` to shut it down forcefully, or you can run `vagrant suspend` to simply suspend the virtual machine. In either case, to restart it again, simply run `vagrant up`. $ vagrant ssh // マシンにSSH接続 $ vagrant suspend // 保留 $ vagrant resume // 再開 $ vagrant up // 起動 $ vagrant halt // シャットダウン $ vagrant reload // 再起動 $ vagrant destroy // 停止・削除
Ruby + Ruby on Rails
準備
$ sudo yum -y install git $ git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
Git,ればにらを入れます.
rbenvをればにらなんて呼ぶのは私だけだと思いますが見えてしまったものはしょうがない.
パス通し..bash_profileをみれば書き込まれたのがわかると思います.
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile $ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile $ exec $SHELL -l
ruby-build
$ git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
Ruby
$ yum install gcc make openssl-devel $ rbenv install 2.0.0p481 $ rbenv global 2.0.0p481 $ ruby -v ruby 2.0.0p481 (2014-05-08 revision 45883) [x86_64-linux]
Ruby on Rails
$ gem update --system $ gem install rails --no-ri --no-rdoc -V $ rbenv rehash $ rails -v Rails 4.1.1