Symfony2, KnpSnappyBundle, Wkhtmltopdf and OVH shared hosting - php

I'm trying to generate pdfs with Symfony2, KnpSnappyBundle, Wkhtmltopdf on a mutualized OVH server.
I've putted wkhtmltopdf binary in the bin folder of symfony.
In\app\config\parameters.yml :
wkhtmlto.binary: %kernel.root_dir%/../bin/wkhtmltopdf
In \app\config\config.yml :s
knp_snappy:
pdf:
enabled: true
binary: %wkhtmlto.binary%
options: []
With chmod 604 on wkhtmltopdf, I've this message :
The exit status code '126' says something went wrong:
stderr: "sh: /home/procontakq/Configurateur/app/../bin/wkhtmltopdf:
Permission denied
"
stdout: ""
command: /home/procontakq/Configurateur/app/../bin/wkhtmltopdf --lowquality
'/tmp/knp_snappy59cbc7c736b541.46778125.html'
'/tmp/knp_snappy59cbc7c736c0f4.36952821.pdf'.
If I put the wkhtmltopdf binary with 715 access right , I have the following error message :
With chmod 715 on wkhtmltopdf, I've this message :
stderr: "sh: /home/procontakq/Configurateur/app/../bin/wkhtmltopdf: No such
file or directory
"
stdout: ""
command: /home/procontakq/Configurateur/app/../bin/wkhtmltopdf --lowquality
'/tmp/knp_snappy59cbc893b03971.22099815.html'
'/tmp/knp_snappy59cbc893b03c91.27932094.pdf'.

Related

Deploying using ansible resets symfony cache file permissions on production environment

I'm using Symfony 5.0.7
My live deploy ansible after-symlink-shared.yaml file:
---
- name: Set up infrastructure-related parameters
template:
src: '{{ playbook_dir }}/templates/.env_live.dist'
dest: '{{ ansistrano_release_path.stdout }}/.env'
- name: Install Composer dependencies
composer:
command: install
arguments: --classmap-authoritative
no_dev: no
optimize_autoloader: yes
working_dir: '{{ ansistrano_release_path.stdout }}'
- name: Clear the cache
command: 'php {{ release_console_path }} cache:clear --no-warmup --env=prod'
- name: Warm up the cache
command: 'php {{ release_console_path }} cache:warmup --env=prod'
- name: Create DB if not exists
command: 'php {{ release_console_path }} doctrine:database:create --if-not-exists --env=prod'
register: create_db_output
changed_when: create_db_output.stdout is not search('already exists. Skipped')
- name: Run migrations
command: 'php {{ release_console_path }} doctrine:migrations:migrate --no-interaction --env=prod'
register: run_migrations_output
changed_when: run_migrations_output.stdout is not search('No migrations to execute')
- name: Install bundle assets
command: 'php {{ release_console_path }} assets:install --symlink --env=prod {{ ansistrano_release_path.stdout }}/public'
- name: Copy build directory
command: 'cp -a {{ ansistrano_release_path.stdout }}/public/build /var/www/project/public'
tags:
- deploy
The deployment works perfectly, however every time I deploy to the server, my production environment hits a 500 error.
I take a look at my prod.log file to understand what is causing the error and I get the following:
[2020-05-09 21:40:59] request.CRITICAL: Uncaught PHP Exception RuntimeException: "Unable to create the storage directory (/var/www/project/symfony/releases/20200509213543Z/var/cache/prod/profiler)." at /var/www/project/symfony/releases/20200509213543Z/vendor/symfony/http-kernel/Profiler/FileProfilerStorage.php line 43 {"exception":"[object] (RuntimeException(code: 0): Unable to create the storage directory (/var/www/project/symfony/releases/20200509213543Z/var/cache/prod/profiler). at /var/www/project/symfony/releases/20200509213543Z/vendor/symfony/http-kernel/Profiler/FileProfilerStorage.php:43)"} []
[2020-05-09 21:40:59] php.CRITICAL: Uncaught Exception: Unable to create the storage directory (/var/www/project/symfony/releases/20200509213543Z/var/cache/prod/profiler). {"exception":"[object] (RuntimeException(code: 0): Unable to create the storage directory (/var/www/project/symfony/releases/20200509213543Z/var/cache/prod/profiler). at /var/www/project/symfony/releases/20200509213543Z/vendor/symfony/http-kernel/Profiler/FileProfilerStorage.php:43)"} []
[2020-05-09 21:40:59] request.CRITICAL: Uncaught PHP Exception RuntimeException: "Unable to create the storage directory (/var/www/project/symfony/releases/20200509213543Z/var/cache/prod/profiler)." at /var/www/project/symfony/releases/20200509213543Z/vendor/symfony/http-kernel/Profiler/FileProfilerStorage.php line 43 {"exception":"[object] (RuntimeException(code: 0): Unable to create the storage directory (/var/www/project/symfony/releases/20200509213543Z/var/cache/prod/profiler). at /var/www/project/symfony/releases/20200509213543Z/vendor/symfony/http-kernel/Profiler/FileProfilerStorage.php:43)"} []
[2020-05-09 21:40:59] php.CRITICAL: Uncaught Exception: Unable to create the storage directory (/var/www/project/symfony/releases/20200509213543Z/var/cache/prod/profiler). {"exception":"[object] (RuntimeException(code: 0): Unable to create the storage directory (/var/www/project/symfony/releases/20200509213543Z/var/cache/prod/profiler). at /var/www/project/symfony/releases/20200509213543Z/vendor/symfony/http-kernel/Profiler/FileProfilerStorage.php:43)"}
This looks like a permissions issue because every time I deploy, this error comes up. Is is possible I can do something from the NGINX perspective to ensure this functions properly? Or is this an ansible solution? I'm trying to avoid manually fixing these errors with each deployment.
The user running the deployment seems to be different than the one that runs php, that's why the user doesn't have permissions to the cache directory after cache:warmup is run.
You have several options:
Change the user the app runs under:
Since you say you are using nginx I guess you are running php-fpm. You can change the user and group parameters in your php-fpm.conf to the one running the deployment. If you are running multiple applications, create a new pool. (Here's slightly outdated guide to fpm and pools to get you going, and the FPM reference).
Adjust primary groups and umask or acls so both users have access.
Run the cache tasks as the php user using become.
Fix permissions as part of the deploy process by running an ansible task. You can use the file module for this. You can either use open permissions or use become.
Keep in mind that using become (the last two options) requires changing the sudoers file so the deploy user can act as the php user.
If you have an uploads directory under public that needs write access by the php process, you need to fix those permissions too.
I figured out the issue.
It was purely a permissions issue that I had to firstly go to the highest level folder of where the var prod folder was and updated the permissions using chown then updated the permissions for all folder below recursively using chmod to ensure everything else moving forward would be written just as the parent was.
Issue happens probably because ansible runs on root user, but PHP server didn't
Try to add the last step for change ownership of directory in the playbook
- name: Fix user rights
command: 'chown -R www-data: /var/www/project/public'
tags:
- deploy
in my example ownership grants to user www-data (default), but in your case it can be different.
For check right user, use command
cd /var/www/project && ls -la

Cakephp 3.4.14 Exception: Shell class for "Serve" could not be found

here is my shell snip
Maan#DESKTOP-TNA7PJU MINGW64 /d/xampp1/htdocs/app
$ bin/cake serve
Exception: Shell class for "Serve" could not be found. in [D:\xampp1\htdocs\app\vendor\cakephp\cakephp\src\Console\ShellDispatcher.php, line 327]
Maan#DESKTOP-TNA7PJU MINGW64 /d/xampp1/htdocs/app
$ cd ../pocketpa-git-clone000000/
Maan#DESKTOP-TNA7PJU MINGW64 /d/xampp1/htdocs/pocketpa-git-clone000000 (master)
$ bin/cake serve
Exception: Shell class for "Serve" could not be found. in [D:\xampp1\htdocs\pocketpa-git-clone000000\vendor\cakephp\cakephp\src\Console\ShellDispatcher.php, line 327]
Warning Error: file_put_contents(D:\xampp1\htdocs\pocketpa-git-clone000000\logs\cli-error.log): failed to open stream: No such file or directory in [D:\xampp1\htdocs\pocketpa-git-clone000000\vendor\cakephp\cakephp\src\Log\Engine\FileLog.php, line 133]
PHP Warning: file_put_contents(D:\xampp1\htdocs\pocketpa-git-clone000000\logs\cli-error.log): failed to open stream: No such file or directory in D:\xampp1\htdocs\pocketpa-git-clone000000\vendor\cakephp\cakephp\src\Log\Engine\FileLog.php on line 133
last night i shut down my pc and in morning when i restart i am facing this issue
cakephp version 3.4.14
php 5.6.36
and having this problem when wants to start project
Sorry my bad i was messed up with diffferent projects i was working on Laravel Projects and using frequently
php artisan serve
This command will start a development server at http://localhost:8000:
when i come back to CakePhp Project i was messed up and trying
bin\cake serve
command to start local server for cakephp environment http://localhost:8765/
thats make me so much trouble
But the orignal command to run CakePhp Sever on LocalHost is
bin\cake server
here you can get more details https://book.cakephp.org/3.0/en/installation.html#development-server

Selinux stoping PhantomJs with Permission Denied Laravel Application on Fedora

I'm using fireguard to create pdf at my laravel application , but on fedora if I execute the command setenforce 0 ,it runs just fine as expected. But if I turn selinux on with setenforce 1 , it gives me the message :
PhantomJS: sh: /var/www/html/.../vendor/bin/phantomjs: Permission
denied.
The audit.log gives me the message :
type=AVC msg=audit(1493867419.082:61578): avc: denied { execute }
for pid=15202 comm="sh" name="phantomjs" dev="xvda1" ino=279975
scontext=system_u:system_r:httpd_t:s0
tcontext=unconfined_u:object_r:httpd_sys_rw_content_t:s0 tclass=file
permissive=0
what should I do to allow phatomjs by selinux without disabling selinux entirely with setenforce 0 ?

Can not find PDOConnection.php

I installed a Laravel project, as I am trying to learn the framework. I am now trying to work on a different machine and I can't set it up.
I get these errors:
blog git:(development) php artisan migrate:install
[ErrorException]
include(/home/ioto/www/my-bitbucket/blog/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php): failed to open stream: No such file or directory
although when I try to check if the file actually exists I can see it but I can't access it:
➜ blog git:(development) cd vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver
➜ Driver git:(development) ls -lisa
total 112
[...]
26740122787838334 4 -rw-rw-rw- 0 777 ioto 3695 sep 10 15:00 PDOConnection.php
[...]
➜ Driver git:(development) cat PDOConnection.php
cat: PDOConnection.php: No such file or directory
I am using "bash on ubuntu on windows"
I get the same errors if I try different things like other artisan commands, if I try to serve the application and so on. I tried a new composer update after deleting the vendor folder. Set chmod to 777, but I'm out of ideas...
Any suggestions on what can I try to debug this ?

Amazon ElasticBeanstalk configuration not working

I have able to successfully deploy a php application using git in elastic beanstalk, but the configuration files doesnot work. I created a .ebextensions folder on my root application folder and created a config file with the following command:
container_commands:
00_make_assets:
command: "sudo mkdir /var/app/current/assets"
I get the following error message on the dashboard
Command failed on instance. Return code: 1 Output: [CMD-AppDeploy/AppDeployStage0/EbExtensionPostBuild] command failed with error code 1: Error occurred during build: Command 00_make_assets failed.
All I want to do is create a folder and give 777 permission to it.
The output in the log file (/var/log/eb-commandprocessor.log) shows:
[2014-10-17T11:01:43.487Z] ERROR [2341] : Command CMD-AppDeploy failed!
[2014-10-17T11:01:43.488Z] INFO [2341] : Command processor returning results:
{"status":"FAILURE","api_version":"1.0","truncated":"false","results":[{"status":"FAILURE","msg":"[CMD-AppDeploy/AppDeployStage0/EbExtensionPostBuild] command failed with error code 1: Error occurred during build: Command 00_make_assets failed","returncode":1,"events":[]}]}
Has anyone been in this situation? How can this issue be solved? Any help will be much appreciated.

Categories