php task

 for 

range 10-20 kms : price is 20

for range 20-30 kms price is 15;

for range 30-40 kms price is 15;

minimum price is 100


for example he travel 25 kms


100+10*20+10*15+5*15


for this code below


<?php




$carid = 'a';

$distance = 21;

echo getPricePerDistance($carid,$distance);

function getPricePerDistance($carid,$distance){

    $farelist  =[

        ['miles_from'=>0,'miles_to'=>10, 'range' => '10', 'price' => 20],

        ['miles_from'=>10,'miles_to'=>15, 'range' => '5', 'price' => 15],

        ['miles_from'=>15,'miles_to'=>20, 'range' => '5', 'price' => 10],

        ['miles_from'=>20,'miles_to'=>25, 'range' => '5', 'price' => 9],

    ];

  

    $data = $farelist;

    $total_fare = 0;

    $total_distance = array_sum(array_map('intval', array_column($data, 'range')));

    

    if ($total_distance >= $distance) {

        $remaining_distance = $distance;

    

        foreach ($data as $d) {

            if ($remaining_distance > 0) { // Check if there's remaining distance to cover

           

                $range_start = intval($d['miles_from']);

                $range_end = intval($d['miles_to']);

                $distance_in_range = min($range_end - $range_start, $remaining_distance);

    

                $total_fare += $distance_in_range * $d['price']; // Calculate fare for this distance

                $remaining_distance -= $distance_in_range; // Update remaining distance

    

                if ($remaining_distance <= 0) {

                    break; // No more distance to cover, exit the loop

                }

            }

        }

    

        return $total_fare; // Output total fare

    } else {

        return  0; // If total distance is less than the requested distance

    }

}


?>

azure accoutn create

 https://azure.microsoft.com/en-in/free/search/?


https://portal.azure.com/?bundlingKind=DefaultPartitioner&configHash=mq7rHpfaLoDK&env=portal&helppanenewdesign=true&l=en.en-gb&pageVersion=13.260.2.113.260.0.1593201853.240415-2109#view/HubsExtension/BrowseResource/resourceType/Microsoft.Compute%2FVirtualMachines


sreeharshaveerapalli

70-532 ( fror developers)

70-534 (implementing solutions in mic azure)


build azure

dIFFERENT TYPES OF CLOUD ENVIRONMENT


IAAS

PAAS

SAAS

https://build5nines.com/azure-cdn-endpoint-interactive-map/

it is telling that , where azure data center locations available


https://portal.azure.com/ it is called azrure resource manager arm

https://www.youtube.com/watch?v=tFG5YKvR2-s



after login it is showing like this

everything like a service

azure with deveops => practicals => 


search for virtual machines in search bar and select that 


https://portal.azure.com/#view/HubsExtension/BrowseResource/resourceType/Microsoft.Compute%2FVirtualMachines






select azure virtual machine 




in resourc egroup 

create resource

name give 

some like pc name 

myvm 

give the details like below 



==


click on next disk 

disk 



networking






management


monitoring


next advanced and anext tags







after create 




click on resource


https://portal.azure.com/#@narayanavamsikrishnagmail.onmicrosoft.com/resource/subscriptions/a0823459-3c2d-4588-8a0a-3b89321f35bb/resourcegroups/myvmg/providers/Microsoft.Compute/virtualMachines/laravel-deployment/overview




virtual machins



click on virtual machine 

connect 



click on ssh using azure cli


click on confugre and connect


click on native os


ssh -i ~/.ssh/id_rsa.pem azureuser@20.195.168.136

azure-ssh-key.pem

ssh -i azure-ssh-key.pem  azureuser@20.195.168.136

commands i used

