Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize automatic deployment of PHP Code in Docker+LNMP+Jenkins+ Code Cloud

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article introduces how to realize the automatic deployment of PHP code in Docker+LNMP+Jenkins+ Code Cloud. The content is very detailed. Interested friends can use it for reference. I hope it will be helpful to you.

Automated deployment (continuous integration / CI + continuous delivery / CD) is a trend in software development and is a good help for DevOps. Today's practice is based on Docker+Jenkins+LNMP + Code Cloud to automate the deployment of PHP code.

Environment configuration

Operating system: CentOS Linux release 7.6.1810

Docker version: 19.03.5

Jenkins version: 2.204.1

Nginx version: 1.15.5

PHP version: 7.2.26

MySQL version: 8.0.18

Redis version: 5.0.5

Code Cloud: code Repository

Prepare the yard cloud warehouse.

Create a project warehouse

Jenkins preparation

Install the ssh plug-in

Because of the construction project, some shell commands of the server need to be executed, so the ssh login mode is used to communicate with the remote server.

1. System Management-> plug-in Management

two。 Search: ssh, install it

New project task

The task name cannot be in Chinese. Choose the first one: Freestyle project Custom Project

Engineering task configuration

1. Source code management option: git

2. Repository URL: warehouse address (mine is Ma Yun Warehouse)

3. Credentials choose to add

4. Add credentials

5. Configure the private key of the warehouse (for more information, please see the warehouse key management help of Shiyun)

After the credential configuration is successful, select the Username configured in the previous step. If you successfully connect to the warehouse address, there will be no error.

Build trigger selection: Github hook trigger for GITScm polling

Build environment: Use secret text (s) or file (s) / / transfer files privately

Credentials: select the specified credential git

Configure ssh

1. System Administration-> system configuration

two。 Configure remote server ssh related information

Configure build shell script

Build: Execute shell script on remote host using ssh / / execute remote server shell scripts during build

1. Fill in SSH site / / remote server ssh login

2. Command / / shell script

Note:

Because the code is automatically deployed under the workspace workspace directory of jenkins and the site directory of the project is under / data/www, you need to copy the updated code files to the project site during construction. (there are many ways to implement this. Here we use the code to make a copy, because the size of the code does not take up much space, and now many static resources are placed on some cloud services.)

The soft connection method was used at first, but because nginx does not support soft connection access.

Once the configuration is complete, click Save.

Code push

Modify the code for Cloud Warehouse, and then submit the PR to the master branch

Deployment tasks are built manually

Automatic code deployment can be achieved by manually clicking build.

Note:

It can also be configured to automatically build directly after monitoring the git push (recommended in the test environment)

Click build manually for better management (recommended in the production environment)

If the task fails to build, there will be an error message and a red flag / / it is easy to manage

Visit the website

After the automated deployment task is built successfully, visit our project to see the effect of the modification.

This is the end of how to realize the automatic deployment of PHP code in Docker+LNMP+Jenkins+ Code Cloud. I hope the above content can be of some help and learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report