How to use php-cli from within n8n docker container?

Hello,

I’ve seen this one:

and tried:

docker run -it n8nio/n8n  /bin/ash
/data $ apk update && apk upgrade
ERROR: Unable to lock database: Permission denied
ERROR: Failed to open apk database: Permission denied

How would I install php in my n8n docker?
Is it wise to do so in the first place, or would it be better to add an image like ‘traefik’ via the docker-composer? (and if so - how? I’m fairly new to the docker).

Hey @Chris7935,

Do you want to use access the php-cli via SSHing to your server? Or do you want to access the php-cli on the same server, without SSH?

Just by the execute command node. (So ideally without SSH)

This post can be helpful: Running Python with n8n - #2 by dali

That does help somewhat.
What I don’t seem to be understanding yet is:
I’ve got all my workflows etc. already build. Now I’d just like to add php - but keep everything as it is.
Will I be overriding anything with the instructions in Running Python with n8n - #6 by chris ?
(it sounds more like taking a new image?)

Are you using a docker-compose file to start the n8n docker container?

In any case, I would suggest that you make sure you have persistent data storage. I suggest you read on storage here: Manage data in Docker | Docker Documentation

Yes, docker-compose.
And I’ve “mounted” a folder on my host file system which persists after I switched of docker - that’s working well.
I’m more worried about the workflows that I’ve built - they are stored inside a SQLite, if I understood that correctly? I didn’t want to move to MySQL or PostgreSQL for my first server with n8n (mostly a MVP at the moment).

The link that you’ve shared (Running Python with n8n - #2 by dali) sounds like I’d be adding sth. to a docker file and I’d be re-creating my n8n ‘instance’ from the docker file + PHP. I assumed, I’d loose my workflows which are currently in SQLite?

I am not 100% certain, but if you add it your docker-compose file, and restart it, you should be fine. You shouldn’t loose any data.

Hey @Chris7935,

Just wanted to check-in and see if you still need help :slight_smile:

It’s working now, but I’m sure it’s a quick an dirty solution:

docker-compose up -d 

docker container ls 
docker exec -it a481d64b5481  /bin/ash
# whoami
root

apk add php7 php7-cli php7-gd php7-ftp
php -v
exit

Do you have some examples of how to add this to my docker compose file?

Not sure about within the compose file but you could just make your own dockerfile and pull the n8n image and install your extras then use that as your image for compose.

That link above has a comment from Jan on it showing how you can do it.

1 Like