One way to develop a web application is to use a framework. There are various frameworks, but this time I will use Django which can be developed with Python. Also, I want to create a local environment for testing as a method of building a development environment, so I will create it using Vagrant.
This time we will use Ubuntu as the guest OS. Please install Vagrant in advance. I'm also using VirtualBox as the VM.
Also, "hashicorp / precision64" is used as the vagrant box. If it is not in the Vagrant box, add it to the Vagrant box with the following command.
$ vagrant box add hashicorp/precise64
When running Vagrant, it's a good idea to create a suitable folder and run it in it. Here, we create a folder called ~ / Vagrant / Django and run it there.
$ mkdir -p ~/Vagrant/Django
$ cd ~/Vagrant/Django
$ vagrant init hasjicorp/precise64
Change the settings of the created Vagrant file. Here we want to access Django on port 12345 on localhost (127.0.0.1). Open the Vagrantfile in a suitable editor.
$ vim Vagrantfile
Add the following content in the file.
config.vm.network "forwarded_port", guest: 8000, host: 12345
Start Vagrant under the set conditions.
$ vagrant up
Enter the booted VM.
$ vagrant ssh
Install Django on the booted VM.
First install pip. pip is a package management system for installing and managing packaged software written in Python. It makes it easy to install Django.
vagrant@precise64:~$ sudo apt-get install python-pip
Install Django with pip. Then use django-admin.py to create your project.
vagrant@precise64:~$ sudo pip install Django
vagrant@precise64:~$ sudo django-admin.py startproject spam
My grade of DB is done and the server is operated. Django is running on port 8000, but from the host side it will be accessed from 127.0.0.1:12345 set in Vagrant.
vagrant@precise64:~$ cd spam/
vagrant@precise64:~/spam$ sudo python manage.py migrate
vagrant@precise64:~/spam$ sudo python manage.py runserver 0.0.0.0:8000
You can see that Django is running by accessing the localhost (127.0.0.1:12345) preset in the Vagrant file after booting.
Recommended Posts