🐘
Languages & Build

PHP

Server-side language for WordPress, Laravel, and web apps

🐧 Linux🍎 Mac🪟 Windows
Reviewed: Tested on: Kubernetes 1.29 · Terraform 1.8 · Ubuntu 22.04

What is this?

PHP runs WordPress, Laravel, and millions of websites — usually paired with Nginx or Apache.

📥

Step 01

Install PHP

(01)Install PHP

Linux
1sudo apt-get install -y php php-cli php-fpm php-mysql php-curl php-xml php-mbstring
2sudo systemctl enable php8.3-fpm
⚙️

Step 02

Configure PHP

(01)Configure PHP

Linux
1php -v
2sudo nano /etc/php/8.3/fpm/php.ini
3# Set memory_limit, upload_max_filesize
4sudo systemctl restart php8.3-fpm

Step 03

Verify

(01)Verify installation

Linux
1php -v
2php -m | grep -E 'curl|mysql|mbstring'

Step 04

Manage PHP

(01)Common tasks

Linux
1composer --version
2composer create-project laravel/laravel myapp

📋Config templates

3 YAML templates for PHP. Copy and deploy after setup.

3 ready-to-copy templates. Expand one, copy the YAML, then run the deploy commands.

Jenkinsfile

yaml
1pipeline {
2 agent any
3
4 environment {
5 DOCKERHUB_CREDENTIALS = credentials('dockerhub')
6 }
7
8 stages {
9 stage('Docker Login') {
10 steps {
11 sh 'echo $DOCKERHUB_CREDENTIALS_PSW | docker login -u $DOCKERHUB_CREDENTIALS_USR --password-stdin'
12 }
13 }
14 stage('Build & Push Image') {
15 steps {
16 sh """
17 cd laravel-app
18 docker build -t $DOCKERHUB_CREDENTIALS_USR/laravel-app:latest .
19 docker push $DOCKERHUB_CREDENTIALS_USR/laravel-app:latest
20 """
21 }
22 }
23 stage('Deploy with Compose') {
24 steps {
25 sh """
26 cd laravel-app
27 docker compose pull
28 docker compose up -d
29 docker compose ps
30 """
31 }
32 }
33 }
34}

laravel-app/docker-compose.yml

yaml
1services:
2 app:
3 image: youruser/laravel-app:latest
4 ports:
5 - "8080:80"
6 depends_on:
7 - db
8 environment:
9 DB_HOST: db
10 DB_DATABASE: laravel
11 DB_USERNAME: root
12 DB_PASSWORD: secret
13
14 db:
15 image: mysql:5.7
16 environment:
17 MYSQL_DATABASE: laravel
18 MYSQL_ROOT_PASSWORD: secret
19 volumes:
20 - db_data:/var/lib/mysql
21
22volumes:
23 db_data:
📄

Step 01

Run Jenkins Pipeline

(01)Configure Jenkins

Linux
1# Add Docker Hub credentials (ID: dockerhub) in Jenkins
2# Install Docker + docker-compose on Jenkins agent
3# Create Pipeline job pointing to Jenkinsfile