How to host PHP Scripts in VPS โ
Solution:
First install the necessary packages from below commands :
Then find out which version of PHP you are using by this command :
After getting the PHP version, use the below commands to allow permission :
Here 7.x means 'x' is the version of your PHP. Just replace the actual version you are using. Then restart the apache using this command :
We are done setting up our VPS to a Web Hosting Server. Now what we need is to upload our PHP files to the public_html folder as usual we upload in our web hostings and then restart apache and our PHP site will be hosted.
To go to the public_html folder, use this command :
Then upload your full PHP project on that folder and restart apache by this command again :
And Boom ๐ฅ
Your PHP Website is running on Your VPS IP Address. To open your site, go to :
Here 'x' is Your IP Address
Solution:
First install the necessary packages from below commands :
sudo apt updatesudo apt install apache2sudo apt install php libapache2-mod-php php-mysqlThen find out which version of PHP you are using by this command :
php -vAfter getting the PHP version, use the below commands to allow permission :
sudo a2enmod php7.xsudo a2enmod rewriteHere 7.x means 'x' is the version of your PHP. Just replace the actual version you are using. Then restart the apache using this command :
sudo systemctl restart apache2We are done setting up our VPS to a Web Hosting Server. Now what we need is to upload our PHP files to the public_html folder as usual we upload in our web hostings and then restart apache and our PHP site will be hosted.
To go to the public_html folder, use this command :
cd var/www/htmlThen upload your full PHP project on that folder and restart apache by this command again :
sudo systemctl restart apache2And Boom ๐ฅ
Your PHP Website is running on Your VPS IP Address. To open your site, go to :
http://x.x.x.xHere 'x' is Your IP Address
How to connect domain to my PHP hosted website โ
Solution:
First open your domain configuration where you purchased the domain. I mean open DNS Management
Then set up 'A Record' by below instructions :
Type:
Host/Name:
Point/IP:
TTL:
If you want to use a sub-domain then,
Type:
Host/Name:
Point/IP:
TTL:
Domain Management System done โ Now wait for 5 minutes to confirm the dns actually setted up
After that, open your VPS and you have to create a new configuration file on your VPS sites configuration folder.
To open sites configuration folder of your VPS use this command :
Then create a new file named [your_domain.conf] like this example using nano editor :
Suppose my domain is : xoiox.com. So i name the file:
After that a editor page will appear in your VPS and simply write this below code on that file :
Now allow permission to your domain site using the below command :
[Note: Here will be is exact same as you created the configuration file name before]
Allow 443 ans 80 port traffics to receive by this command :
And then restart your apache again using this command :
After that, wait for 5 minutes again and boom ๐ฅ๐ฅ
Your site is now running at your domain ๐ฅ
If you want to check your access logs and error logs, just command these :
Boom ๐ฅ๐ฅ๐ฅ
Solution:
First open your domain configuration where you purchased the domain. I mean open DNS Management
Then set up 'A Record' by below instructions :
Type:
A RecordHost/Name:
@Point/IP:
x.x.x.xTTL:
Leave Empty or 3600If you want to use a sub-domain then,
Type:
A RecordHost/Name:
Your_Subdomain_NamePoint/IP:
x.x.x.xTTL:
Leave Empty or 3600Domain Management System done โ Now wait for 5 minutes to confirm the dns actually setted up
After that, open your VPS and you have to create a new configuration file on your VPS sites configuration folder.
To open sites configuration folder of your VPS use this command :
cd /etc/apache2/sites-availableThen create a new file named [your_domain.conf] like this example using nano editor :
Suppose my domain is : xoiox.com. So i name the file:
nano xoiox.com.confAfter that a editor page will appear in your VPS and simply write this below code on that file :
<VirtualHost *:80>
ServerAdmin your_mail@mail.com
ServerName your_domain_or_subdomain
ServerAlias www.your_domain_or_subdomain
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/html>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>Now allow permission to your domain site using the below command :
sudo a2ensite your_domain.conf[Note: Here will be is exact same as you created the configuration file name before]
Allow 443 ans 80 port traffics to receive by this command :
sudo ufw allow 'Apache'And then restart your apache again using this command :
sudo systemctl restart apache2After that, wait for 5 minutes again and boom ๐ฅ๐ฅ
Your site is now running at your domain ๐ฅ
If you want to check your access logs and error logs, just command these :
sudo tail -f /var/log/apache2/access.logsudo tail -f /var/log/apache2/error.logBoom ๐ฅ๐ฅ๐ฅ
A Few Things PHP Website Related โโ
1. If you want to use the hosted files without (.php) extensions, then all you need to create a file, write something and save and then restart apache.
Below instructions is for (.php) extension remove :
First create a new file if not exists in your public_html folder (e.g. /var/www/html) :
Then save this below script on that file :
After that command this :
And finally restart your apache using this command again :
And now finally boom ๐ฅ๐ฅ You can now use any files without php extension on your website
2. If you need to install any PHP Extensions for your site, then use apt-get package install manager to install extensions for your website.
Suppose, I need to install Curl Extension for my PHP website, so the command for php-curl installation is :
And Your extension will be installed...๐ฅ๐ฅ
And for use the extension, just do restart your apache again ๐๐ :
And your website is running super fast ๐ฅโ๐ฅ
1. If you want to use the hosted files without (.php) extensions, then all you need to create a file, write something and save and then restart apache.
Below instructions is for (.php) extension remove :
First create a new file if not exists in your public_html folder (e.g. /var/www/html) :
cd /var/www/htmlsudo nano .htaccessThen save this below script on that file :
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^\.]+)$ $1.php [NC,L]After that command this :
sudo a2enmod rewriteAnd finally restart your apache using this command again :
sudo systemctl restart apache2And now finally boom ๐ฅ๐ฅ You can now use any files without php extension on your website
2. If you need to install any PHP Extensions for your site, then use apt-get package install manager to install extensions for your website.
Suppose, I need to install Curl Extension for my PHP website, so the command for php-curl installation is :
sudo apt-get updatesudo apt-get install php-curlAnd Your extension will be installed...๐ฅ๐ฅ
And for use the extension, just do restart your apache again ๐๐ :
sudo systemctl restart apache2And your website is running super fast ๐ฅโ๐ฅ
#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 :-
After doing all these commands successfully, you will check heroku cli version using this command :
And boom ๐ฅ๐ฅ Heroku cli is all set. Now lets host python projects on heroku. See my next post โค๏ธ๐ซถ
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 -ywget http://cli-assets.heroku.com/heroku-linux-arm.tar.gz -O heroku.tar.gztar -xvzf heroku.tar.gzmkdir -p /data/data/com.termux/files/usr/lib/herokumv heroku/* /data/data/com.termux/files/usr/lib/herokurm -rf heroku heroku.tar.gzln -s /data/data/com.termux/files/usr/lib/heroku/bin/heroku /data/data/com.termux/files/usr/bin/herokucd /data/data/com.termux/files/usr/lib/heroku/bin/sed -i 's/#!/#!\/data\/data\/com.termux\/files/g' herokupkg install nodejs -ymv node node.oldln -s ../../../bin/node nodeecho 'export PATH="/data/data/com.termux/files/usr/lib/heroku/bin:$PATH"' >> ~/.bashrcsource ~/.bashrcAfter doing all these commands successfully, you will check heroku cli version using this command :
heroku --versionAnd 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:
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:
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 ๐ฅ๐
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 | shIn 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 gitFor 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:
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.