Wednesday, 29 June 2016

Install and run Redis on Mac OS - Redis Server Installation and First Run

Following is the recipe to install Redis server on Mac OS using homebrew in a very simple manner:

 $ brew install redis


After installation, you may edit Redis configuration file by going to the path via Mac OS terminal:

$ /usr/local/etc/redis.conf

To start Redis Server using configuration file on Mac OS, use following command:
$ redis-server /usr/local/etc/redis.conf

After running the Redis Server on Mac OS, you can check whether Redis Server is running by opening a new terminal window and enter following command:
$ redis-cli ping

Install and run Redis on Mac OS - Redis Server Installation and First Run

Following is the recipe to install Redis server on Mac OS using homebrew in a very simple manner:

 $ brew install redis


After installation, you may edit Redis configuration file by going to the path via Mac OS terminal:

$ /usr/local/etc/redis.conf

To start Redis Server using configuration file on Mac OS, use following command:
$ redis-server /usr/local/etc/redis.conf

After running the Redis Server on Mac OS, you can check whether Redis Server is running by opening a new terminal window and enter following command:
$ redis-cli ping

The server should reply PONG which means that the server is pinging.

Tuesday, 24 February 2015

MongoDB Correct way to start MongoDB - Error Cannot connect to mongodb errno:61 Connection refused [Solved]

Recently, while involved in full stack Django development and developing an application using Mongodb as database backend, I encountered following error after installing Mongodb on my mac. Ok first, I installed Mongodb by using brew install command:

brew update
brew install mongodb

After installing Mongodb, I tried to access the mongo shell by using mongo command, but I got "Cannot connect to mongodb errno:61 Connection refused error" . Here is the full trace:

alis-air:~ aliraza$ mongo
MongoDB shell version: 2.6.6
connecting to: test
2015-02-24T17:51:36.067+0500 warning: Failed to connect to 127.0.0.1:27017, reason: errno:61 Connection refused
2015-02-24T17:51:36.069+0500 Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed at src/mongo/shell/mongo.js:146
exception: connect failed

I searched for correct ways to start Mongodb on Mac OS. I tried several solutions but the one which worked for me is as follows: In the shell write sudo mongod to start it.

$ mkdir -p /data/db
$ sudo mongod

This started my Mongodb. Next I opened another shell instance (new shell window) and wrote mongo command and it worked without Error Cannot connect to mongodb errno:61 Connection refused! MongoDB starting Problem Solved.