exit

 chmod 400 azure-ssh-key.pem 

 2004  ssh -i azure-ssh-key.pem  azureuser@20.195.168.136


    2  sudo apt update

    3  sudo nano /etc/ssh/sshd_config

    4  sudo service sshd reload

    5  sudo apt update

    6  sudo apt upgrade

    7  sudo apt install zip unzip

    8  sudo apt install apache2

    9  sudo service apache2 restart

   10  sudo mkdir www

   11  cd www

   12  git clone https://gitlab.com/vamsigdv/docker-laravel.git

   13  cd ../

   14  sudo chmod -R 777 www

   15  cd www

   16  git clone https://gitlab.com/vamsigdv/docker-laravel.git

   17  ls

   18  cd docker-laravel/

   19  ls

   20  git branch

   21  git checkout laravel

   22  git pull orgin laravel

   23  git pull

   24  ls

   25  docker-compose u p -d

   26  sudo apt install apt-transport-https ca-certificates curl software-properties-common

   27  curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

   28  sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"

   29  sudo apt install docker-ce

   30  sudo systemctl status docker

   31  docker -v

   32  docker-compose -v

   33  sudo apt install docker-compose

   34  sudo docker-compose up -d

   35  ls

   36  docker-compose up -d

   37  composer install

   38  sudo apt install composer 

   39  composer install

   40  php -v

   41  sudo apt install php libapache2-mod-php php-mbstring php-xmlrpc php-soap php-gd php-sqlite3 php-cli php-zip php-bcmath php-tokenizer php-json php-pear php-mysql php-curl php-memcached php-xdebug php-intl php-fpm php-pgsql php-imap

   42  composer install

   43  sudo apt install php8.2-curl

   44  sudo apt install php -curl

   45  sudo add-apt-repository ppa:ondrej/php

   46  sudo apt install php8.2

   47  sudo update-alternatives --set php /user/bin/php8.2

   48  sudo update-alternatives --set php /usr/bin/php8.2

   49  php -v

   50  sudo apt install php libapache2-mod-php php-mbstring php-xmlrpc php-soap php-gd php-sqlite3 php-cli php-zip php-bcmath php-tokenizer php-json php-pear php-mysql php-curl php-memcached php-xdebug php-intl php-fpm php-pgsql php-imap

   51  composer install

   52  sudo apt-get install php8.2-dom

   53  composer install

   54  composer self-update

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

   56  php composer-setup.php --install-dir=/usr/local/bin --filename=composer

   57  composer clear-cache

   58  composer self-update

   59  sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer

   60  sudo chmod a+w /usr/local/bin

   61  php composer-setup.php --install-dir=/path/to/your/directory --filename=composer

   62  composer self-update

   63  composer install

   64  ls

   65  nano composer.json

   66  cd ../

   67  composer create-project laravel/laravel:^8.0 example-app

   68  sudo apt-get install php-mbstring

   69  composer create-project laravel/laravel:^8.0 example-app

   70  php -m | grep mbstring

   71  php -i | grep php.ini

   72  nano /etc/php/8.2/cli/php.ini

   73  sudo i

   74  sudo -i

   75  php -i | grep mbstring

   76  composer self-update

   77  sudo apt update

   78  sudo apt upgrade

   79  composer self-update

   80  sudo apt-get install php-mbstring

   81  composer self-update

   82  php -v

   83  history



laravel and vuejs installation in aws from scratch



services

compute

ec2

volumes

create a volume

give the examle gb 100

create volume



come down 
create voluem
==

after created volume 

its redirect to voulme list page

u can click on created volme

u can see total volume details



then go to instances 

left side bar

click on launch instance at instanc page

after its redirect to instance page

