


Detailed explanation of the steps to deploy Github projects to the server
Mar 27, 2023 am 10:53 AMGithub is currently the largest open source community in the world. Many programmers will host their own code on Github to take advantage of its convenient version control and collaboration functions. However, the project on Github is just code, and deploying it to the server for running requires some extra work. This article will introduce you to the specific steps.
1. Log in to the server
Use SSH to connect remotely and enter the command:
ssh?root@your_server_ip
2. Install the necessary software
Install Git and Node.js on the server. Taking the Ubuntu system as an example, execute the following command:
sudo?apt-get?update sudo?apt-get?install?git sudo?apt-get?install?nodejs
3. Create a Git repository on the server
Create an empty directory on the server and put it in it Initialize a Git repository and execute the following command:
mkdir?myapp cd?myapp git?init?--bare
4. Set up Git Hooks
Add a post-receive hook in the Git repository to automatically deploy the application, execute The following command:
cd?hooks touch?post-receive sudo?chmod?+x?post-receive nano?post-receive
Enter the following content in the open text editor:
#!/bin/bash git?--work-tree=/var/www/html/myapp?--git-dir=/root/myapp.git?checkout?-f cd?/var/www/html/myapp sudo?npm?install
The script will automatically check out the code to /var/www/html/myapp and execute npm install command to install project dependencies.
5. Configure Webhooks on Github
Log in to Github, click the Webhooks option in the project's Settings page, and then click the Add webhook button. Enter the server's IP address and the path of the post-receive hook in the Payload URL, for example: http://your_server_ip:8000/hooks/post-receive. Select application/json in Content type and click Add webhook.
6. Add the server address in the local code
Modify the package.json file in the local code and add the following content:
{ ??"scripts":?{ ????"start":?"node?app.js", ????"deploy":?"git?push?deploy?master" ??}, ??"config":?{ ????"deploy":?{ ??????"production":?{ ????????"user":?"root", ????????"host":?"your_server_ip", ????????"ref":?"origin/master", ????????"repo":?"ssh://git@your_server_ip:/root/myapp.git", ????????"path":?"/var/www/html/myapp", ????????"ssh_options":?["StrictHostKeyChecking=no",?"PasswordAuthentication=no"], ????????"post-deploy":?"npm?install?&&?pm2?restart?app" ??????} ????} ??} }
Among them, the deploy script will push the code to the myapp.git warehouse on the server; some configuration items are defined in config/deploy/production, including the IP address of the server, the path of the project, the path of the hook, etc.
7. Execute code deployment
Execute the following command in the local code directory:
npm?run?deploy?production
This command will push the code to the server and trigger The post-receive hook automatically deploys the code to the /var/www/html/myapp directory.
8. Start the application
Go to the /var/www/html/myapp directory and execute the following command to start the application:
npm?start
The application should now run on the server! If the application fails to start, you need to check that the dependencies are installed correctly and that the application is configured correctly.
Summary:
The above are the steps to deploy the project on Github to the server. Although this process may seem tedious, using this approach allows for efficient code deployment and collaboration. At the same time, it also provides us with great learning opportunities, allowing us to have a deeper understanding of Git, Node.js and other technologies.
The above is the detailed content of Detailed explanation of the steps to deploy Github projects to the server. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

To view Git commit history, use the gitlog command. 1. The basic usage is gitlog, which can display the submission hash, author, date and submission information; 2. Use gitlog--oneline to obtain a concise view; 3. Filter by author or submission information through --author and --grep; 4. Add -p to view code changes, --stat to view change statistics; 5. Use --graph and --all to view branch history, or use visualization tools such as GitKraken and VSCode.

To delete a Git branch, first make sure it has been merged or no retention is required. Use gitbranch-d to delete the local merged branch. If you need to force delete unmerged branches, use the -D parameter. Remote branch deletion uses the gitpushorigin-deletebranch-name command, and can synchronize other people's local repositories through gitfetch-prune. 1. To delete the local branch, you need to confirm whether it has been merged; 2. To delete the remote branch, you need to use the --delete parameter; 3. After deletion, you should verify whether the branch is successfully removed; 4. Communicate with the team to avoid accidentally deleting shared branches; 5. Clean useless branches regularly to keep the warehouse clean.

To add a subtree to a Git repository, first add the remote repository and get its history, then merge it into a subdirectory using the gitmerge and gitread-tree commands. The steps are as follows: 1. Use the gitremoteadd-f command to add a remote repository; 2. Run gitmerge-srecursive-no-commit to get branch content; 3. Use gitread-tree--prefix= to specify the directory to merge the project as a subtree; 4. Submit changes to complete the addition; 5. When updating, gitfetch first and repeat the merging and steps to submit the update. This method keeps the external project history complete and easy to maintain.

To identify fake altcoins, you need to start from six aspects. 1. Check and verify the background of the materials and project, including white papers, official websites, code open source addresses and team transparency; 2. Observe the online platform and give priority to mainstream exchanges; 3. Beware of high returns and people-pulling modes to avoid fund traps; 4. Analyze the contract code and token mechanism to check whether there are malicious functions; 5. Review community and media operations to identify false popularity; 6. Follow practical anti-fraud suggestions, such as not believing in recommendations or using professional wallets. The above steps can effectively avoid scams and protect asset security.

As a pioneer in the digital world, Bitcoin’s unique code name and underlying technology have always been the focus of people’s attention. Its standard code is BTC, also known as XBT on certain platforms that meet international standards. From a technical point of view, Bitcoin is not a single code style, but a huge and sophisticated open source software project. Its core code is mainly written in C and incorporates cryptography, distributed systems and economics principles, so that anyone can view, review and contribute its code.

What are the key points of the catalog? UselessCoin: Overview and Key Features of USELESS The main features of USELESS UselessCoin (USELESS) Future price outlook: What impacts the price of UselessCoin in 2025 and beyond? Future Price Outlook Core Functions and Importances of UselessCoin (USELESS) How UselessCoin (USELESS) Works and What Its Benefits How UselessCoin Works Major Advantages About USELESSCoin's Companies Partnerships How they work together

There are three main ways to set environment variables in PHP: 1. Global configuration through php.ini; 2. Passed through a web server (such as SetEnv of Apache or fastcgi_param of Nginx); 3. Use putenv() function in PHP scripts. Among them, php.ini is suitable for global and infrequently changing configurations, web server configuration is suitable for scenarios that need to be isolated, and putenv() is suitable for temporary variables. Persistence policies include configuration files (such as php.ini or web server configuration), .env files are loaded with dotenv library, and dynamic injection of variables in CI/CD processes. Security management sensitive information should be avoided hard-coded, and it is recommended to use.en

This article has selected several top Python "finished" project websites and high-level "blockbuster" learning resource portals for you. Whether you are looking for development inspiration, observing and learning master-level source code, or systematically improving your practical capabilities, these platforms are not to be missed and can help you grow into a Python master quickly.
