Automate PHP Packaging and Deployment with Jenkins: A Step‑by‑Step Guide
This tutorial walks PHP developers through installing Jenkins, creating a freestyle job, configuring source control, setting environment variables, writing a shell build script, defining post‑build actions, and running the pipeline to achieve automated packaging and deployment.
1. Install Jenkins
First install Jenkins on the server using the appropriate method for the operating system, then open the Jenkins management UI in a browser.
2. Create a new Jenkins job
Click “New Item”, provide a job name, select “Freestyle project”, and confirm to create the job.
3. Configure source code repository
In the job configuration, locate the “Source Code Management” section, choose Git, SVN, or another VCS, enter the repository URL, credentials, and the branch to build.
4. Set up build environment variables
Add two environment variables in the “Build Environment” section:
PHP_HOME – path to the PHP interpreter, e.g., /usr/bin/php.
COMPOSER_HOME – path to Composer, e.g., /usr/local/bin/composer.
5. Define the build script
Add an “Execute shell” build step and paste the following script (adjust paths as needed):
# Enter project directory
cd /path/to/project
# Install Composer dependencies
composer install
# Run PHP unit tests
phpunit
# Package the PHP application
tar -czf release.tar.gz .6. Configure post‑build actions
In the “Post‑build Actions” section, choose actions such as archiving the build artifacts or deploying them to another server.
7. Save and run the job
Save the configuration, then trigger the job manually with “Build Now”. Each commit to the repository will automatically start the build, run tests, and produce the packaged artifact, which can be inspected via Jenkins build history.
Conclusion
Jenkins provides a powerful CI/CD pipeline for PHP projects, automating packaging and deployment, improving development efficiency and code quality.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
php Courses
php中文网's platform for the latest courses and technical articles, helping PHP learners advance quickly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