give the name 
select os  ( i selected ubuntu)
slect the machine image
architechture (default  selected(


select the key or create new key pair


pem is for ssh
ppk is for putty

aftrer click on create key pair 
it wil download to your local
remember the location where it is stored

after thet click on instances in side bar

then click on required instance row clock

click on connect 
it wirll redirect to instance page

you have pem file
go to where downloaded
and then enter
chmod 400 "pem file  name"

then 
ssh -i "pem file" ubuntu@ipaddressor domain name
given in above image


whjenver u enter that in terminal it shows connected succesfully then 
it will show specs


go back to list on instances page at aws
click on required isntances
it show the details in below window


click on security tab

click on that blue link security groups under
click on edit inbound rules
then
edit inbound rules




in terminal
sudo password root
change password 
new password 
retype



then chang e
sudo nano /etc/ssh/sshd_config
ctr+w

search for root
modify like this PermitRootLogin yes

then 



click on add rule
select alltcp
anywhere ipv4
select 0 ---



click on save rule

select the public dns 
it copy and enter into browser


similarly
PasswordAuthentication yes


ctrl+x
yes
name enter
then its saved

then reload this file

sudo service sshd reload

then 

sudo apt update

sudo apt upgrade

sudo apt install zip unzip

sudo apt install apache2

sudo service apache2 restart

it have to show like this default page when u visit browser ( when u copy the public ipv4dns)




then start to install laravel application using docker 

clone the git repository this 
git clone https://gitlab.com/vamsigdv/docker-laravel.git

it is a public repository 
then there is no need of user name and apassword

then 
ls
then move to docker-laravel
git checkout laravel

swithc to laravel branch 

git pull orgin laravel

docker-compose u p -d


not installaed docker 

so install docker step by step 
  1. sudo apt update


sudo apt install apt-transport-https ca-certificates curl software-properties-common

Next, install a few prerequisite packages which let apt use packages over HTTPS:

  1. sudo apt install apt-transport-https ca-certificates curl software-properties-common

Then add the GPG key for the official Docker repository to your system:

  1. curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

Add the Docker repository to APT sources:

  1. sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"

Finally, install Docker:

  1. sudo apt install docker-ce

Docker should now be installed, the daemon started, and the process enabled to start on boot. Check that it’s running:

  1. sudo systemctl status docker


if u know the terminal password
sudo usermod -aG docker ${USER}

su - ${USER}

docker -v

docker-compose -v
sudo apt install docker-compose

to know the password 
cat /etc/password

if sudo is must

sudo -i 

or 
sudo docker-compose up -d


docker ps -a
to knwo the containers status
docker images -a

to know the images status


url:8000


in docker file u can see the 
docker-compose.yml in 
\
phpmyadmin_testing:
    container_name: phpmyadmin_testing
    image: phpmyadmin/phpmyadmin
    restart: always
    environment:
        - PMA_HOST=mysql_testing
        - PMA_PORT=3306
    ports:
        - 8000:80

this is the database name and passwor d

 "MYSQL_USER=testing"
        - "MYSQL_PASSWORD=ueDMcQVb8JVCyjws"

check nginx server
 nginx:
    container_name: nginx
    image: nginx:1.17
    restart: always
    ports:
        - "9999:9999"

url:9999

check the databse connecting to root password

sudo docekr exec -it mysql_testing mysql -uroot -pueDMcQVb8JVCyjw
 docker exec -it mysql_testing mysql -uroot -pueDMcQVb8JVCyjw
  - "MYSQL_ROOT_PASSWORD=ueDMcQVb8JVCyjw"
        - "MYSQL_DATABASE=testing"

its logined to database from terminal

show databases;
exit


./dock php php artisan migrate 

if it is migratee it is ok 
otherwise 
error 

change the folder name to
oocker-laravel

nginx/default.conf folder 
i given my-laravel-app
so change the folder name to docker-laravel
folder nam e
is 
www/ in this location all fodlers is to be
move this folder 
mv docker-laravel www
docker-laravel move to www

then connect docker to mynetwork
docker network create --driver bridge mynetwork

docker network inspect mynetwork

docker network connect mynetwork php
docker network connect mynetwork mysql_testing
docker network inspect mynetwork

ls dockerFIle
nano DockerFile

if u got any eror while crfeating containers or iamges

just remove contaienrs and images , then re build

docker kill $(docker ps -q)
docker rm $(docker ps -a -q)

docker rmi -f $(docker images -q)
remove the container

sudo docker rm  composer php phpmyadmin
stop the contaienrs and then remove the containers

mv www larvel 
move the laravel to www

install composer 
sudo apt install composer 
composer update
composer install
composer dump-autoload
composer -v
php -v 
update php to latest version
sudo apt install php -curl

sudo add-apt-repository ppa:ondrej/php
sudo apt install php8.2
sudo apt install php8.2-curl
sudo update-alternatives --set php /user/bin/php8.2
sudo update-alternatives --set php /usr/bin/php8.2

sudo service apache2 restart
sudo apt install php-xml 
sudo apt install php-dom
sudo systemctl restart php-fpm
sudo 
php -i | grep intl
normaliser not found
sudo apt install php-intl

sudo apt install php-intl
sudo systemctl restart apache2
sudo systemctl restart nginx
sudo systemctl restart mysql
sudo systemctl restart php-fpm
sudo systemctl restart docker

  1. SysVinit Services (older CentOS, Debian, Ubuntu):

    • Restart Apache:
      bash
      sudo service apache2 restart
    • Restart Nginx:
      bash
      sudo service nginx restart
    • Restart MySQL:
      bash
      sudo service mysql restart
    • Restart PostgreSQL:
      bash
      sudo service postgresql restart
    • Restart PHP-FPM:
      bash
      sudo service php-fpm restart
    • Restart Docker:
      bash
      sudo service docker restart
=
sudo apt install php8.2-curl
sudo apt install php8.2-mbstring
sudo apt install php8.2-intl

mv .env-example .env

php artisan key:generate
php network get address get adddre info failed 
temporar yfailure in name in resiluton

below thing

http://localhost:8000/
http://localhost:9999/

docker-compose up -d

docker kill $(docker ps -q)
docker rm $(docker ps -a -q)

docker rmi -f $(docker images -q)
docker-compose stop
docker-compose down
docker ps -a
docker images -a


docker exec -it mysql_testing mysql -uroot -pueDMcQVb8JVCyjw

php and mysql_testing not connected to same network


docker network create --driver bridge mynetwork


docker network inspect mynetwork

docker network connect mynetwork php
docker network connect mynetwork mysql_testing
docker network inspect mynetwork

./dock php php artisan migrate

===

sudo apt install mysql-server
sudo nano /etc/phpmyadmin/config-db.php
sudo mysql

sudo apt install php8.2 libapache2-mod-php8.2 php8.2-mbstring php8.2-xmlrpc php8.2-soap php8.2-gd php8.2-sqlite3 php8.2-cli php8.2-zip php8.2-bcmath php8.2-tokenizer php8.2-json php8.2-pear php8.2-mysql php8.2-gettext php8.2-curl php8.2-memcached php8.2-xdebug php8.2-intl php8.2-fpm php8.2-pgsql php8.2-imap


sudo apt install php libapache2-mod-php php-mbstring php-xmlrpc php-soap php-gd php-sqlite3 php-cli php-zip php-bcmath php-tokenizer php-json php-pear php-mysql php-gettext php-curl php-memcached php-xdebug php-intl php-fpm php-pgsql php-imap


conclusion 
sudo password root
2 sudo passwd root
3 sudo nano /etc/ssh/sshd_config
4 sudo service sshd reload
5 sudo apt update
6 sudo apt upgrade
7 sudo systemctl restart ssh
8 sudo apt install zip unzip
9 sudo apt install apache2
10 sudo service apache2 restart
11 php -v
12 sudo apt install php libapache2-mod-php php-mbstring php-xmlrpc php-soap php-gd php-sqlite3 php-cli php-zip php-bcmath php-tokenizer php-json php-pear php-mysql php-gettext php-curl php-memcached php-xdebug php-intl php-fpm php-pgsql php-imap
13 sudo apt install php libapache2-mod-php php-mbstring php-xmlrpc php-soap php-gd php-sqlite3 php-cli php-zip php-bcmath php-tokenizer php-json php-pear php-mysql php-curl php-memcached php-xdebug php-intl php-fpm php-pgsql php-imap
14 php -v
15 git clone https://gitlab.com/vamsigdv/docker-laravel.git
16 ls
17 sudo mkdir www
18 mv docker-laravel www
19 sudo chmod -R 777 www
20 mv docker-laravel www
21 ls
22 cd www
23 ls
24 git checkout laravel
25 cd docker-laravel/
26 git checkout laravel
27 git pull origin laravel
28 ls
29 cd ../
30 cd docker-laravel/
31 git clone https://gitlab.com/vamsigdv/docker-laravel.git
32 sudo apt install apt-transport-https ca-certificates curl software-properties-common
33 curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
34 sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"
35 sudo apt install docker-ce
36 sudo systemctl status docker
37 docker -v
38 docker-compose -v
39 sudo apt install docker-compose
40 docker-compose -v
41 docker ps -a
42 sudo -i
43 sudo docker-compose up -d
44 ls
45 docker-compose up -d
46 sudo systemctl restart docker
47 sudo systemctl status docker
48 docker-compose up -d
49 docker -v
50 ls
51 cat docker-compose.yml
52 mv docker-laravel my-laravel-app
53 cd ../
54 mv docker-laravel my-laravel-app
55 ls
56 cd my-laravel-app/
57 docker-compose up -d
58 cd ../
59 docker -v
60 cd my-laravel-app/
61 ls
62 cat docker-compose.yml
63 docker-compose up -d
64 pip install --upgrade docker
65 docker -v
66 docker-compose -v
67 docker-compose up -d
68 cd ../
69 docker run hello-world
70 sudo docker run hello-world
71 ls
72 cd ../
73 rm -rf www
74 ls
75 git clone https://gitlab.com/vamsigdv/docker-laravel.git
76 ls
77 cd docker-laravel/
78 ls
79 git checkout larvel
80 git checkout laarvel
81 git checkout laravel
82 git pull origin laravel
83 docker-compose up -d
84 docker
85 docekr -v
86 docker -v
87 sudo docker-compose up -d
88 docker compose u p -d
89 docker compose up -d
90 sudo docker compose up -d
91 ls
92 mv docker-laravel my-laravel-app
93 cd ../
94 mv docker-laravel my-laravel-app
95 ls
96 sudo mkdir www
97 mv my-laravel-app www
98 sudo chmod -R 777 www
99 ls
100 mv my-laravel-app www
101 ls
102 cd www
103 ls
104 docker kill $(docker ps -q)
105 docker rm $(docker ps -a -q)
106 docker rmi -f $(docker images -q)
107 sudo -i
108 ls
109 cd my-laravel-app/
110 docker compose up -d
111 sudo docker compose up -d
112 composer -v
113 sudo apt install composer
114 composer update
115 composer install
116 composer dump-autoload
117 cat .nv
118 cat .env
119 sh clear-all-cache.sh
120 docker network create --driver bridge mynetwork
121 sudo -i
122 ./dock php php artisan migrate
123 sudo ./dock php php artisan migrate
124 docker exec -it php bash
125 sudo docker exec -it php bash
126 sudo -i
127 cd
128 chown -R www-data:www-data /var/www/html/my-laravel-app
129 chown -R www-data:www-data /var/www/html/my-laravel-app
130 chmod -R 755 /var/www/html/my-laravel-app
131 cd www
132 cd my-laravel-app/
133 docker exec -it php bash
134 sudo docker exec -it php bash
135 sudo -i
136 history

sudo docker exec -it php bash

cd my-laravel-app
2 ls
3 cd www/my-laravel-app
4 php artisan migrate
5 chown -R www-data:www-data /var/www/html/my-laravel-app
6 chmod -R 755 /var/www/html/my-laravel-app
7 exit
8 pwd
9 cd ../
10 pwd
11 ls
12 cd my-laravel-app/
13 php artisan migrate
14 php artisan key:generate
15 history


sudo -i
root@ip-172-31-24-214:~# history
1 dokcer-compose up -d
2 docker-compose up -d
3 exit
4 docker kill $(docker ps -q)
5 docker rm $(docker ps -a -q)
6 docker rmi -f $(docker images -q)
7 ls
8 exit
9 docker network create --driver bridge mynetwork
10 docker network inspect mynetwork
11 docker network connect mynetwork php
12 docker network connect mynetwork mysql_testing
13 docker network inspect mynetwork
14 exit
15 chown -R www-data:www-data /var/www/html/my-laravel-app
16 chmod -R 755 /var/www/html/my-laravel-app
17 exit
18 history



===

vuejs 


cd frontend/
141 docker compose u p -d
142 docker compose up -d
143 sudo -i
144 sudo docker compose up -d
145 sudo ./dock node npm run server
146 docker exec -it node bash
147 sudo docker exec -it node bash
148 npm run build
149 npm install -g @vue/cli
150 npm install -g npm@10.6.0
151 npm install -g npm@8
152 sudo npm install -g npm@8
153 npm -v
154 sudo npm install -g npm@10.6.0
155 curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
156 nvm ls-remote
157 export NVM_DIR="$HOME/.nvm"
158 [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
159 [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
160 curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
161 exit
162 cd www
163 cd frontend/
164 nvm use 8
165 nvm install 10
166 nvm use 10
167 npm -v
168 nod e-v
169 node -v
170 sudo apt update
171 sudo apt install nodejs
172 nvm list-remote
173 nvm install 20.12.2
174 nvm use 20.12.2
175 node -v
176 npm install -g @vue/cli
177 vue -v
178 vue -V
179 npm run build
180 npm install --save-dev @vue/cli-service
181 npm install
182 npm run build
183 ls
184 nano docker-compose.yml
185 cd nginx
186 ls
187 cat default.conf
188 cd ../
189 docker-compose build
190 docker-compose up -d
191 docker compose build
192 sudo docker compose build
193 sudo docker compose u p-d
194 sudo docker compose up -d
195 npm install
196 cat docker-compose.yml
197 cat Dockerfile
198 docker-compose logs node
199 docker compose logs node
200 sudo docker compose logs node
201 ppwd
202 pwd
203 nano docker-compose.yml
204 docker compose up -d
205 nano docker-compose.yml
206 git status
207 git diff
208 nano docker-compose.yml
209 docker compose up -d
210 dudo docker compose up -d
211 sudo docker compose up -d
212 git status
213 history



Event listening in react

 How we can listen to som eevents some envents fire like click or automatically user enters into input button , that is event on word type i...