Code Monkey home page Code Monkey logo

python-vagrant-centos7's Introduction

A CentOS 7.6 Vagrant Box with Python 3.6 via Ansible

Aging Repository Notice

This repository has not been updated in quite some time. Most developers on our team have moved on to different forms of development: local, WSL-2 Ubuntu, on-server, and Docker. Python 3.6 will shortly be end-of-life. We keep this repository here for reference, but recommend looking for other development solutions.

What's in the Box

  • Apache 2.4, with mod_wsgi for running Django
  • Microsoft ODBC & FreeTDS drivers for MS SQL Server
  • PostgreSQL Drivers & Server

This repository contains a CentOS 7.6 box for Vagrant. Python 3.6 is installed alongside the system Python (2.7.5). The Vagrant config uses Ansible roles to configure the box for the development environment, that should also be (mostly) suitable for setting up a production server. Cookiecutter and Pygments are installed with the system Python, and bash aliases exist to venv for mkvirtualenv, workon and cdsitepackages (for those used to virtualenvwrapper shortcuts).

PostgreSQL 10 server is installed locally for full-stack local development. MS SQL is also supported as a Django database backend with either the Microsoft provided ODBC driver or the FreeTDS ODBC Driver to an external SQL Server. wkhtmltopdf is installed for compatibility with Python's PDF kit.

Django 1.11 or greater is recommended at the time of this writing for new projects. Django 1.11 is an LTS (Long Term Support) release, meaning it will be actively supported with bug fixes and security patches until at least April, 2020 (and probably longer): https://www.djangoproject.com/download/#supported-versions

Compatibility & Prerequisites to Install

Windows

Mac

