2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

さくらの標準OS(CentOS6.9)にnginx/pyenv/virtualenvを入れる [2017年12月版]

Last updated at Posted at 2017-12-14

はじめに

Flask 使ってちょっとした自分用のアプリ作ろうと思ったので久々にさくらでサーバ借りてまずは構成管理をする。Ansible とか Chef とか使ってもいいがスケールする予定も今のところないので一旦手動で諸々セットアップを行う。CentOS7系の場合またいろいろ話が変わるので注意。

nginx

yum repository の登録

/etc/yum.repos.d ディレクトリの中に、以下のファイルを作成。

$ sudo vim /etc/yum.repos.d/nginx.repo
nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/6/$basearch/
gpgcheck=0
enabled=1

yum install

# sudo 権限を持つユーザを仮定
$ sudo yum -y install nginx

pyenv

pyenv-installer を使う

以前は GitHub から入れた気がするが、pyenv-installerなるものがあったのでこちらを利用。

$ curl -L https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer | bash

ちなみに、このコマンドで pyenv-virtualenv もインストールされる。

~/.bash_profile に追記

~/.bash_profile
export PATH="/home/{user}/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"

{user}はユーザ名。

すぐに反映したいので

$ source ~/.bash_profile

依存ライブラリのインストール

yum install gcc gcc-c++ make git openssl-devel bzip2-devel zlib-devel readline-devel sqlite-devel bzip2 sqlite
 zlib-devel bzip2 bzip2-devel readline-devel sqlite sqlite-devel openssl-devel

Python 3.6.3のインストール

一旦 Python 3系の最新安定版である3.6.3をインストールする。

$ pyenv install 3.6.3
$ pyenv rehash
$ pyenv global 3.6.3

virtualenv

pyenv-virtualenv でもいいが、Flask のドキュメント見ても virtualenv を使ってるようだし、ディレクトリで閉じれるので virtualenv にしてみる。余談だが、この二つの差に関してはこちらのページがわかりやすい。

pipでかんたんに

先程インストールしたグローバルな python 3.6.3 に pip で入れてしまう。

$ pip install virtualenv

参考

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?