Яндекс.Метрика
qr-код - Как-то так стрелка - Как-то так
Leading Economist + ... пиктограмма - Как-то Так THIS     Economic literacy and web solutions
All on the topic: what, how and why. Actual things - in their own words.
Turn your quality WITH ME - BUTW !
If you don't like what you get, change what you give. © Carlos Castaneda     KAKTOTAK.BY - economic design and web development services (php/js - telegram, WordPress, Laravel, Vue, SEO)    Cooperation - on an ongoing basis    Be in the topic   -    SUBSCRIBE      My notes are ECONOMICS +  и  WEB Developer's Guide | php+js+seo   в Telegram   telegram  

How to deploy a project: a step-by-step guide to deploying and updating an application

How to deploy a project: a step-by-step guide to deploying and updating an application

When developing your own project, after making any changes to it, it becomes necessary to deploy it. This is because the changes that have been made require updating the code on the server to ensure that they are available to users.

What is a project deployment?

Project deployment is the process of deploying applications or websites on a server in order to make them available to users. This process includes several steps such as:

  • Updating the code: getting the latest version of the code from the repository, for example, using the git pull command.
  • Installing dependencies: installing the necessary libraries and packages, for example, using composer or npm.
  • Performing migrations: Applying changes to the database structure using the appropriate commands for migrations.
  • Caching: Optimize configuration, routes, and events to improve application performance.
  • Restarting the server: Sometimes it may be necessary to restart the service or application to fully apply the changes.

Thus, the deployment process helps to move from the development stage to the current version of the application, which becomes available to users.

A step-by-step algorithm for the process of quickly updating the project on the server

In order to prepare our project for updating on the server, you need to create a filedeploy.sh in the root of the project on the local server. This file will contain a bash script, the execution of which on an external server will deploy our project. The script will include executing the git pull command to get all the changes from GitHub and other necessary operations.

Example of the contents of the filedeploy.sh :


#!/bin/bash

# Go to the project directory
cd /path/to/your/project

# Performing a git pull to update the code
git pull origin master

# (Optional) We install dependencies if we use, for example, npm or composer
# npm install
# composer install

# (Optional) We execute commands to build the project, if required
# npm run build

# Restart the server if required (for example, using systemctl or pm2)
# sudo systemctl restart service_name
# pm2 restart application name

echo "Deployment completed!"

    

An example from a real project:


#!/bin/bash

set -e

git pull origin master
php8.2 artisan down
php8.2 composer.phar install --no-dev --optimize-autoloader
php8.2 artisan migrate --force
php8.2 artisan config:cache
php8.2 artisan event:cache
php8.2 artisan route:cache
php8.2 artisan up

    

After the filedeploy.sh has been created, you need to run the following commands in the console of our project on the local server:


git add .
git commit -m "Change 1"
git push origin master

    

(if you work in the master branch)

Next, you need to connect to an external server (hosting) using the command:


ssh -i ~/.ssh/id_rsa username@server_address

    

P.S. The ssh -i ~/.ssh/id_rsa command is used to connect to a remote server using the specified key file for authentication. The key file is usually generated on our local machine and must have proper access rights. Learn more here.

After we have connected to the server console, we need to go to the folder of our project and run the bash script we created deploy.sh . This can be done using the following command:


sh deploy.sh

  

Executing this script will perform all the steps specified in it, which will ensure a quick update of the project on the server. As a result, users will be able to access the latest changes that have been made to the code.

автор - Михаленко Р.
M R. Автор - kaktotak.by Specialization: financial and economic design - modeling of business, investment projects of the real sector, analysis and evaluation of efficiency, optimization of the management decision system.

A wide range of web-based competencies for solving business problems.

Subscribe to my telegram channel - My notes are ECONOMICS +
Improve your quality with me - what, how and why in economics in a simple way. Micro and macro aspects.

And also - WEB Developer's Guide | php+js+seo
Notes and native solutions to simple local tasks in PHP, JS. Something about Laravel, WordPress, Vue and SEO.

  Personal assistance in economic design and web development:

  • Financial and economic modeling, analysis, accounting, business planning
  • Comprehensive web development/project support on the web (php/js, seo – Laravel, WordPress, Vue, telegram, administration, content, advertising in Yandex Direct

  telegram или форма обратной связи

Administrator
19
0
Name
E-mail
Rating
Review

Currency Converter
RUB RUB-icon
USD USD-icon
EUR EUR-icon
CNY CNY-icon
BYN BYN-icon
UAH UAH-icon
KZT KZT-icon
SHORT- what is it about
ECONOMIC LITERACY
  Simple online solutions to problems of economics and finance  
I Want To Know Everything. Useful Tips