Skip to content

feat: implemented e2b php template #105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions templates/deploy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const { execSync } = require("child_process")
const path = require("path")
const fs = require("fs")

// Get template name from command line args
const templateName = process.argv[2]

function deployTemplate(dir) {
try {
// Change to template directory
process.chdir(dir)
console.log(`Deploying template in ${dir}...`)

// Run e2b template build
execSync("e2b template build", { stdio: "inherit" })

console.log(`Successfully deployed template in ${dir}`)
} catch (error) {
console.error(`Error deploying template in ${dir}:`, error.message)
process.exit(1)
}
}

// If template name is provided, deploy only that template
if (templateName) {
const templateDir = path.join(__dirname, templateName)
if (!fs.existsSync(templateDir)) {
console.error(`Template directory ${templateName} not found`)
process.exit(1)
}
if (!fs.existsSync(path.join(templateDir, "e2b.toml"))) {
console.error(`No e2b.toml found in ${templateName}`)
process.exit(1)
}
deployTemplate(templateDir)
} else {
// Deploy all templates that have e2b.toml
const entries = fs.readdirSync(__dirname, { withFileTypes: true })
for (const entry of entries) {
if (entry.isDirectory()) {
const templateDir = path.join(__dirname, entry.name)
if (fs.existsSync(path.join(templateDir, "e2b.toml"))) {
deployTemplate(templateDir)
}
}
}
}
8 changes: 5 additions & 3 deletions templates/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,24 @@
"scripts": {
"build": "tsc",
"dev": "tsc --watch",
"deploy": "sh deploy.sh"
"deploy": "node deploy.js"
},
"exports": {
".": "./dist/index.js",
"./configs": "./dist/index.js",
"./nextjs": "./nextjs",
"./reactjs": "./reactjs",
"./streamlit": "./streamlit",
"./vanillajs": "./vanillajs"
"./vanillajs": "./vanillajs",
"./php": "./php"
},
"files": [
"dist",
"nextjs",
"reactjs",
"streamlit",
"vanillajs"
"vanillajs",
"php"
],
"devDependencies": {
"typescript": "^5.8.3",
Expand Down
8 changes: 8 additions & 0 deletions templates/php/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Ignore Git and system files
.*

# Ignore E2B files
e2b*

# Ignore environment-specific node_modules
node_modules
2 changes: 2 additions & 0 deletions templates/php/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
54 changes: 54 additions & 0 deletions templates/php/e2b.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Use the E2B base image
FROM e2bdev/code-interpreter:latest

# Install PHP and Apache
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y \
php \
php-cli \
php-common \
libapache2-mod-php \
apache2 && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

# Install Node.js (which includes npm)
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \
apt-get install -y nodejs

# Clear npm cache to avoid conflicts
RUN npm cache clean --force

# Initialize npm and install Vite and the PHP plugin
WORKDIR /home/user/project
RUN npm init -y && \
npm install --save-dev vite vite-plugin-php

# Enable Apache rewrite module
RUN a2enmod rewrite

# Configure Apache for the project directory
RUN echo '<VirtualHost *:80>\n\
DocumentRoot /home/user/project\n\
<Directory /home/user/project>\n\
Options Indexes FollowSymLinks\n\
AllowOverride All\n\
Require all granted\n\
</Directory>\n\
</VirtualHost>' > /etc/apache2/sites-available/000-default.conf

# Set proper permissions for the project directory
RUN mkdir -p /home/user/project && \
chown -R www-data:www-data /home/user/project && \
chmod -R 755 /home/user/project

# Copy everything from the current directory into /home/user/project
COPY . /home/user/project

# Expose port 80
EXPOSE 80

# Start Apache
CMD ["apache2-foreground"]


16 changes: 16 additions & 0 deletions templates/php/e2b.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# This is a config for E2B sandbox template.
# You can use template ID (8zr0kth5jzu5pdfq9afh) or template name (gitwit-php) to create a sandbox:

# Python SDK
# from e2b import Sandbox, AsyncSandbox
# sandbox = Sandbox("gitwit-php") # Sync sandbox
# sandbox = await AsyncSandbox.create("gitwit-php") # Async sandbox

# JS SDK
# import { Sandbox } from 'e2b'
# const sandbox = await Sandbox.create('gitwit-php')

team_id = "34eab90a-97dc-4be5-87e3-a17b6e6e8bc6"
dockerfile = "e2b.Dockerfile"
template_name = "gitwit-php"
template_id = " "
37 changes: 37 additions & 0 deletions templates/php/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PHP Project</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="bg-light">
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
<div class="container">
<a class="navbar-brand" href="#">Sandbox</a>
</div>
</nav>

<di

v class="container mt-5">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card shadow-lg">
<div class="card-header bg-primary text-white">
<h2 class="text-center">Start Building your amazing project</h2>
</div>
<div class="card-body text-center">
<h1 class="display-4 text-primary">
<?php echo "Hello, PHP!"; ?>
</h1>
<p class="lead mt-3">This is a dynamic page powered by PHP and styled with Bootstrap.</p>
</div>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
14 changes: 14 additions & 0 deletions templates/php/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "php-vite-template",
"version": "1.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
},
"devDependencies": {
"vite": "^5.0.0",
"vite-plugin-php": "^1.0.0"
}
}
15 changes: 15 additions & 0 deletions templates/php/vite.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import path from "path"
import { defineConfig } from "vite"
import php from "vite-plugin-php"
export default defineConfig({
plugins: [php()],
server: {
host: "0.0.0.0",
allowedHosts: true, // Allow all hosts
},
resolve: {
alias: {
"@": path.resolve(__dirname, "./src"),
},
},
})