Jenkins Deploys PHP applications

Source: Internet
Author: User
Tags coding standards pear ssh server

Installing Jenkins

Mode One: Docker mode installation

Pull the official Jenkins image and start mirroring in the mirrored document.

Mode two: Manual installation

All of the following actions are performed using the root user.

Download Java, Tomcat, Jenkins on each project website

Java:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html tomcat:http:// tomcat.apache.org/download-90.cgi Jen jenkins:https://jenkins.io/

Environment used: jdk1.8.0_121 Tomcat-9.0.0.m17 Jenkins 2.32.2

I put the tar.gz compressed package in the/opt/directory and extracted it into the/usr/local/src.

Installing Java

The extracted Java Baumer think jdk1.8.0_121

Configure the Java environment variables vim /etc/profile to include:

#javaJAVA_HOME=/usr/local/src/jdk1.8.0_121 #这行根据实际情况修改PATH=$JAVA_HOME/bin:$PATHCLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

After the modification is complete, use the source /etc/profile new configuration to take effect.

Installing Tomcat

After extracting the Tomcat Baumer think Apache-tomcat-9.0.0.m17

Use the chmod a+x apache-tomcat-9.0.0.M17/bin/*.sh command to give Tomcat the ability to start a shell script execution.

Execution bin/catalina.sh run can see the Tomcat boot from the console to ensure that Tomcat starts correctly.

To have Tomcat run in the background, use thebin/startup.sh

Installing Jenkins

Put Jenkins's. War package in Tomcat's WebApps directory and runbin/startup.sh

You can then http://<你的ip地址>/jenkins/ access the installed Jenkins

Then follow the instructions on the page to complete the final installation

Jenkins Plugin
    • subversion/git: For integrated project version control software, select as needed (used in previous blog post)
    • phing/ant: Use phing or Apache Ant to automate the construction of PHP projects
    • CheckStyle: A tool for code style checking using PHP codesniffer. A pear package to check if PHP code violates a set of pre-set coding standards, with built-in zend,pear coding style rules
    • Clover PHP: Tools that use PHPUnit for unit testing can be xdebug extended to generate code coverage reports, and can be integrated with phing for automated testing, and selenium integration to complete large-scale automated integration testing
    • DRY: Use PHPCPD (PHP copy paste detector) to discover duplicate code in your project
    • HTML publisher: Used to publish PHPUnit code coverage reports
    • JDepend: Use PHP depend to analyze static code in PHP to check the size and complexity of code in your project
    • Plot: Use Phploc to count PHP project size tools to count PHP project code lines
    • PMD: Using PHPMD (PHP mess Dector) to analyze results based on pdepend, a warning message will be issued once the project exceeds the requirements of each specific indicator in pdepend.
    • violations: Displays the results of PWD static code analysis in the Code defect severity set
    • xUnit: Use the JUnit format to output phpunit log files
Jenkins Deploying PHP Steps

Code Pull-Perform check (not required)-package-remote or on-premises deployment

There are many ways to deploy, and Jenkins also offers many plugins to optimize the deployment process

This document is mainly about remote deployment

Remote deployment pulls the code first, and we use git to manage the code.

Using Ssh-keygen to generate the public and private keys, git and log on to the remote server will be used.

Each project on the GIT repository has a deployment public key that adds the generated public key to the Git repository.

Then create a free-style Jenkins deployment project to enter the configuration.

Pull substitution Code

Choose Git, the default is to pull the master branch of the repository, click Add to add a pull-code voucher.

Kind SSH Username with private key private key select from the Jenkins Master ~/.ssh (the public private key has been generated using Ssh-keygen)

After creation, select the credentials, enter the address of the Git repository, then you can save and click on the build immediately, test the code can not be correctly pulled, pull the correct and click on the workspace to see the code in your code base.

Build

These build options are available by default, and the local build simply executes shell instructions using the Execute shell.

Remote build requires a new plugin to be installed, search the Publish over SSH plugin in the system Management-management plug-in-optional plugin and install, restart Jenkins to enable plugins.

Copy the local public key to the remote server root user's/root/.ssh/authorized_keys file.

Then in system administration-system setup-publish over SSH

Fill in the private key file address

Add an SSH server configuration

Build in select Send files or execute commands over SSH

Simple point can directly execute the shell instructions, to the project directory you want to deploy git directly pull remote code, but this is really not very big with Jenkins, you can package the code in this machine, then transfer to the remote machine, and then unpack to the project directory.

cd /var/www/webtar -czf project_`date +%F-%H-%M-%S`.bak.tar.gz --exclude=‘project/runtime‘ --exclude=‘project/.git‘ /home/www/web/projecttar xzf /var/www/web/project-tar/project.${BUILD_NUMBER}.${BUILD_ID}.tar.gz -C /home/www/web/projectchmod -R 755 /home/www/web/project/chmod 777 /home/www/web/project/web/assets/tail -n100 /home/www/web/project/runtime/logs/error.log

The above is an example of a series of operations such as online code backup packaging, unpacking new deployment packages, modifying permissions, and printing error logs.

Building a packaging operation is a tool that is used by phing and is interested to know about this tool

Jenkins Deploys PHP applications

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.