Configuration

Maksudur Rahman Maateen edited this page Jan 23, 2016 · 2 revisions

#Configuration

Hope you have already gone through Installation page and after that come here. If not, please gone through Installation page first.

Note: I using Ubuntu 14.04 LTS terminal to play with following commands.

####Creating a Database in MySQL/MariaDB

  • Log into MySQL/MariaDB using the following command:
mysql -u root -p
  • Type in the password you set up during installation to continue. We will create a database "shortener". Create the database with the following command:
CREATE DATABASE shortener;
  • The SQL syntax is as follows to create a user named myusername for the database shortener, created in previous command, with a password called 'mypasword'. The following will also grant myusername full rights:
GRANT ALL ON shortener.* TO myusername@localhost IDENTIFIED BY 'mypasword';
  • WOW! We have done all. Now exit the from the client.
exit;

####Configuring config.py

Hope you have found config.py already. It is in Py-URL-Shortener folder, where requirements.txt exists. Open it in your favorite editor. The first line looks as follows:

SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://username:password@host/database'

We will change it accordingly and make it looks like below:

SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://myusername:mypassword@localhost/shortener'

There are still some things you can set. But most of them need to be set up on production. Just read the relevent comment.

####Working with manage.py

Just now, manage.py takes only one arguement 'syncdb' and create all tables already declared in app/models.py.

cd /path/to/Py-URL-Shortener/
python3 manage.py syncdb

Note: Everytime you run 'python3 manage.py syncdb' on your terminal, your previous tables will be dropped and new tables will be created. So play with attention, dude!

####Running and Enjoying

cd /path/to/Py-URL-Shortener/
python3 run.py

Hope you will see the following output on the terminal:

 * Restarting with stat
 * Debugger is active!
 * Debugger pin code: xxx-xxx-xxx

Now open your favorite browser, and hit http://127.0.0.1:5000/. Hope you are seeing the homepage now . (See Screenshots)

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.