๐—–๐—ผ๐—ฑ๐—ฒ๐—ฟ๐—ฎ๐˜๐—ผ๐—ฟ
67 subscribers
6 links
A Free Channel for Sharing and Learning PHP, Nodejs, Python, HTML, CSS Codes to make your own scripts

Feel Free to ask
Download Telegram
#Part1 Heroku Deploying

How to host any php/python projects/files in heroku using Heroku-Cli โ“

So So So Simple ๐Ÿคญ๐Ÿ”ฅ

Solution:

First you need to install heroku-cli on your system. For instance let me using Termux

So command these one by one :-

pkg install wget tar gzip -y

wget http://cli-assets.heroku.com/heroku-linux-arm.tar.gz -O heroku.tar.gz

tar -xvzf heroku.tar.gz

mkdir -p /data/data/com.termux/files/usr/lib/heroku

mv heroku/* /data/data/com.termux/files/usr/lib/heroku

rm -rf heroku heroku.tar.gz

ln -s /data/data/com.termux/files/usr/lib/heroku/bin/heroku /data/data/com.termux/files/usr/bin/heroku

cd /data/data/com.termux/files/usr/lib/heroku/bin/

sed -i 's/#!/#!\/data\/data\/com.termux\/files/g' heroku

pkg install nodejs -y

mv node node.old

ln -s ../../../bin/node node

echo 'export PATH="/data/data/com.termux/files/usr/lib/heroku/bin:$PATH"' >> ~/.bashrc

source ~/.bashrc

After doing all these commands successfully, you will check heroku cli version using this command :

heroku --version

And boom ๐Ÿ”ฅ๐Ÿ”ฅ Heroku cli is all set. Now lets host python projects on heroku. See my next post โค๏ธ๐Ÿซถ
#Part2 Heroku Deploying

The previous process was about how to install heroku cli on termux. If you have windows or linux (ubuntu, debian etc.) then proceed the below instructions :

In windows, install Heroku-cli application by downloading and installing this:

32-Bit
64-Bit

In VPS, use this command to install heroku-cli:

sudo curl https://cli-assets.heroku.com/install.sh | sh

In termux, already posted in previous post

So finally our heroku cli installation has successfully completed.

Now we need to install GIT on our system. To install git use this below instructions:

For Linux/Termux Users, use this below command:

apt install git

For Windows, download and install the below application:

32-Bit
64-Bit

After installing GIT, your system is finnally ready to be able to host any php/python projects on heroku. So, go to the next post to see how to host on heroku ๐Ÿ”ฅ๐Ÿ‘
๐Ÿ‘1
#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:

apt install php

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:

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

php composer-setup.php --install-dir=/data/data/com.termux/files/usr/bin --filename=composer

For 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=composer

After 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.py

If you want to run a folder, then use:

worker: python -m folder

Then save the file. And you are set all.

Now initialize a git repository for your project inside your directory by this command:

git init

Then, set up configuration file for your git repository following this command:

git config --global user.email YOUR_EMAIL@gmail.com

git config --global user.name YOUR_NAME

After 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-files

If 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 --hard

After 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:

heroku login

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:

heroku create YOUR_APP_NAME

After create, connect your git repository with this heroku app using the below command:

heroku git:remote -a YOUR_APP_NAME

After connect, push your git repository to heroku using this below command:

git push heroku master

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:

heroku ps:scale worker=1

And boom ๐Ÿ”ฅ๐Ÿ”ฅ

Your python project is also hosted in heroku. โค๏ธ๐Ÿ”ฅ

Now enjoy ๐Ÿซถ
Git Repository Connect to Shell:

git init

git add README.md

git commit -m "first commit"

git branch -M main

git remote add origin [REPO_LINK]

git push -u origin main

Existing Git Repository Connect to Existing Local Git Repository:

git remote add origin [REPO_LINK]

git branch -M main

git push -u origin main
โค2
In python 3.7>= older versions:

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

pip install -U setuptools cython -y

GRPC_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 -y

pip install firebase_admin -y

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 ๐Ÿ˜ž
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 :

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


Boom ๐Ÿ”ซ Your server is hosted. And you can get ssl certificate using certbot for free lifetime.

Do you need that tutorial too? ๐Ÿ˜ด
Please open Telegram to view this post
VIEW IN TELEGRAM
๐Ÿ”ฅ2
๐Ÿ  Hey, guys! Let's host our project in our Heroku using Dockerfile containing our project ๐Ÿ‘‹

( โš ๏ธ Ubuntu Only )

๐Ÿ’Ž Installed Prequisites:
- Heroku CLI (Required)
- Docker (Required)
- Git (Optional)

๐Ÿ›ก Steps:

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 | sh

2. 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)

๐Ÿ‘‡ Next steps below
Please open Telegram to view this post
VIEW IN TELEGRAM
โค1
๐Ÿ‘‹ So, our next step is:

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-name

7. Login to heroku container:

heroku container:login

8. Release the docker container:

heroku container:release worker --app app-name

9. Start PS Dyno Scales:

heroku ps:scale worker=1 --app app-name

๐Ÿ’ฅ Your project hosted in heroku inside the docker image โค๏ธ

Check logs, using:

heroku logs --tail --app app-name
Please 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:

curl -fsSL https://pgp.mongodb.com/server-7.0.asc | sudo gpg -o /usr/share/keyrings/mongodb-server-7.0.gpg --dearmor


2๏ธโƒฃ Then Create MongoDB Source List File includes the URL of MongoDB:

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


3๏ธโƒฃ Then install mongodb using below steps:

sudo apt update
sudo apt install -y mongodb-org

sudo systemctl start mongod
sudo systemctl enable mongod

๐Ÿ˜€ Finally check MongoDB Status if it is Active/Running/Successful Icon appearing:

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.