Linux

  • VirtualBox 6.0.8 can be downloaded here: https://www.virtualbox.org/wiki/Linux_Downloads
    • Builds are provided for Debian, Ubuntu, openSUSE, Fedora, Oracle Linux, CentOS/RHEL, and vanilla Linux.
  • Vagrant 2.2.5 can be downloaded here: https://www.vagrantup.com/downloads.html
    • Builds are provided for Debian/Ubuntu, CentOS/RHEL, Arch, and vanilla Linux.
  • On newer machines, ensure that you have virtualization enabled in BIOS (duckduckgo it for your machine's model).

Fedora 25, CentOS 7

These are available via the package manager.

$ sudo dnf install vagrant
$ sudo dnf install VirtualBox

Additional Roles Not Installed by Default

The Ansible playbook for the installation is located at provisioning/vagrant_playbook.yml. Several additional roles are commented out that can be added, including elastic_search, redis, httpd (with httpd_mod_wsgi), nodejs, and a yum_update role. These are not included by default, but can be uncommented if you wish you use them.

Get Started

  • Create and add a public SSH key to your git server (GitHub, GitLab, etc).
  • Clone the repository and bring up the virtual development environment. The first time you install the box, "vagrant up" will take a little while. Grab a cup of coffee or something!
  • You may want to use a host name for your domain; for example, if you're a member of The Wharton School, you may want to use the command VAGRANT_HOSTNAME="vagrant.wharton.upenn.edu" vagrant up below instead of vagrant up. If you don't provide a hostname, you will be prompted for one. If you don't have one, feel free to use vagrant.example.com.
  • The Vagrant plugin vagrant-vbguest will cause problems with the shared folder in most cases. Please uninstall the plugin first if you have it installed with vagrant plugin uninstall vagrant-vbguest.
git clone https://github.com/wharton/python-vagrant-centos7.git
cd python-vagrant-centos7
vagrant up
vagrant ssh

Fedora 25, CentOS 7

Check Vagrantfile and make sure the port forwarding settings will work for your use case. You may wish to forward the guest VM port 80 to something other than port 80 on the host, e.g. 8888.

config.vm.network "forwarded_port", guest: 80, host: 8888, auto_correct: false

Replace the the vagrant up line from above with the following.

$ vagrant up --provider=virtualbox 

Sit back, and let the installation complete.

  • You can also add the host name to your computer's hosts file. Your hosts file should be located at:

    • Mac / Linux: /etc/hosts
    • Windows: %SystemRoot%\system32\drivers\etc\hosts

Add this line (with the appropriate host name, if you changed it):

192.168.99.100  vagrant.my.domain.com

Default installation creates

default: SSH address: 127.0.0.1:2222
default: SSH username: vagrant
default: SSH auth method: private key
$ vagrant ssh

Another, less desirable, option for SSH'ing into the vagrant box.. (this requires the use of the default password, vagrant)

$ ssh [email protected] -p 2222

At this point, you should change the default password for the vagrant user. You may also want to add/remove users soon.

Using PostgreSQL & Creating a New Database for a Django Project

The Vagrant box comes with PostgreSQL 9.6. The vagrant user is set up as a PostgreSQL superuser (in addition to the postgres user).

$ psql
psql (10.7)
Type "help" for help.

vagrant=# \?
...
vagrant=# CREATE USER my_django_user WITH PASSWORD 'my_django_password';
CREATE ROLE
vagrant=# CREATE DATABASE my_django_db WITH OWNER my_django_user;
CREATE DATABASE
vagrant=# \q

Setting Up Django & virtualenv

First, change to the directory set aside to hold user projects.

$ cd projects

Next, create a new virtual environment for your Django project:

$ mkvirtualenv django-project

Next, within this virtualenv, install django, django-extensions, and pygraphviz:

(django-project) [vagrant@vagrant django-project]$ pip install django django-extensions pygraphviz

Now, create a new Django project and enter its directory:

(django-project) [vagrant@vagrant django-project]$ django-admin startproject myproject
(django-project) [vagrant@vagrant django-project]$ cd myproject

Creating ERDs of Django Models

The django-extensions app can build handy Entity Relationship Diagrams for Django apps, even your entire project. The pre-requisites for the Python packages are included with this Vagrant box.

An example ERD with three Django apps.

First, within your Django project's virtualenv, install django-extensions and pygraphviz:

 (django-project) [vagrant@vagrant django-project]$ pip install django-extensions pygraphviz

Next, add django_extensions to your INSTALLED_APPS. Then you can create the diagrams; to create a PNG of all models in your Django project.

$ ./manage.py graph_models -a -g -o project-erd.png

Or, to just do a few Django apps:

$ ./manage.py graph_models users faculty courses -g -o users-faculty-courses.png

Windows 10: Forwarding Port 80 for Testing Apache

In Windows 10, the "World Wide Web Publishing Service" automatically starts on port 80. You can disable it so Vagrant can forward port 80.

  • Click Start, type "Services" and open Services.
  • Scroll down to World Wide Web Publishing Service. Right click and go into Properties.
  • Change "Startup type" to be Manual.
  • Click the "Stop" button.
  • Click "OK".

Maintainer:

Contributors:

python-vagrant-centos7's People

Contributors

clayball avatar flipperpa avatar frankwiles avatar polyatomicbrian avatar rgs258 avatar seidelma avatar shawnzam avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-vagrant-centos7's Issues

pip not using 3.5 by default

pip install django-extensions pygraphviz

Produces the following exception:

Exception:
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/usr/lib/python2.7/site-packages/pip/commands/install.py", line 326, in run
    strip_file_prefix=options.strip_file_prefix,
  File "/usr/lib/python2.7/site-packages/pip/req/req_set.py", line 742, in install
    **kwargs
  File "/usr/lib/python2.7/site-packages/pip/req/req_install.py", line 834, in install
    strip_file_prefix=strip_file_prefix
  File "/usr/lib/python2.7/site-packages/pip/req/req_install.py", line 1037, in move_wheel_files
    strip_file_prefix=strip_file_prefix,
  File "/usr/lib/python2.7/site-packages/pip/wheel.py", line 346, in move_wheel_files
    clobber(source, lib_dir, True)
  File "/usr/lib/python2.7/site-packages/pip/wheel.py", line 317, in clobber
    ensure_dir(destdir)
  File "/usr/lib/python2.7/site-packages/pip/utils/__init__.py", line 83, in ensure_dir
    os.makedirs(path)
  File "/usr/lib64/python2.7/os.py", line 157, in makedirs
    mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/usr/lib/python2.7/site-packages/django_extensions'

Python 2.7 is being referenced.

I'll update the README file.

Not sure if making changes to the Vagrantfile or wherever would provide a fix for this or not.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.