If you are struggling with below error while deploying Django on VPS, this post may help and save you hours for MariaDB Troubleshoot.
- Did you install mysqlclient or MySQL-python?
- OSError: mysql_config not found
- ModuleNotFoundError: No module named ‘ConfigParser’
This is my 2nd times try out Django with MariaDB. The 1st one went smoothly. Couple of searches and I find that I only need to add a simple line into “activate” file of Python VirtualEnv
2nd time didn’t go right, when running “python manage.py migrate“, I got “Did you install mysqlclient or MySQL-python?“. Continue trying to run “pip install mysqlclient“, I got “OSError: mysql_config not found“, and sometimes “ModuleNotFoundError: No module named ‘ConfigParser‘”
I tried and installed many things and not quite sure which one resolved the issue. I do believe below helped me out
“yum install mariadb-devel”
After running above command, I was able to “pip install mysqlclient” and “python manage.py migrate”
Believe me or not, there are hundred ways to setup web server. I searched and tried many of them on a VPS with 512MB of RAM. Most of them had issue with database, MySQL or MariaDB was die again and again. This one has worked for me for more than a year: CNMP (Centos 7 + NGINX + MariaDB + PHP 7).
Grab a VPS
I’ve used DigitalOcean as VPS provider for a while. Linode is one of my next try since its same price but double RAM. If you have any experience with other VPS providers, please share.
Create a Swap File
This section doesn’t apply for VPS at Linode since they have option to create SWAP file at VPS configuration.
LEMP (Linux, NGINX, MariaDB/MySQL, PHP) Stack Setup
You will see this page if you try to access to your server by using IP
Setup Configuration for WordPress Site
Create root directory & Server Block folders
sudo mkdir /etc/nginx/sites-available
sudo mkdir /etc/nginx/sites-enabled
sudo mkdir -p /var/www/vndeveloper.com/html
Create the First Server Block File
sudo vi /etc/nginx/sites-available/vndeveloper.conf
Create a symlink
sudo ln -s /etc/nginx/sites-available/vndeveloper.conf /etc/nginx/sites-enabled/
Download WordPress source
sudo unzip latest.zip
sudo mv wordpress/* /var/www/vndeveloper.com/html/
mysql -u root -p
CREATE DATABASE dbname;
CREATE USER ‘dbuser’@’localhost’ IDENTIFIED BY ‘password’;
GRANT ALL PRIVILEGES ON dbname.* TO ‘dbuser’@’localhost’;
Wrap it up
That’s it. I know it’s too much if you are newbie to VPS but I hope it is helpful for you. This is how I setup Developer’s Notes (I didn’t cover ssl part yet). Leave a comment or feedback right below.