Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

feat: PHP Composer support

Andras Bacsai7a2f29f6a39b
diff --git a/src/lib/buildPacks/php.ts b/src/lib/buildPacks/php.ts
index 14ee5d0cb2..cfb39d20a0 100644
--- a/src/lib/buildPacks/php.ts
+++ b/src/lib/buildPacks/php.ts
@@ -4,6 +4,12 @@ import { promises as fs } from 'fs';
const createDockerfile = async (data, image, htaccessFound): Promise<void> => {
const { workdir, baseDirectory } = data;
const Dockerfile: Array<string> = [];
+ let composerFound = false;
+ try {
+ await fs.readFile(`${workdir}${baseDirectory || ''}/composer.json`);
+ composerFound = true;
+ } catch (error) {}
+
Dockerfile.push(`FROM ${image}`);
Dockerfile.push(`LABEL coolify.image=true`);
Dockerfile.push('WORKDIR /app');
@@ -11,6 +17,10 @@ const createDockerfile = async (data, image, htaccessFound): Promise<void> => {
if (htaccessFound) {
Dockerfile.push(`COPY .${baseDirectory || ''}/.htaccess ./`);
}
+ if (composerFound) {
+ Dockerfile.push(`RUN composer install`);
+ }
+
Dockerfile.push(`COPY /entrypoint.sh /opt/docker/provision/entrypoint.d/30-entrypoint.sh`);
Dockerfile.push(`EXPOSE 80`);
await fs.writeFile(`${workdir}/Dockerfile`, Dockerfile.join('\n'));
@@ -21,12 +31,14 @@ export default async function (data) {
try {
let htaccessFound = false;
try {
- const d = await fs.readFile(`${workdir}${baseDirectory || ''}/.htaccess`);
+ await fs.readFile(`${workdir}${baseDirectory || ''}/.htaccess`);
htaccessFound = true;
} catch (e) {
//
}
- const image = htaccessFound ? 'webdevops/php-apache' : 'webdevops/php-nginx';
+ const image = htaccessFound
+ ? 'webdevops/php-apache:8.0-alpine'
+ : 'webdevops/php-nginx:8.0-alpine';
await createDockerfile(data, image, htaccessFound);
await buildImage(data);
} catch (error) {
diff --git a/src/routes/applications/[id]/configuration/buildpack.svelte b/src/routes/applications/[id]/configuration/buildpack.svelte
index cd005768cd..c885f3bf57 100644
--- a/src/routes/applications/[id]/configuration/buildpack.svelte
+++ b/src/routes/applications/[id]/configuration/buildpack.svelte
@@ -81,6 +81,9 @@
);
const indexHtml = files.find((file) => file.name === 'index.html' && file.type === 'blob');
const indexPHP = files.find((file) => file.name === 'index.php' && file.type === 'blob');
+ const composerPHP = files.find(
+ (file) => file.name === 'composer.json' && file.type === 'blob'
+ );
if (yarnLock) packageManager = 'yarn';
if (pnpmLock) packageManager = 'pnpm';
@@ -103,7 +106,7 @@
foundConfig = findBuildPack('python');
} else if (indexHtml) {
foundConfig = findBuildPack('static', packageManager);
- } else if (indexPHP) {
+ } else if (indexPHP || composerPHP) {
foundConfig = findBuildPack('php');
} else {
foundConfig = findBuildPack('node', packageManager);
@@ -127,6 +130,9 @@
);
const indexHtml = files.find((file) => file.name === 'index.html' && file.type === 'file');
const indexPHP = files.find((file) => file.name === 'index.php' && file.type === 'file');
+ const composerPHP = files.find(
+ (file) => file.name === 'composer.json' && file.type === 'file'
+ );
if (yarnLock) packageManager = 'yarn';
if (pnpmLock) packageManager = 'pnpm';
@@ -146,7 +152,7 @@
foundConfig = findBuildPack('python');
} else if (indexHtml) {
foundConfig = findBuildPack('static', packageManager);
- } else if (indexPHP) {
+ } else if (indexPHP || composerPHP) {
foundConfig = findBuildPack('php');
} else {
foundConfig = findBuildPack('node', packageManager);