Skip to content

Instantly share code, notes, and snippets.

@Lalmi-Issam
Last active January 21, 2022 02:06
Show Gist options
  • Save Lalmi-Issam/75462f873fb3f5589d2a2182b590a618 to your computer and use it in GitHub Desktop.
Save Lalmi-Issam/75462f873fb3f5589d2a2182b590a618 to your computer and use it in GitHub Desktop.
##HOW TO SETUP DJANGO WEBSITE ?
01/ Install new ubuntu system 18.04 LTS and use follwing cammands to install GUI.
A) "sudo tasksel install ubuntu-mate-desktop"
B) "sudo service lightdm start"
02/ Create new user with "www-data" and superuser permession:
A) "adduser username"
B) "usermod -aG sudo username"
C) "sudo usermod -aG www-data iain
D) "addgroup www-data"
03/ Create "project" folder at "/home/username" copy project files to "/home/username/project"
04/ Change permmesion "project" folder "chmod 755 -R project"
05/ Change user permession folde by usnig "chmod 777 -R /home"
06/ Install apache2 "sudo apt-get install apache2"
07/ Setup apache confugration to work with django:
a) sudo apt-get update
b) sudo apt-get install python3-pip apache2 libapache2-mod-wsgi-py3
c) sudo pip3 install virtualenv
d) edit file at "/etc/apache2/sites-available/000-default.conf":
<VirtualHost *:80>
Alias /static /home/user/project/static
<Directory /home/user/project/static>
Require all granted
</Directory>
<Directory /home/user/project/project(max...)>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess myproject python-home=/home/user/myvenv/venv python-path=/home/user/project
WSGIProcessGroup project
WSGIScriptAlias / /home/user/project/project/wsgi.py
</VirtualHost>
08/ create folder at "/home/username/" name it "projectvenv" then "cd projectvenv"
09/ create venv "virtualenv virtual_env_name" activate BY "source ./virtual_env_name/bin/activate"
10/ Install requirements of the project "pip install -r requirements.txt"
11/ Change venv folder permession using "chmod 755 -R project"
12/ Install MYSQL using "sudo apt-get install mysql-server"
13/ Install PHPMYADMIN :
A) "sudo apt install phpmyadmin php-mbstring php-gettext"
B) "sudo phpenmod mbstring"
C) Adjusting User Authentication and Privileges :
a) Use to check if root allow password access "SELECT user,authentication_string,plugin,host FROM mysql.user;"
b) Create password for root user "ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';"
c) apply edits "FLUSH PRIVILEGES;"
d) Create new user for db "CREATE USER 'user'@'localhost' IDENTIFIED BY 'password';"
e) add permession to user "GRANT ALL PRIVILEGES ON *.* TO 'user'@'localhost' WITH GRANT OPTION;"
f) activate PHPMYADMIN "sudo ln -s /etc/phpmyadmin/apache.conf /etc/apache2/sites-enabled/phpmyadmin.conf"
g) access PHPMYADMIN using yourdomain.com/phpmyadmin
14/ Server advence confugration:
A) General confugration:
a) Edit conf file at "/etc/apache2/apache2.conf"
b) Set "Timeout 50"
c) Set "KeepAlive On"
d) Set "MaxKeepAliveRequests 200"
e) Set "KeepAliveTimeout 3"
B) Setup Mpm prefork settings (use "a2query -M" to define which one):
StartServers 3
MinSpareServers 300
MaxSpareServers 500
MaxRequestWorkers 1200
MaxConnectionsPerChild 0
ServerLimit 256
C) MYSQL settings edit at "/etc/mysql/mysql.conf/mysqld.conf":
a) Set "innodb_buffer_pool_size=1G"
a) Set "wait_timeout=15"
a) Set "interactive_timeout=15"
a) Set "max_connections=2000"
15/ Setup Let's encrypt SSL free certificate :
a) apt-get install python-certbot-apache
b) certbot --apache
c) edit configfile comment WSGI lines.
d) follow steps read the instructions.
e) create "CRON JOB" OR "sudo certbot renew" every 90 days.
16/ Secure PHPMYADMIN no root access using "$cfg['Servers'][$i]['AllowRoot'] = FALSE;" at "/usr/share/phpmyadmin/config_sample.ini.conf" also need to edit file conf at "/usr/share/phpmyadmin/libraries/vedor_config.php"
17/ Disable root access using ssh set "Permitroot no" in "/etc/ssh/sshd_conf"
18/ HAVE FUN ^_^
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment