wordpress 更新のやり方。バックアップの取り方
wordpressの更新を行う前にデータベースをバックアップしておくこと。
データベースの
ruby on rails 5 ではまったこと→あとで調べる
LoginController 作ってるとき
ActionController::InvalidAuthenticityToken error
に遭遇した。
ruby - Rails 5 ActionController::InvalidAuthenticityToken error - Stack Overflow
に解決策があったので参考にした。
protect_from_forgery prepend: true, with: :exception
をLoginController クラスの直下に記述したらうまくいった。意味はあとで調べる
SSHの設定まとめ(VPSにSSH接続する)
ssh-keygen で秘密鍵(id_rsa)と公開鍵(id_rsa.pub)を作成する。
鍵の名前は任意につけられるので-f オプションで覚えやすい名前にしておく。
ssh-keygen -t rsa -b 4096 -f sakura_rsa -C 'sakura'
- Cオプションはコメントをつけられる。
この場合、sakura_rsa(秘密鍵)とsakura_rsa.pub(公開鍵)が作成される。
sakura_rsa.pubの方をVPSサーバーにアップロードし、あらかじめホームディレクトリ~/に作成しておいた~/.sshに格納する。
scp -o PreferredAuthentications="password" -P 22 sakura_rsa.pub user@xxx.xxx.xxx.xxx:~/.ssh/
- Pオプションはポート番号指定。
- oオプションでパスワードでログインするという意味。
#VPSサーバー側 chmod 700 .ssh chmod 600 .ssh/sakura_rsa.pub
という権限にしておく。これをしないと接続できない。
#サーバー側の/etc/ssh/sshd_config PasswordAuthentication no PermitEmptyPasswords yes
としておくとパスワードなしでログインできるようになる。
うまくsshの設定ができないとき
ssh host -v
- v 処理の詳細を表示してくれるのでdebugしやすい。
Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
とか出るときは、サーバー側のログを見てみる。
sudo tail /var/log/secure
vagrant チートシート
ちょっと便利なチートシート。主に覚書。
vagrant ssh-config --host 192.168.33.10
で ~/.ssh/configに以下のように書き込まれるので
Host 192.168.33.10 HostName 127.0.0.1 User vagrant Port 2200 UserKnownHostsFile /dev/null StrictHostKeyChecking no PasswordAuthentication no IdentityFile /Users/xxxxx/Vagrant/ansibleCentOS72/.vagrant/machines/default/virtualbox/private_key IdentitiesOnly yes LogLevel FATAL
ssh 192.168.33.10
でsshアクセスできる。
ruby on railsは、うまく動作させるまでが結構大変
mysql2はバージョン0.3.21を使うべし 0.4.5は動かない。
rspecのバージョンは3.4を使うべし、これで動いた。
centos7への
mysql5.6のインストール・設定を書いておく
sudo yum -y localinstall http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm sudo yum remove mariadb-libs sudo rm -rf /var/lib/mysql/ yum repolist all | grep mysql sudo yum -y install yum-utils sudo yum-config-manager --disable mysql57-community sudo yum-config-manager --enable mysql56-community sudo yum -y install mysql-community-server sudo systemctl start mysqld sudo systemctl enable mysqld /usr/bin/mysqladmin -u root password 'root' sudo yum install mysql-devel
ローカル開発環境なのでmysqlのパスワードはrootにしているが、実際は難しいのにしましょう。環境変数で設定する。
Gemfile
source 'https://rubygems.org' ruby '2.1.0' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '4.1.0' # Use mysql as the database for Active Record gem 'mysql2', '~> 0.3.21' # Use SCSS for stylesheets gem 'sass-rails', '~> 4.0.3' # Use Uglifier as compressor for JavaScript assets gem 'uglifier', '>= 1.3.0' # Use CoffeeScript for .js.coffee assets and views gem 'coffee-rails', '~> 4.0.0' # See https://github.com/sstephenson/execjs#readme for more supported runtimes # gem 'therubyracer', platforms: :ruby # Use jquery as the JavaScript library gem 'jquery-rails' # Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks gem 'turbolinks' # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder gem 'jbuilder', '~> 2.0' # bundle exec rake doc:rails generates the API under doc/api. gem 'sdoc', '~> 0.4.0', group: :doc # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring gem 'spring', group: :development # Use ActiveModel has_secure_password # gem 'bcrypt', '~> 3.1.7' # Use unicorn as the app server # gem 'unicorn' # Use Capistrano for deployment # gem 'capistrano-rails', group: :development # Use debugger # gem 'debugger', group: [:development, :test] gem 'therubyracer', platforms: :ruby gem 'bcrypt', '~> 3.1.7' gem 'nokogiri', '~> 1.6.1' gem 'rails-i18n', '~> 4.0.1' group :test do gem 'rspec-rails', '~> 3.4' gem 'spring-commands-rspec', '~> 1.0.1' gem 'capybara', '~> 2.2.1' gem 'factory_girl_rails', '~> 4.4.1' gem 'database_cleaner', '~> 1.2.0' end
ansibleをサックと簡単に使うんよ
ansibleでvagrantの開発環境をサックと整備したいということで色々やってみた。
ansible_localというのでvagrant内にansibleをインストールして、そこで、playbookに記述した内容を実行する。
ruby on railsの開発環境を構築してみた。
Vagrantファイルのあるところに
play_book.yml
hosts
ansible.cfg
の3つを用意する。
play_book.yml
--- - hosts: all become: yes user: vagrant tasks: - yum: name={{item}} state=latest with_items: - gcc - zlib-devel - openssl-devel - libffi-devel - readline-devel - name: install git yum: name=git state=latest - git: > repo=https://github.com/sstephenson/rbenv.git dest=/home/vagrant/.rbenv/ - git: > repo=https://github.com/sstephenson/ruby-build.git dest=/home/vagrant/.rbenv/plugins/ruby-build/ - file: path=/home/vagrant/.rbenv owner=vagrant state=directory recurse=yes - lineinfile: dest: /home/vagrant/.bashrc line: export PATH=$PATH:$HOME/.rbenv/bin:$HOME/.rbenv/shim - lineinfile: dest: /home/vagrant/.bashrc line: eval "$(rbenv init -)" - shell: source $HOME/.bashrc - shell: rbenv install -v 2.1.5 become: no - shell: rbenv rehash become: no - shell: rbenv global 2.1.5 become: no - shell: /usr/bin/bash -l -c '$HOME/.rbenv/shims/gem install bundler --no-document' become: yes become_user: vagrant - shell: /usr/bin/bash -l -c '$HOME/.rbenv/shims/gem install rails -v 4.1.0' become: yes become_user: vagrant - yum: name={{item}} state=latest with_items: - ruby-devel - rubygems
hosts
192.168.33.10 ansible_connection=local
ansible.cfg
[defaults] host_key_checking = no executable = /bin/bash -l [ssh_connection] ssh_args = -o ControlMaster=auto -o ControlPersist=60s -o UserKnownHostsFile=/dev/null -o IdentitiesOnly=yes
Vagrantfile
Vagrant.configure("2") do |config| config.vm.box = "CentOS72" config.vm.network "private_network", ip: "192.168.33.10" config.vm.provision :ansible_local do |ansible| ansible.playbook = 'play_book.yml' ansible.verbose = true ansible.install = true ansible.limit = 'all' ansible.inventory_path = 'hosts' end end