Last active
December 30, 2021 06:31
-
-
Save TakayoshiMiyamoto/14ba0e2b2e3c6f49525e to your computer and use it in GitHub Desktop.
Vagrant, Ubuntu14.04, uWSGI, Nginx, Python3.5, Flask, MariaDB first settings.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Versions: | |
# Vagrant: 1.8.1 | |
# Ubuntu: 14.04 | |
# uWSGI: 2.0.12 | |
# Nginx: 1.8.1 | |
# Python: 2.7.6, 3.5.1 | |
# Flask: 0.10.1 | |
# MariaDB: 5.5.46 | |
# My computer: MacOSⅩ 10.10.5 (Yosemite) | |
# VM: VirtualBox 5.0.14 | |
# ************************************************ | |
# Vagrant settings | |
# ************************************************ | |
vim Vagrantfile | |
>>> | |
config.vm.network :private_network, ip: "192.168.33.11" | |
<<< | |
vagrant reload | |
vagrant ssh | |
# ************************************************ | |
# Nginx install | |
# ************************************************ | |
# Add repository | |
sudo add-apt-repository ppa:nginx/stable | |
# Update and upgrade | |
sudo apt-get update | |
sudo apt-get -y upgrade | |
# Install | |
sudo apt-get install -y nginx | |
# Wake up! | |
sudo service nginx start | |
# Check the nginx page in the browser | |
http://192.168.33.11/ # -> Welcome to nginx! | |
# ************************************************ | |
# Python 3.5 install | |
# ************************************************ | |
# Add repository | |
sudo add-apt-repository ppa:fkrull/deadsnakes | |
# Update | |
sudo apt-get update | |
# Install | |
sudo apt-get install -y python3.5 | |
cd /usr/bin | |
sudo rm python3 # Remove the symbolic | |
sudo ln -s python3.5 python3 # Add symbolic to python3 | |
# Check the python version | |
python3 -V | |
Python 3.5.1 | |
python -V | |
Python 2.7.6 | |
# ************************************************ | |
# Vagrant settings | |
# ************************************************ | |
# Create flask project folder | |
sudo mkdir -p /var/www/my_proj | |
# Exit | |
exit | |
# Edit Vagrantfile | |
vim Vagrantfile | |
>>> | |
config.vm.synced_folder "/Users/Developer/Flask_Projects/my_proj", "/var/www/my_proj" | |
<<< | |
# Make local sync folder | |
mkdir /Users/Developer/Flask_Projects/my_proj | |
# Reload | |
vagrant reload | |
vagrant ssh | |
# ************************************************ | |
# Create flask project | |
# ************************************************ | |
# Project directory owner setting | |
sudo chown -R vagrant:vagrant /var/www/my_proj/ | |
# Make venv | |
python3 -m venv --without-pip /var/www/my_proj/venv | |
# Active | |
source /var/www/my_proj/venv/bin/activate | |
# Check python version | |
python -V # -> Python 3.5.1 | |
mkdir ~/src | |
cd ~/src | |
# Installing pip | |
curl -O https://pypi.python.org/packages/source/s/setuptools/setuptools-3.5.1.tar.gz | |
tar xvfz setuptools-3.5.1.tar.gz | |
cd setuptools-3.5.1/ | |
python setup.py install | |
cd .. | |
curl -O https://pypi.python.org/packages/source/p/pip/pip-8.0.2.tar.gz | |
tar xvfz pip-8.0.2.tar.gz | |
cd pip-8.0.2/ | |
python setup.py install | |
# Install flask | |
cd /var/www/my_proj | |
source /var/www/my_proj/venv/bin/activate | |
pip install flask | |
# Write to requirements.txt | |
(venv)$ pip freeze > requirements.txt | |
# Making Hello World page | |
vim /var/www/my_proj/hello.py | |
>>> | |
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
from flask import Flask | |
app = Flask(__name__) | |
@app.route('/') | |
def hello(): | |
return 'Hello, World!' | |
if __name__ == '__main__': | |
app.run(host='0.0.0.0', port=8080) | |
<<< | |
# Wake up! | |
python /var/www/my_proj/hello.py | |
# Check the flask page in the browser | |
http://192.168.33.11:8080 # -> Hello, World! | |
# Remove nginx default site symbolic | |
sudo rm /etc/nginx/sites-enabled/default | |
# Making flask application nginx conf | |
vim /var/www/my_proj/nginx.conf | |
>>> | |
server { | |
listen 80; | |
server_name localhost; | |
charset utf-8; | |
client_max_body_size 75M; | |
location / { try_files $uri @flaskapp; } | |
location @flaskapp { | |
include uwsgi_params; | |
uwsgi_pass unix:/tmp/uwsgi.sock; | |
} | |
} | |
<<< | |
# Add symbolic to nginx default site | |
sudo ln -s /var/www/my_conf/nginx.conf /etc/nginx/sites-enabled/ | |
# Restart nginx | |
sudo service nginx restart | |
# ************************************************ | |
# uWSGI install | |
# ************************************************ | |
# Deactive venv | |
deactivate | |
# Check python version | |
python -V # -> Python 2.7.6 | |
# Install the packages needed to build the uWSGI | |
sudo apt-get install -y build-essential python3-dev | |
sudo apt-get install -y build-essential python3.5-dev | |
# Making venv of uWSGI | |
sudo -s # vagrant -> root | |
python3 -m venv --without-pip /opt/venv/uwsgi | |
source /opt/venv/uwsgi/bin/activate | |
cd ~/src/setuptools-3.5.1/ | |
python setup.py install | |
cd ../pip-8.0.2/ | |
python setup.py install | |
# Install uWSGI | |
pip install uwsgi | |
# Make uWSGI log directory | |
sudo mkdir -p /var/log/uwsgi | |
sudo chown -R vagrant:vagrant /var/log/uwsgi | |
# ************************************************ | |
# uWSGI settings | |
# ************************************************ | |
# Make uWSGI ini file | |
vim /var/www/my_proj/uwsgi.ini | |
>>> | |
[uwsgi] | |
base = /var/www/my_proj | |
app = hello | |
module = %(app) | |
virtualenv = /var/www/my_proj/venv | |
pythonpath = %(base) | |
socket = /tmp/uwsgi.sock | |
chmod-socket = 666 | |
callable = app | |
logto = /var/log/uwsgi/%n.log | |
<<< | |
# Wak...ry) | |
uwsgi --ini /var/www/my_proj/uwsgi.ini | |
# Check the browser | |
http://192.168.33.11/ # -> Hello, World! | |
# ************************************************ | |
# MariaDB install | |
# ************************************************ | |
# Deactivate | |
deactivate | |
sudo rm -rf /var/lib/mysql | |
sudo apt-get install -y python-apt | |
sudo apt-get install -y apt-file | |
sudo apt-file update | |
sudo apt-file search add-apt-repository | |
sudo apt-get install -y software-properties-common | |
sudo apt-get install -y mariadb-server | |
sudo service mysql start | |
# Check mariadb | |
mysql --version | |
mysql -u root -p | |
# mysqlclient install | |
sudo apt-get install libmysqlclient-dev | |
source /var/www/my_proj/venv/bin/activate | |
(venv)$ pip install mysqlclient | |
# Check mysqlclient | |
pip freeze # -> mysqlclient==1.3.7 | |
# EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment