I'm trying to run a symfony4 application in the Google Cloud App Engine following this instructions.
My app has a dependency which itself depends on php-gd. This extension seems to be unavailable since composer fails with the requested PHP extension gd is missing from your system..
How would I have to modify the tutorial to have the extension available?
Can this be solved with a php.ini file or do I need a custom environment?
Alternatively since I don't need the parts of my dependency which require php-gd, is there a way to get composer run with the --ignore-platform-reqs flag?
Make sure to get installed this php-gd or apt-get install php5-gd
-your OS apt-get install php gd or apt-get install php5-gd, be aware of your php version.
The other approach here woulbe to add "ext-gd": "*" to your application's composer.json:
composer require "ext-gd:*" --ignore-platform-reqs
It doesn't matter if gd is enabled in your local PHP install, the flexible environment is built using your composer.json and app.yaml files, so you need to add it there.
Well this is based on Symfony
So on the root of your application create a file php.ini
In the file enter this line
extension=gd.so
So that your php.ini file will look like this.
Google Cloud App Engine only seems to load extensions required in the top level composer.json's require.
It does not seem to resolve dependencies recursevly.
Therefore a workaroud is to add all required extensions manually to the projects composer.json.
Related
I'm using PHP_CodeSniffer in my GitLab CI/CD pipelines to ensure my code is properly formatted. The job looks like follows:
stages:
- test
- build
- deploy
coding_standard:
stage: test
script:
- curl -OL https://squizlabs.github.io/PHP_CodeSniffer/phpcs.phar
- php phpcs.phar --extensions=php .
That's working as expected. However, the exact version of the tool is not specified here. So if there's suddenly a new major version of PHP_Codesniffer, the CI/CD job might fail, although my PHP code hasn't changed.
Furthermore, I currently have the tool installed globally on my local machine. In that way, I cannot have a specific version of the tool for every PHP project.
Now I'd like to add the tool as Composer dev-dependency (require-dev).
In the CI/CD job I would then call composer install instead of downloading the tool via curl.
The problem: That will download all packages needlessly, instead of just PHP_Codesniffer and its dependencies. Can I prevent that?
You can't do this with composer. You can't even install "only the dev dependencies". It's all the dependencies, all the non-dev dependencies, and that's all.
And it's generally a bad idea to install this kind of dependency as a project dependency, since very easily you can enter in dependency hell for reasons beyond your actual application needs. Development tools should not bring that level of complexity and danger to your deployment strategy.
To get around this, you could use something like the Composer Bin Plugin to isolate these dependencies and yet install them through composer. Then on CI you'd run composer install on this directory only, and run the tool from this location (or symlink it to bin, which is what the plugin does when it's installed, but you wouldn't have it installed in CI if you are not installing all the dependencies anyway).
Why not download any tagged version from Github through https://github.com/squizlabs/PHP_CodeSniffer/releases, like https://github.com/squizlabs/PHP_CodeSniffer/releases/download/3.6.0/phpcs.phar?
Using a PHAR is better than installing such stuff using Composer, as you might install other incompatible dependencies that way (this is not the case with phpcs, but other tools like phpmd install other dependencies from Symfony)
I'm trying to deploy my PHP (CakePHP) application through Azure DevOps and install Composer dependencies in the build step of the pipeline, using a Windows hosted agent.
The composer install is failing because common PHP extensions (namely intl and fileinfo) are unavailable to the PHP executable running in the build. Once deployed, the Web App on Azure does have these extensions. The composer web app extension is installed on the actual app service on Azure and there is a composer.phar file in the root of the repository.
The step I'm trying to run is just php composer.phar install --no-scripts --no-interaction --optimize-autoloader.
The pipeline fails with this error, but I have no idea how to access the .ini file or provide any options.
To enable extensions, verify that they are enabled in your .ini files:
- C:\tools\php\php.ini
PHP_INI_SCAN_DIR can be set, but this 'php template' from DevOps wipes out any added configuration properties when a new deploy happens. This also seems to be a totally different PHP than what the App Service actually runs. I can make a new template for config options, but the PHP extension issue seems to still be there on the build step.
If anyone knows how to simply have composer install dependencies and have them included in the build artifact (.zip file) created, I would greatly appreciate it. Thank you!
As answered in the comment by Levi Lu-MSFT, I was able to modify the PHP configuration by adding a new build task using the Command Line task and entering:
echo extension=intl >> C:\tools\php\php.ini
echo extension=fileinfo >> C:\tools\php\php.ini
Adding quotes caused an issue, but without it seems to work.
I am told by PHPStorm that I need to composer require ext-zip, however, that command is failing...
PHPStorm says
The command I am issuing is
composer require ext-zip
results in
Your requirements could not be resolved to an installable set of packages.
and
Installation failed, reverting ./composer.json to its original content.
Solution #1 - add ext-zip to your required section of composer.json:
{
"require" : {
"ext-zip": "*"
}
}
Solution #2 - install php-zip extension:
Windows:
Uncomment this line in your php.ini
;extension=php_zip.dll
Linux:
sudo apt-get install php-zip
or
sudo apt-get install php7.0-zip (make sure you typed YOUR php version, you can check your version by doing php -v command)
Then, you need to restart your web server.
sudo service apache2 restart
If your code runs OK - you've already got the zip extension installed on your machine. PHPStorm adds this suggestion to ensure that anywhere else that the project is deployed also has the right extensions too.
Manually adding the line in your composer.json file (require block) "ext-zip": "*", (and others that it can suggest, such as ext-apc, ext-redis and ext-json, as well as any others that you might be using) will make sure that when you deploy it composer can also check that the appropriate extra items are installed.
It's only a warning though, and you could ignore it - or you can allow composer to make sure that your servers are setup as they would be needed to run your code, and do things with zip-files. If your server doesn't have ext-zip installed, composer install would complain, and stop - saving issues later when you discover that code fails without the zip extension, et al.
The given hint comes from PhpStorm, not from composer itself: your IDE has detected that your code uses a method (or in this case: the ZipArchive class) that is only available when the ZIP extension is enabled. But your composer.json did not contain that requirement so far.
So, PhpStorm asks you to add this requirement to the JSON file to make the requirements to run your code more precise. How you solve that requirement is up to you: the best way would be to install that extension, but that is out of composer's scope
I got a website which I need to maintain and after looking at the files and code, I thought there are some missing files in project/vendor folder.
After talking to the current maintainer, he told me I need to use composer in order to see those files. I have installed composer but I don't know how to "fill" the folder with the files.
From reading online I understood I need to extract and install dependencies using the composer.json file but even after searching the web for more then an hour I didn't find how to do it.
Go to the root of you project and run
composer install
after that composer will download all package that are in the composer.json file in the require and require-dev section
First, install the composer, take a look here composer, after this try to run composer install, in some cases I do update with composer update too.
Remember to run the command composer install on the same path where composer.json
Apparently I had to install php7.0-curl using the sudo apt-get install php7.0-curl.
After that I just used composer install again and it's good now
I want to install and use php-pushwoosh on my system running on Ubuntu 12.04 LTS Linux OS.
For it I went to the link php-pushwoosh website. There I come to know about I can install php-pushwoosh by using Composer:
The easiest way to install the library is to use Composer and define the following dependency inside your composer.json file.
But I've no idea about Composer and how to install any software using Composer. My ultimate goal is to install php-pushwoosh on my machine and execute the code. Be it install by Composer or not, it doesn't matter so much to me.
If you could explain some working code example of php-pushwoosh to send push-notification to iPhone that would be even great.
Composer is a tool for dependency management in PHP. It allows you to declare the dependent libraries your project needs and it will install them in your project for you.
If you are a PHP developer by profession I really recommend getting into composer, you will love this piece of software.
It's not so complicated as it looks at first glance, just read Composer's introduction and you should be able to install composer and require any packages.
Start a new project
Create a new folder my-project-name/
Following the composer project install guide
Create a new file my-project-name/composer.json
Look at the php-pushwoosh install guide and copy the require section into your composer.json file:
{
"require": {
"gomoob/php-pushwoosh": "~1.0"
}
}
Move into your project folder (terminal/command line) cd my-project-name
Run composer install
wait ...
start a new php-file and reqire require __DIR__.'/vendor/autoload.php';
start programming