Home > Article > Backend Development > Docker+LNMP+Jenkins+Code Cloud realizes automatic deployment of PHP code
Automated deployment (continuous integration/CI continuous delivery/CD) is a trend in software development and is a good help for the development of DevOps. Today’s practice is based on the Docker Jenkins LNMP code cloud to realize the automated deployment process 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 Warehouse
Code Cloud Warehouse Preparation
Create Project Warehouse
Jenkins preparation
Install the ssh plug-in
Because building the project requires executing some shell commands on the server, So use ssh login method to communicate with the remote server.
1. System Management->Plug-in Management
2. Search: ssh, install it
##New project task
The task name cannot be in Chinese, choose the first one: Freestyle project Custom project ##Engineering task configuration1. Source code management selection: git
2. Repository URL: warehouse address (mine is the code cloud warehouse)
3. Credentials, select Add
4. Add credentials
5. Configure the warehouse private key (for details, please view the warehouse key management help of Code Cloud)
After the credentials are configured successfully, just select the Username configured in the previous step. If you successfully connect to the warehouse address, no error will be reported.
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 credentials git
Configure ssh1. System Management->System Configuration
2. Configure remote server ssh related information
Configure build shell scriptBuild: Execute shell script on remote host using ssh //Execute remote server shell script when building
1. Fill in SSH site //Remote server ssh Login
2. Command //shell script
Remarks:
Because the code is automatically deployed in the workspace directory of jenkins, and the project’s site directory is in /data/ www, so when building, you need to copy the updated code file to the project site (there are many ways to implement it. Here, use a copy of the code because the size of the code will not take up a lot of space. Nowadays, many static Resources are placed on some cloud services)
I initially used the soft connection method, but because nginx does not support soft connection access.
After the configuration is completed, click Save
Code Cloud Code PushModify the code in the code cloud warehouse, and then submit the PR to the master branch
Manual construction of deployment tasks
Click Build manually to realize automated code deployment
Remarks:
Also It can be configured to automatically build directly after monitoring git push (this is recommended for the test environment)
Clicking the build manually is for better management (this is recommended for the production environment)
If the task construction fails, there will be an error message and a red mark //very convenient for management
Visit the website
After the automated deployment task is successfully built, visit our project to see the modification effect
The above is the detailed content of Docker+LNMP+Jenkins+Code Cloud realizes automatic deployment of PHP code. For more information, please follow other related articles on the PHP Chinese website!