#Part3 Heroku Deploying
So, we have now git and heroku-cli installed on our system and we are now ready to deoloy.
First, create or navigate to the directory/folder where your python/php project files located.
Then use these below instructions:
If you want to deploy a php project, then you need two files in your project named "composer.json" & "composer.lock", so use the below instructions to get those:
First, install php in your system.
For linux/termux, use the below command:
For windows, go this post
After installing php, then you need to install composer in your system. Use the below commands to install composer:
For windows, download and install:
Composer
For termux, use these commands:
For vps, use these commands:
After successfully installed composer, lets proceed further to deploy a php project on heroku:
So, initialize a composer file by command this first:
[Inside this initialization:
Package Name will be the default inside the brackets
Description will be your choice, no matter what
Author will be your name and email
Minimum Stability will be "stable"
Package Type will be "project"
License will be "MIT"
Then it will ask to define dependencies for your php project. Simply write "yes" and enter. Then first write "php" and enter after that if ask latest version just leave it blank and enter
Then it will again ask another dependencies, so proceed with your dependencies for example if you need php-curl, then search it and choose "php-curl-class/php-curl-class" this if has, you can choose another provider also.
After that enter and if asks dev-dependencies then skip and enter and proceed to finalization. Then it will crete two files in your directory named "composer.json" and "composer.lock"]
If you want to deploy a python project then you need one file named "Procfile", so create a " Procfile" without any extension and write inside the file :
If you want to run a folder, then use:
Then save the file. And you are set all.
Now initialize a git repository for your project inside your directory by this command:
Then, set up configuration file for your git repository following this command:
After setting up config file, now add all files to the repository following this command:
After that, you need to commite that you update files on the repository by this command:
If you think some files are mistakely add to git repository then you can remove files using below command:
If you want to check how many files and which which are there in the repository, then command the below:
If you think to delete all the files inside the repository, then use the below command:
To reset git repository, use this commamd:
After changes in git repository you must need to commit that you change something using below command:
So, our git repository is ready to deploy. Now what we need is to push this git repository to our heroku. See you in the next post ๐ฅ๐ซถ
So, we have now git and heroku-cli installed on our system and we are now ready to deoloy.
First, create or navigate to the directory/folder where your python/php project files located.
Then use these below instructions:
If you want to deploy a php project, then you need two files in your project named "composer.json" & "composer.lock", so use the below instructions to get those:
First, install php in your system.
For linux/termux, use the below command:
apt install phpFor windows, go this post
After installing php, then you need to install composer in your system. Use the below commands to install composer:
For windows, download and install:
Composer
For termux, use these commands:
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"php composer-setup.php --install-dir=/data/data/com.termux/files/usr/bin --filename=composerFor vps, use these commands:
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"php -r "if (hash_file('sha384', 'composer-setup.php') === 'e21205b207c3ff031906575712edab6f13eb0b361f2085f1f1237b7126d785e826a450292b6cfd1d64d92e6563bbde02') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"php composer-setup.php --install-dir=/usr/local/bin --filename=composerAfter successfully installed composer, lets proceed further to deploy a php project on heroku:
So, initialize a composer file by command this first:
composer init[Inside this initialization:
Package Name will be the default inside the brackets
Description will be your choice, no matter what
Author will be your name and email
Minimum Stability will be "stable"
Package Type will be "project"
License will be "MIT"
Then it will ask to define dependencies for your php project. Simply write "yes" and enter. Then first write "php" and enter after that if ask latest version just leave it blank and enter
Then it will again ask another dependencies, so proceed with your dependencies for example if you need php-curl, then search it and choose "php-curl-class/php-curl-class" this if has, you can choose another provider also.
After that enter and if asks dev-dependencies then skip and enter and proceed to finalization. Then it will crete two files in your directory named "composer.json" and "composer.lock"]
If you want to deploy a python project then you need one file named "Procfile", so create a " Procfile" without any extension and write inside the file :
worker: python your_project.pyIf you want to run a folder, then use:
worker: python -m folderThen save the file. And you are set all.
Now initialize a git repository for your project inside your directory by this command:
git initThen, set up configuration file for your git repository following this command:
git config --global user.email YOUR_EMAIL@gmail.comgit config --global user.name YOUR_NAMEAfter setting up config file, now add all files to the repository following this command:
git add .After that, you need to commite that you update files on the repository by this command:
git commit -m "Initialize Project Repository"If you think some files are mistakely add to git repository then you can remove files using below command:
git rm [files/folders]If you want to check how many files and which which are there in the repository, then command the below:
git ls-filesIf you think to delete all the files inside the repository, then use the below command:
git rm -r .To reset git repository, use this commamd:
git reset --hardAfter changes in git repository you must need to commit that you change something using below command:
git commit -m "Your Changes"So, our git repository is ready to deploy. Now what we need is to push this git repository to our heroku. See you in the next post ๐ฅ๐ซถ
#Part4 Heroku Deploying
So, first of all, we need to login to our heroku account for deployment. So, command below:
After this command, it will asks to enter for continue process. So, enter and it will prompt auto to open a browser. So, login your account on the browser. If the browser does not auto opened, then you will see a url so just open the url on your local browser and login. After login successfully, come back to your system.
After login, you need to create a heroku app for your project, so command:
After create, connect your git repository with this heroku app using the below command:
After connect, push your git repository to heroku using this below command:
After successfully pushing, if you had a php project it will directly hosted in heroku and you dont need to do any more things. Just copy the url shown in terminal and open it. And boom ๐ฅ Your website is ready to host
But if you had a python project, then after pushing, you need to scale your project with dynos using a worker for this app using the below command:
And boom ๐ฅ๐ฅ
Your python project is also hosted in heroku. โค๏ธ๐ฅ
Now enjoy ๐ซถ
So, first of all, we need to login to our heroku account for deployment. So, command below:
heroku loginAfter this command, it will asks to enter for continue process. So, enter and it will prompt auto to open a browser. So, login your account on the browser. If the browser does not auto opened, then you will see a url so just open the url on your local browser and login. After login successfully, come back to your system.
After login, you need to create a heroku app for your project, so command:
heroku create YOUR_APP_NAMEAfter create, connect your git repository with this heroku app using the below command:
heroku git:remote -a YOUR_APP_NAMEAfter connect, push your git repository to heroku using this below command:
git push heroku masterAfter successfully pushing, if you had a php project it will directly hosted in heroku and you dont need to do any more things. Just copy the url shown in terminal and open it. And boom ๐ฅ Your website is ready to host
But if you had a python project, then after pushing, you need to scale your project with dynos using a worker for this app using the below command:
heroku ps:scale worker=1And boom ๐ฅ๐ฅ
Your python project is also hosted in heroku. โค๏ธ๐ฅ
Now enjoy ๐ซถ
Git Repository Connect to Shell:
Existing Git Repository Connect to Existing Local Git Repository:
git initgit add README.mdgit commit -m "first commit"git branch -M maingit remote add origin [REPO_LINK]git push -u origin mainExisting Git Repository Connect to Existing Local Git Repository:
git remote add origin [REPO_LINK]git branch -M maingit push -u origin mainโค2
In python 3.7>= older versions:
In python3.8=< later versions:
#Keypoint
Note: In python 3.8 or later versions, there is a new ":=" walrus operator, which can do conditional statements with assignation, so you can make your script more shorter and more improver
response = await call()
# Assume 'response' is 50
if response:
sum = 10 + response
print(sum)
else:
print("Sorry, no response found")
In python3.8=< later versions:
if response := await call():
print(10 + response)
else:
print("Sorry, no response found")
#Keypoint
Note: In python 3.8 or later versions, there is a new ":=" walrus operator, which can do conditional statements with assignation, so you can make your script more shorter and more improver
๐ฅฐ1
FIREBASE ADMIN MODULE INSTALLATION IN TERMUX
This will take at least 1.5 to 2 hour to properly install it on your android machine, even if the machine is a VPS or Windows or Android or IOS or MacOS, doesnโt matter ๐
pip install -U setuptools cython -yGRPC_PYTHON_DISABLE_LIBC_COMPATIBILITY=1 GRPC_PYTHON_BUILD_SYSTEM_OPENSSL=1 GRPC_PYTHON_BUILD_SYSTEM_ZLIB=1 GRPC_PYTHON_BUILD_SYSTEM_CARES=1 CFLAGS+=" -U__ANDROID_API__ -D__ANDROID_API__=30 -include unistd.h" LDFLAGS+=" -llog" pip install grpcio -ypip install firebase_admin -yThis will take at least 1.5 to 2 hour to properly install it on your android machine, even if the machine is a VPS or Windows or Android or IOS or MacOS, doesnโt matter ๐
Hey guys, long time no post ๐ญ So, today I wanna share another method ๐
How to host your python flask web application (templates, static, app.py) in your Ubuntu Server gracefully and connect your domain or sub-domain?๐ซ
First of all install these below commands :
Then, host your python web application on ubuntu using screen or gunicorn.
(Gunicorn will be extremely best choice for production application. As for test, you can use screen)
Then, create a configuration file of your application with your domain by below command:
Here, "application_name" can be either your domain name or any preferred name๐
And, paste the below code on that configuration file ๐
Then, enable the website in ubuntu vps by this command ๐
Here also, "application_name" must be as you set before๐ฅ
And finally, run these commands to check nginx scripts and restart nginx server :
Boom ๐ซ Your server is hosted. And you can get ssl certificate using certbot for free lifetime.
Do you need that tutorial too?๐ด
How to host your python flask web application (templates, static, app.py) in your Ubuntu Server gracefully and connect your domain or sub-domain?
First of all install these below commands :
sudo apt update
sudo apt install nginx certbot python3-certbot-nginx
Then, host your python web application on ubuntu using screen or gunicorn.
(Gunicorn will be extremely best choice for production application. As for test, you can use screen)
pip install gunicorn
gunicorn --workers 3 app:app
Then, create a configuration file of your application with your domain by below command:
sudo nano /etc/nginx/sites-available/application_name
Here, "application_name" can be either your domain name or any preferred name
And, paste the below code on that configuration file ๐
server {
listen 80;
server_name your_domain;
location / {
proxy_pass http://your_vps_ip:port_of_your_web_application;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}Then, enable the website in ubuntu vps by this command ๐
sudo ln -s /etc/nginx/sites-available/application_name /etc/nginx/sites-enabled/
Here also, "application_name" must be as you set before
And finally, run these commands to check nginx scripts and restart nginx server :
sudo nginx -t
sudo systemctl restart nginx
Do you need that tutorial too?
Please open Telegram to view this post
VIEW IN TELEGRAM
๐ฅ2
( โ ๏ธ Ubuntu Only )
-
Heroku CLI (Required)-
Docker (Required)-
Git (Optional)1. Install Heroku CLI, Docker first. Optional (git):
sudo apt update -y && sudo apt install git curl -y && sudo apt install docker.io -y && sudo curl https://cli-assets.heroku.com/install-ubuntu.sh | sh2. Open your project in terminal ( Optional: Git clone your github public repository and open ):
cd myProject(โ ๏ธ Since we are using docker to deploy our project in heroku, Make sure you have requirements.txt, Dockerfile & heroku.yml in your project. If you don't have these, make one using)
requirements.txt:
requests
bs4
heroku.yml:
build:
docker:
worker: Dockerfile
Dockerfile:
FROM python:3.11.11-slim
WORKDIR /usr/src/app
RUN chmod 777 /usr/src/app
COPY requirements.txt .
RUN pip3 install --break-system-packages --ignore-installed --no-cache-dir -r requirements.txt
COPY . .
CMD ["your", "command"]
3. Now, Important step is to log-in your heroku account in the Heroku CLI:
First of all, open your any of browser, login on heroku.com dashboard, then open this link and create a new authorization (description is actually lebel to recognize the token later)
Then, come back to our terminal and command:
heroku login -iโ ๏ธ This will prompt heroku email and password (auth token you just generated)
๐
Please open Telegram to view this post
VIEW IN TELEGRAM
โค1
4. Create an Application manually in your Heroku Dashboard and copy Application Name. (Important โ ๏ธ)
5. Since, you are on your project inside terminal, build your Docker Image in your server manually:
docker build -t heroku/app-name-worker .( โ Here app-name, instead of this, use your actual application name of heroku )
6. Now push your built container in your heroku application:
heroku container:push worker --app app-name7. Login to heroku container:
heroku container:login8. Release the docker container:
heroku container:release worker --app app-name9. Start PS Dyno Scales:
heroku ps:scale worker=1 --app app-nameCheck logs, using:
heroku logs --tail --app app-namePlease open Telegram to view this post
VIEW IN TELEGRAM
โค3
Install Google Chrome On Ubuntu
sudo apt update
sudo apt install wget
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo apt install ./google-chrome-stable_current_amd64.deb
Install Local MongoDB Server in Your Ubuntu/Debian VPS
1๏ธโฃ First Import MongoDB Public GPG Key in your VPS:
2๏ธโฃ Then Create MongoDB Source List File includes the URL of MongoDB:
3๏ธโฃ Then install mongodb using below steps:
๐ Finally check MongoDB Status if it is Active/Running/Successful Icon appearing:
If any successful message is appearing, it means you have successfully installed Latest MongoDB 7.0 on your Ubuntu/Debian VPS.
curl -fsSL https://pgp.mongodb.com/server-7.0.asc | sudo gpg -o /usr/share/keyrings/mongodb-server-7.0.gpg --dearmor
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list
sudo apt update
sudo apt install -y mongodb-org
sudo systemctl start mongod
sudo systemctl enable mongod
sudo systemctl status mongod
If any successful message is appearing, it means you have successfully installed Latest MongoDB 7.0 on your Ubuntu/Debian VPS.
Please open Telegram to view this post
VIEW IN TELEGRAM
Next guide will be on Windows ๐ ๏ธ So stay with here.