Thiết Lập Django CMS Trên Ubuntu Server

– Kiểm tra phiên bản python trên máy linux thấy đang là python 2.7

root@srv:/home/nhanld# python
Python 2.7.12 (default, Dec 4 2017, 14:50:18)
[GCC 5.4.0 20160609] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.
>>> exit()

– Thực hiện chuyển sang python 3

root@srv:/home/nhanld# update-alternatives –remove python /usr/bin/python2
root@srv:/home/nhanld# update-alternatives –install /usr/bin/python python /usr/bin/python3 1

root@srv:/home/nhanld# python
Python 3.5.2 (default, Nov 23 2017, 16:37:01)
[GCC 5.4.0 20160609] on linux
Type “help”, “copyright”, “credits” or “license” for more information.
>>>

– Cài đặt pip3

root@srv:/home/nhanld# apt install python3-pip

root@srv:/home/nhanld# which pip3
/usr/bin/pip3

root@srv:/home/nhanld# ln -s /usr/bin/pip3 /usr/bin/pip
root@srv:/home/nhanld# pip -V
pip 8.1.1 from /usr/lib/python3/dist-packages (python 3.5)

– Thực hiện cài đặt Django theo phiên bản xác định 1.11

root@srv:/home/nhanld# pip install django==1.11
root@srv:/home/nhanld# pip install –upgrade pip
root@srv:/home/nhanld# django-admin –version
1.11

– Tạo project Django Project

root@srv:~# mkdir /opt/django/ && cd /opt/django/
root@srv:/opt/django# django-admin startproject myblog
=> khởi động tạo project tên “myblog”

root@srv:/opt/django/myblog# ls
manage.py myblog

=> xuất hiện file “manage.py”
=> file này dùng để quản lý server ứng với project myblog

root@srv:/opt/django/myblog# tree .
.
├── manage.py
└── myblog
├── __init__.py
├── settings.py
├── urls.py
└── wsgi.py

1 directory, 5 files
root@srv:/opt/django/myblog#

– Kiểm tra các thông số của “manage.py”

root@srv:/opt/django/myblog# python manage.py –help
root@srv:/opt/django/myblog# python manage.py migrate
root@srv:/opt/django/myblog# python manage.py runserver 0.0.0.0:8080

– Client thử nghiệm kết nối đến địa chỉ máy chủ Django http://192.168.255.132:8080

– Tiếp tục ta thực hiện cài đặt Django CMS

root@srv:~# pip install –upgrade pip
Requirement already up-to-date: pip in /usr/local/lib/python3.5/dist-packages (10.0.0)

– Cài đặt chương trình djangocms-installer

root@srv:~# pip install djangocms-installer
=> ta sẽ có dòng lệnh mới “djangocms”

root@srv:~# cd /opt/
root@srv:/opt# mkdir web-project && cd web-project

