How to setup Django on Live Server?

0
163
Django development

update and upgrade ubuntu budgie

sudo apt update
sudo apt upgrade

Install Apache

sudo apt update
sudo apt install apache2
sudo ufw app info "Apache Full"
sudo ufw allow in "Apache Full"

Install Mysql

sudo apt update
sudo apt install mysql-server
sudo mysql_secure_installation
sudo mysql
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
FLUSH PRIVILEGES;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION;
exit
systemctl status mysql.service
sudo mysqladmin -p -u root version

Install phpMyAdmin

sudo apt update
sudo apt install phpmyadmin php-mbstring php-gettext
sudo phpenmod mbstring
sudo systemctl restart apache2
if phpmyadmin was not found
sudo -H nano /etc/apache2/apache2.conf
Then add the following line to the end of the file:
IncludeOptional /etc/phpmyadmin/apache.conf
/etc/init.d/apache2 restart

Now create yourfile.conf file in sies-available

<VirtualHost *:80>
Alias /static /var/www/misthipro/static
<Directory /var/www/misthipro/static>
Require all granted
</Directory>
<Directory /var/www/misthipro/misthi>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess misthipro python-home=/var/www/misthipro/misthipro python-path=/var/www/misthipro
WSGIProcessGroup misthipro
WSGIScriptAlias / /var/www/misthipro/misthi/wsgi.py
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Install Django now

sudo apt-get install python3-pip
pip3 install virtualenv
virtualenv venv
source venv/bin/activate
pip3 install django
django-admin startproject misthi .
cd projectname
sudo nano settings.py #edit the settings.py file and add following code in footer
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')
pip3 install mysqlclient 
sudo apt-get install libmariadbclient-dev
python manage.py makemigrations
python manage.py migrate

LEAVE A REPLY

Please enter your comment!
Please enter your name here