-
Notifications
You must be signed in to change notification settings - Fork 10
WebFaction Django Python tips notes
Misc. notes working my way through Django/Python dev setup on WebFaction.
Add this to .bash_profile
:
# Default Python
# http://docs.webfaction.com/software/python.html#creating-a-python-alias
alias python=python3.4
Reload your changes:
$ source ~/.bash_profile
Add this to .bash_profile
:
# Default pip
alias pip=pip3
Reload your changes:
$ source ~/.bash_profile
First, in your home directory, make:
$ mkdir -p ~/.virtualenvs
In your .bash_profile
, append this:
# Default Python
# http://docs.webfaction.com/software/python.html#creating-a-python-alias
alias python=python3
# Default pyvenv
alias pyvenv=pyvenv-3
# Default pip
alias pip=pip3
… and then reload your profile:
$ source ~/.bash_profile
Create the environment:
$ pyvenv ~/.virtualenvs/repower
Activate:
$ source ~/.virtualenvs/repower/bin/activate
Deactivate (when activated):
$ deactivate
Note, pip
comes with Python 3.4 pyvenv:
$ which pip
~/.virtualenvs/repower/bin/pip
Nice!
To make it quick, add an alias to your .bash_profile
:
# Simplify pyvenv activation for "repower" environment:
alias repower='source ~/.virtualenvs/repower/bin/activate'
And then reload:
source ~/.bash_profile
Now:
$ repower
Now you can use pip
(in the venv
) to install dependencies/packages.
Append this to ~/username/.virtualenvs/repower/bin/activate
:
export DJANGO_SETTINGS_MODULE="repower.settings.production"
echo $DJANGO_SETTINGS_MODULE
And, optionally:
$ source ~/.bash_profile
Now, when activating the virtual environment, you'll see the settings echoed upon instantiation:
$ repower
repower_root.settings.production
(repower) [mhulse@web419 repower]$
Important: Dont’d forget to swap production
for local
if developing locally.
Do this:
$ ssh-keygen
# No pass (though, it's recommended)
$ chmod 644 ~/.ssh/id_rsa.pub
$ ssh-agent bash
$ ssh-add
Now we need to add the public key to BitBucket
- Log in to Bitbucket.
- Click on your user icon and choose ‘Manage account‘ tab
- Under the ‘SSH keys‘ pane, copy and paste
cat ~/.ssh/id_rsa.pub | pbcopy
(pbcopy
does not work on WebFaction) the text from your public key file (~/.ssh/id_rsa.pub
) into the text input box and click the ‘Add key’ button (remove any extra line endings). - In the
.ssh
directory, add a file namedconfig
(no extension) with these contents (tabs are stripped for some reason, sorry):
Host bitbucket.org
IdentityFile ~/.ssh/id_rsa
- Run
$ source ~/.bash_profile
- Check if everything is working:
$ ssh -T [email protected]
; you should get this back:
conq: logged in as tutorials.
You can use git or hg to connect to Bitbucket. Shell access is disabled.
Verify that the command returns your account name.
- Add this to your Git repo's
.git
config (tabs are being stripped, sorry):
[remote "origin"]
url = [email protected]:user/repo.git
fetch = +refs/heads/*:refs/remotes/origin/*
Here's a complete example (tabs stripped, sorry):
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
url = [email protected]:user/repo.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
[user]
email = [email protected]
name = First Last
[push]
default = simple
- Log out and back in to the server. You should now be able to push/pull without passwords.
If you see:
Address already in use: make_sock: could not bind to address
And there's a port number output, like 20261
, then, do this:
$ netstat -ltnp | grep ':20261'
Find the process number and kill
it.
Put in .bash_profile
or .bashrc
:
# Restart Apache:
alias arest='~/webapps/appname_root/apache2/bin/restart'
# Server and HTTP error logs:
alias herr='tail -f -n 500 ~/logs/frontend/error_appname.log'
alias serr='tail -f -n 500 ~/logs/user/error_appname_root.log'
… and reload your profile by sourcing it.