root@srv:/opt/web-project# djangocms -f -p . webproject
Creating the project
Please wait while I install dependencies
Dependencies installed
Creating the project
Operations to perform:
Apply all migrations: admin, auth, cms, contenttypes, djangocms_column, djangocms_file, djangocms_googlemap, djangocms_link, djangocms_picture, djangocms_snippet, djangocms_style, djangocms_text_ckeditor, djangocms_video, easy_thumbnails, filer, menus, sessions, sites
Running migrations:
Applying contenttypes.0001_initial… OK
Applying auth.0001_initial… OK
Applying admin.0001_initial… OK
Applying admin.0002_logentry_remove_auto_add… OK
Applying contenttypes.0002_remove_content_type_name… OK
Applying auth.0002_alter_permission_name_max_length… OK
Applying auth.0003_alter_user_email_max_length… OK
Applying auth.0004_alter_user_username_opts… OK
Applying auth.0005_alter_user_last_login_null… OK
Applying auth.0006_require_contenttypes_0002… OK
Applying auth.0007_alter_validators_add_error_messages… OK
Applying auth.0008_alter_user_username_max_length… OK
Applying sites.0001_initial… OK
Applying cms.0001_initial… OK
Applying cms.0002_auto_20140816_1918… OK
Applying cms.0003_auto_20140926_2347… OK
Applying cms.0004_auto_20140924_1038… OK
Applying cms.0005_auto_20140924_1039… OK
Applying cms.0006_auto_20140924_1110… OK
Applying cms.0007_auto_20141028_1559… OK
Applying cms.0008_auto_20150208_2149… OK
Applying cms.0008_auto_20150121_0059… OK
Applying cms.0009_merge… OK
Applying cms.0010_migrate_use_structure… OK
Applying cms.0011_auto_20150419_1006… OK
Applying cms.0012_auto_20150607_2207… OK
Applying cms.0013_urlconfrevision… OK
Applying cms.0014_auto_20160404_1908… OK
Applying cms.0015_auto_20160421_0000… OK
Applying cms.0016_auto_20160608_1535… OK
Applying cms.0017_pagetype… OK
Applying cms.0018_create_pagenode… OK
Applying cms.0019_set_pagenode… OK
Applying cms.0020_old_tree_cleanup… OK
Applying djangocms_column.0001_initial… OK
Applying djangocms_column.0002_auto_20160915_0818… OK
Applying filer.0001_initial… OK
Applying filer.0002_auto_20150606_2003… OK
Applying filer.0003_thumbnailoption… OK
Applying filer.0004_auto_20160328_1434… OK
Applying filer.0005_auto_20160623_1425… OK
Applying filer.0006_auto_20160623_1627… OK
Applying djangocms_file.0001_initial… OK
Applying djangocms_file.0002_auto_20151202_1551… OK
Applying djangocms_file.0003_remove_related_name_for_cmsplugin_ptr… OK
Applying djangocms_file.0004_set_related_name_for_cmsplugin_ptr… OK
Applying djangocms_file.0005_auto_20160119_1534… OK
Applying djangocms_file.0006_migrate_to_filer… OK
Applying djangocms_file.0007_adapted_fields… OK
Applying djangocms_file.0008_add_folder… OK
Applying djangocms_file.0009_fixed_null_fields… OK
Applying djangocms_file.0010_removed_null_fields… OK
Applying filer.0007_auto_20161016_1055… OK
Applying djangocms_googlemap.0001_initial… OK
Applying djangocms_googlemap.0002_auto_20160622_1031… OK
Applying djangocms_googlemap.0003_auto_20160825_1829… OK
Applying djangocms_googlemap.0004_adapted_fields… OK
Applying djangocms_googlemap.0005_create_nested_plugins… OK
Applying djangocms_googlemap.0006_remove_fields… OK
Applying djangocms_googlemap.0007_reset_null_values… OK
Applying djangocms_googlemap.0008_removed_null_fields… OK
Applying djangocms_googlemap.0009_googlemapmarker_icon… OK
Applying djangocms_link.0001_initial… OK
Applying djangocms_link.0002_auto_20140929_1705… OK
Applying djangocms_link.0003_auto_20150212_1310… OK
Applying djangocms_link.0004_auto_20150708_1133… OK
Applying djangocms_link.0005_auto_20151003_1710… OK
Applying djangocms_link.0006_remove_related_name_for_cmsplugin_ptr… OK
Applying djangocms_link.0007_set_related_name_for_cmsplugin_ptr… OK
Applying djangocms_link.0008_link_attributes… OK
Applying djangocms_link.0009_auto_20160705_1344… OK
Applying djangocms_link.0010_adapted_fields… OK
Applying djangocms_link.0011_fixed_null_values… OK
Applying djangocms_link.0012_removed_null… OK
Applying djangocms_link.0013_fix_hostname… OK
Applying djangocms_picture.0001_initial… OK
Applying djangocms_picture.0002_auto_20151018_1927… OK
Applying djangocms_picture.0003_migrate_to_filer… OK
Applying djangocms_picture.0004_adapt_fields… OK
Applying djangocms_picture.0005_reset_null_values… OK
Applying djangocms_picture.0006_remove_null_values… OK
Applying djangocms_picture.0007_fix_alignment… OK
Applying djangocms_snippet.0001_initial… OK
Applying djangocms_snippet.0002_snippet_slug… OK
Applying djangocms_snippet.0003_auto_data_fill_slug… OK
Applying djangocms_snippet.0004_auto_alter_slug_unique… OK
Applying djangocms_snippet.0005_set_related_name_for_cmsplugin_ptr… OK
Applying djangocms_snippet.0006_auto_20160831_0729… OK
Applying djangocms_snippet.0007_auto_alter_template_helptext… OK
Applying djangocms_style.0001_initial… OK
Applying djangocms_style.0002_set_related_name_for_cmsplugin_ptr… OK
Applying djangocms_style.0003_adapted_fields… OK
Applying djangocms_style.0004_use_positive_small_integer_field… OK
Applying djangocms_style.0005_reset_null_values… OK
Applying djangocms_style.0006_removed_null_fields… OK
Applying djangocms_style.0007_style_template… OK
Applying djangocms_text_ckeditor.0001_initial… OK
Applying djangocms_text_ckeditor.0002_remove_related_name_for_cmsplugin_ptr… OK
Applying djangocms_text_ckeditor.0003_set_related_name_for_cmsplugin_ptr… OK
Applying djangocms_text_ckeditor.0004_auto_20160706_1339… OK
Applying djangocms_video.0001_initial… OK
Applying djangocms_video.0002_set_related_name_for_cmsplugin_ptr… OK
Applying djangocms_video.0003_field_adaptions… OK
Applying djangocms_video.0004_move_to_attributes… OK
Applying djangocms_video.0005_migrate_to_filer… OK
Applying djangocms_video.0006_field_adaptions… OK
Applying djangocms_video.0007_create_nested_plugin… OK
Applying djangocms_video.0008_reset_null_values… OK
Applying djangocms_video.0009_removed_null_values… OK
Applying easy_thumbnails.0001_initial… OK
Applying easy_thumbnails.0002_thumbnaildimensions… OK
Applying filer.0008_auto_20171117_1313… OK
Applying filer.0009_auto_20171220_1635… OK
Applying filer.0010_auto_20180414_2058… OK
Applying menus.0001_initial… OK
Applying sessions.0001_initial… OK
Applying sites.0002_alter_domain_unique… OK
Creating admin user
All done!
Get into “/opt/web-project” directory and type “python manage.py runserver” to start your project
root@srv:/opt/web-project#

– Sau khi cài đặt xong thì tài khoản là

root@srv:/opt/web-project/webproject# ls
__init__.py __pycache__ settings.py static templates urls.py wsgi.py

root@srv:/opt/web-project/webproject# vi settings.py
#Khu vực dòng 29 thay đổi nội dung
DEBUG = True
ALLOWED_HOSTS = [‘192.168.255.132’]

root@srv:/opt/web-project/webproject# cd ..
root@srv:/opt/web-project# python manage.py runserver 0.0.0.0:8080

– Client kết nối đến đường link và tài khoản đăng nhập là “admin/admin”

http://192.168.255.132:8080/

 

Để có thêm thông tin hữu ích, bạn tham khảo nội dung khóa học Linux 2 tại trung tâm Athena

Lịch khai giảng