$ mongo
MongoDB shell version: 2.6.6
connecting to: test
Server has startup warnings: 
2015-02-24T18:20:51.384+0500 [initandlisten] 
2015-02-24T18:20:51.384+0500 [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
> 

Friday, 30 January 2015

Django Setting DEBUG = False causes 500 Error - Django 500 error debug false - ALLOWED_HOSTS Problem [SOLVED]

Python Django alirazabhayani Full stack development
Django Debug False 500 error Solved
Being involved in Full Stack Django/Python Web Application Development for 3 years now, I recently deployed my Django application on a test server and encountered Server Error (500) on Django when template debug is set to False. That is in Django settings.py, when I changed DEBUG = FALSE from DEBUG = TRUE, it caused 500 error.

I had upgraded my application from Django 1.4 to Django 1.7. I came to know that 500 error on DEBUG = False error is encountered by everyone using django 1.5 or greater as soon as they change their settings.py to DEBUG = False. Well my problem got solved after reading several blogs and digging deeper in the Django Docs for DEBUG = False ALLOWED_HOSTS settings

What I did was, in settings.py, changed ALLOWED_HOSTS value in the following way:
ALLOWED_HOSTS = ['123.123.198.123']
# Above mentioned IP is not my actual IP. Enter your actual server IP or domain name here. 

If you have a domain name of your server, you may write:
ALLOWED_HOSTS = ['www.example.com']
You can also use a '*' wildcard to allow all hosts. But this is not recommended in the production environment.
ALLOWED_HOSTS = ['*']
You can find a full detail regarding the ALLOWED_HOSTS settings here hidden deep inside django document  

Saturday, 10 January 2015

Django Syncdb Create superuser ValueError: unknown locale: UTF-8 [Solved]

While setting up a new remote server for a new Django Application I am currently working on, I encountered following error as entered yes to create superuser after I entered syncdb command for the first time.
ValueError: unknown locale: UTF-8
Here is the full trace:

(django1.5)[root@DXDS2102 testdjango]# python manage.py syncdb
Creating tables ...
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_groups
Creating table auth_user_user_permissions
Creating table auth_user
Creating table django_content_type
Creating table django_session
Creating table django_site

You just installed Django's auth system, which means you don't have any superusers defined.
Would you like to create one now? (yes/no): yes
ValueError: unknown locale: UTF-8
As I had centOS server for my Django Application, I entered following commands which actually solved this problem:
export LC_CTYPE=en_US.UTF-8
export LC_ALL=en_US.UTF-8
After running the above command I again did syncdb but Django didn't asked me about creating superuser. So for manually creating a superuser, I entered following command:
python manage.py createsuperuser
The django superuser was created without the error of "ValueError: unknown locale: UTF-8".

Tuesday, 6 January 2015

django.core.exceptions.improperlyconfigured error loading mysqldb module no module named mysqldb - Python Django MySQL Error

In order to deal massive (Big) data in one of my applications. I am testing MySQL with MariaDB and TokuDB. Previously I had used PostgreSQL for my applications but the Reporting Engine I am designing requires some unique features to update data faster and retrieve it in an efficient manner. TokuDB being based on Fractal Indexing makes the insertion faster for Bigger Data and keeps the database compressed resulting in efficient use of storage data. While running MySQL MariaDB with Django in my virtual environment, I encountered following error: 


 
django.core.exceptions.improperlyconfigured error loading mysqldb module no module named mysqldb
Full Trace is:
 
(django1.5)alis-air:DjangoMariaDb aliraza$ python manage.py syncdb
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/aliraza/Projects/VirtualEnv/django1.5/lib/python2.7/site-packages/django/core/management/__init__.py", line 453, in execute_from_command_line
    utility.execute()
  File "/Users/aliraza/Projects/VirtualEnv/django1.5/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/aliraza/Projects/VirtualEnv/django1.5/lib/python2.7/site-packages/django/core/management/__init__.py", line 272, in fetch_command
    klass = load_command_class(app_name, subcommand)
  File "/Users/aliraza/Projects/VirtualEnv/django1.5/lib/python2.7/site-packages/django/core/management/__init__.py", line 77, in load_command_class
    module = import_module('%s.management.commands.%s' % (app_name, name))
  File "/Users/aliraza/Projects/VirtualEnv/django1.5/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "/Users/aliraza/Projects/VirtualEnv/django1.5/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 8, in <module>
    from django.core.management.sql import custom_sql_for_model, emit_post_sync_signal
  File "/Users/aliraza/Projects/VirtualEnv/django1.5/lib/python2.7/site-packages/django/core/management/sql.py", line 9, in <module>
    from django.db import models
  File "/Users/aliraza/Projects/VirtualEnv/django1.5/lib/python2.7/site-packages/django/db/__init__.py", line 40, in <module>
    backend = load_backend(connection.settings_dict['ENGINE'])
  File "/Users/aliraza/Projects/VirtualEnv/django1.5/lib/python2.7/site-packages/django/db/__init__.py", line 34, in __getattr__
    return getattr(connections[DEFAULT_DB_ALIAS], item)
  File "/Users/aliraza/Projects/VirtualEnv/django1.5/lib/python2.7/site-packages/django/db/utils.py", line 93, in __getitem__
    backend = load_backend(db['ENGINE'])
  File "/Users/aliraza/Projects/VirtualEnv/django1.5/lib/python2.7/site-packages/django/db/utils.py", line 27, in load_backend
    return import_module('.base', backend_name)
  File "/Users/aliraza/Projects/VirtualEnv/django1.5/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "/Users/aliraza/Projects/VirtualEnv/django1.5/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 17, in <module>
    raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb

The solution to this error which worked for me was simply installing mysql-python module in my virtual environment. Use following command:
 
pip install mysql-python
and if you are not using virtualenv, then use:
 
sudo pip install mysql-python

Wednesday, 24 December 2014

Psycopg2 - MacOS X - library not loaded libssl.1.0.0.dylib reason image not found - Issue Resolved

I encountered following error on my MacOS X after installing PostgreSQL and Psycopg2 for my Python and Django based application.

ImportError: dlopen(/Users/aliraza/Projects/VirtualEnv/django1.5/lib/python2.7/site-packages/psycopg2/_psycopg.so, 2): Library not loaded: libssl.1.0.0.dylib
  Referenced from: /Users/aliraza/Projects/VirtualEnv/django1.5/lib/python2.7/site-packages/psycopg2/_psycopg.so
  Reason: image not found

STEP-1:
Check if you have openssl installed by writing openssl on the commandline:
$ openssl

 If it starts, this means its installed in your system and you may skip STEP-2 and go directly to STEP-3.

STEP-2: 
If openssl isn't installed, install it by:
$ brew install openssl

STEP-3: 
Check the path of openssl lib on your machine. On my machine it was:
$ /usr/local/opt/openssl/lib/

STEP-4:
You have to simply include this path from STEP-3 by running following command:
$ export DYLD_LIBRARY_PATH=***YOUR OPENSSL PATH FROM STEP-3 HERE***
i.e in my case, the command with the STEP-3 path is:
$ sudo export DYLD_LIBRARY_PATH=/usr/local/opt/openssl/lib/

You may also have to create a symbolic link to PostgreSQL's lib folder. For that, first check your path of PostgreSQL's lib folder and then write following commands accordingly:

$ sudo ln -s /Library/PostgreSQL/9.4/lib/libssl.1.0.0.dylib /usr/lib/
$ sudo ln -s /Library/PostgreSQL/9.4/lib/libcrypto.1.0.0.dylib /usr/lib/

Now run python/ Django shell and import psycopg2. I had no errors after following this recipe.