How to create a snap with PHP as a dependency?

I have just completed the first pass of my CLI app which I wrote using Laravel Zero. Laravel Zero is a micro-framework for building console applications. It is based on PHP and uses Laravel and Symfony components.

I’m stuck and don’t know how to add PHP as a dependency.

Any help would be really appreciated.

Thanks in advance.

In Nextcloud we build PHP from source (and also support building PHP modules). You’re welcome to steal that if it’s helpful.

1 Like

Thanks!
It would be really great if you could take my hand and guide me.
If I understand correctly, I just grab the php section. Right?

You’ll need the PHP section as well as the PHP plugin if you care about building modules. If you don’t you can probably get away with using the built-in autotools plugin and modifying the YAML you’re copying slightly.

1 Like

I gave it a shot and added the php section as well as copied the php plugin but I got this error.

Screenshot%20from%202020-03-03%2001-23-09

Would you mind sharing your snapcraft.yaml?

Sure, Here it is.

This seems to have changed since that error was raised. It’s due to your app command starting with php, although your snapcraft.yaml doesn’t appear to have that anymore. Did you modify it for posting here? Regardless, try changing it to command: bin/php <whatever> instead of what you were using.

1 Like

I see. Thanks!
Let me give it a shot.

I removed the thnings I don’t need like redis and boost section. Now it gave this error after :
unknown plugin: php
Screenshot%20from%202020-03-03%2002-10-02

Re-ran
Screenshot%20from%202020-03-03%2002-15-51

Where did you place the PHP plugin you took from Nextcloud? In the snap/plugins/ directory?

Yes. Here’s the directory tree of my project:

.
├── snap
│ ├── gui
│ │ └── icon.svg
│ ├── plugins
│ │ └── x-php.py
│ └── snapcraft.yaml
├── src
│ ├── common
│ │ └── utilities
│ │ └── common-utilities
│ ├── delay-on-failure
│ │ └── bin
│ │ └── delay-on-failure
│ ├── hooks
│ │ ├── bin
│ │ │ ├── configure
│ │ │ └── pre-refresh
│ │ └── utilities
│ │ └── configuration-utilities
│ ├── import-export
│ │ └── bin
│ │ ├── export-data
│ │ └── import-data
│ └── php
│ ├── bin
│ │ ├── run-php
│ │ └── start-php-fpm
│ ├── config
│ │ ├── php-fpm.conf
│ │ ├── php-fpm.d
│ │ │ └── www.conf
│ │ └── php.ini
│ └── utilities
│ └── php-utilities
└── app.zip

I started from scratch and the plugin issue is resolved. Then I got the libpng-12-dev issue which i resolved by changing it to libpng-dev.

It’s building… will update the results as soon as it completes

Finally, the build is successful! Thanks a bunch @kyrofa for your help.

1 Like

Awesome! Glad you got it working.

One problem though command: bin/php app is causing problem. After successfully building the snap when i install and run the app command, it gives this error:

Could not open input file: app

This is the updated yaml file