I tried my best to install GnuPG extension in PHP but it does not work.
I followed a lot of instruction but I have not been successful.
This is the code, and it always produces the error:
import failed
$keyring = "/var/www/.gnupg/";
putenv("GNUPGHOME=$keyring");
$GnuPG = new gnupg();
$GnuPG->seterrormode(GNUPG_ERROR_WARNING);
$PublicData = "key text";
$PrivateData = "key text";
$PublicKey = $GnuPG->import($PublicData); -->error here
$PrivateKey = $GnuPG->import($PrivateData); --> error here
echo 'Public Key : ',$PublicKey['fingerprint'],' & Private Key :',$PrivateKey['fingerprint'];
I tried to set the GNUPGHOME where the apache home directory is located (/var/www/.gnupg) in the code, but it does not work.
I give the permissions (777) to the folder /var/www to Apache user (www-data) but it does not work.
drwxrwxrwx 2 www-data www-data 4096 Jun 27 17:38 .
drwxr-xr-x 3 root root 4096 Jun 27 16:56 ..
-rwxrwxrwx 1 www-data www-data 383 Jun 27 16:50 pubring.gpg
-rwxrwxrwx 1 www-data www-data 383 Jun 27 16:50 pubring.gpg~
-rwxrwxrwx 1 www-data www-data 600 Jun 27 16:50 random_seed
-rwxrwxrwx 1 www-data www-data 753 Jun 27 16:50 secring.gpg
-rwxrwxrwx 1 www-data www-data 1280 Jun 27 16:50 trustdb.gpg
Environement
PHP 5.3.10
Ubuntu 12.04
GPGme Version 1.2.0
GnuPG Extension Version 1.3.6
The same problem in this thread:
PHP gnupg 'import failed'
The access rights on your pubring.gpg and secring.gpg files seems correct. You may want to drop the execute (x) right as that's not needed. Could it happen that the files are corrupt? May also want to run the program under strace to see if it is indeed accessing those file.
Related
I am running Wordpress on a Debian Based (Raspbian Buster) LEMP server. For the most part, everything is working fine except some problems with uploading photos using the command line interface. I have many pictures in my servers ~/Pictures folder that I am trying to upload to wordpress using the command line interface.
I navigate to the root directory of my wordpress installation and run the following command:
wp media import ~/Pictures/*.jpg
To which I get the following errors:
Warning: Unable to import file '/home/Danran/Pictures/img_0754.jpg'. Reason: The uploaded file could not be moved to wp-content/uploads/2020/03.
for each corresponding file. I am fairly certain that this is some sort of permissions error, but because I am a noob, I don't want to risk tinkering around with permissions in my wordpress directory without some sort of guidance by a pro.
How can I get rid of this error and successfully import my photos to wordpressing using the wp-cli?
could you please verify that you have write permissions in the uploads directory?
if u are using apache, normally what I do is set the www-data group as the owner of that directory
chown -R www-data:www-data /var/www/wordpress/wp-content/uploads
but, if what you want is to know if it is a permissions problem, simply set the permissions to 777 of that directory, and try to upload the files again... if you succeed, then it is a problem permissions, and setting them to 777 grants the cli access to that folder.
chmod 777 /var/www/wordpress/wp-content/uploads
Once you upload all of your photos with the CLI, you can change the permissions back to their original with chmod -R 755 on the same uploads folder you originally modified.
However, I usually set the permissions as follows ..
Directories: 644
Files: 755
find /var/www/wordpress/ -type f -exec chmod 644 {} \;
find /var/www/wordpress/ -type d -exec chmod 755 {} \;
EDIT1
Compare it with yours:
/var/www/wordpress/
root#www:/var/www# ls -l
total 212
-rw-r--r-- 1 www-data nogroup 420 Nov 30 2017 index.php
-rw-r--r-- 1 www-data nogroup 19935 Jan 1 2019 license.txt
-rw-r--r-- 1 www-data nogroup 7368 Sep 2 2019 readme.html
-rw-r--r-- 1 www-data nogroup 6939 Sep 2 2019 wp-activate.php
drwxr-xr-x 9 www-data nogroup 4096 Dec 18 17:16 wp-admin
-rw-r--r-- 1 www-data nogroup 369 Nov 30 2017 wp-blog-header.php
-rw-r--r-- 1 www-data nogroup 2283 Jan 20 2019 wp-comments-post.php
-rw-r--r-- 1 www-data nogroup 2898 Jan 7 2019 wp-config-sample.php
-rw-r--r-- 1 www-data root 3310 Jan 7 11:54 wp-config.php
drwxr-xr-x 8 www-data nogroup 4096 Jan 7 15:17 wp-content
-rw-r--r-- 1 www-data nogroup 3955 Oct 10 18:52 wp-cron.php
drwxr-xr-x 20 www-data nogroup 12288 Dec 18 17:16 wp-includes
-rw-r--r-- 1 www-data nogroup 2504 Sep 2 2019 wp-links-opml.php
-rw-r--r-- 1 www-data nogroup 3326 Sep 2 2019 wp-load.php
-rw-r--r-- 1 www-data nogroup 47597 Dec 9 08:30 wp-login.php
-rw-r--r-- 1 www-data nogroup 8483 Sep 2 2019 wp-mail.php
-rw-r--r-- 1 www-data nogroup 19120 Oct 15 11:37 wp-settings.php
-rw-r--r-- 1 www-data nogroup 31112 Sep 2 2019 wp-signup.php
-rw-r--r-- 1 www-data nogroup 4764 Nov 30 2017 wp-trackback.php
-rw-r--r-- 1 www-data nogroup 3150 Jul 1 2019 xmlrpc.php
/var/www/wordpress/wp-content
root#www:/var/www/wp-content# ls -l
total 28
drwxr-xr-x 3 www-data www-data 4096 Jan 7 14:52 cache
-rw-r--r-- 1 www-data nogroup 28 Jan 8 2012 index.php
drwxr-xr-x 2 www-data www-data 4096 Jan 7 11:55 languages
drwxr-xr-x 11 www-data nogroup 4096 Jan 8 16:24 plugins
drwxr-xr-x 4 www-data nogroup 4096 Jan 7 13:51 themes
drwxr-xr-x 2 www-data www-data 4096 Jan 7 14:52 upgrade
drwxr-xr-x 6 www-data www-data 4096 Jan 7 14:50 uploads
I'm running a Laravel 5.7 app in the Ngnix server. All my files and directory permissions are set to www-data:www-data user:group. The problem is when I tried to run following PHP artisan command from the code using PHP exec() function, it is giving permission denied issue to create file under storage/log/ folder, which is already 777 and the queue was never executed.
$file_name = "queue-log";
exec('php artisan queue:work --tries=3 --stop-when-empty > storage/logs/'.$file_name.'.log &',$array);
When I simply try to do it by CLI, it works normally. My php.ini is not in safe mode and exec() is not under disabled functions list and exec("whoami") returns www-data when debugging from the browser.
Any clues what is going on?
The output of ls -la storage is
drwxrwxrwx 6 www-data www-data 4096 Jun 13 11:30 .
drwxrwxr-x 14 www-data www-data 4096 Jul 3 10:39 ..
drwxrwxrwx 5 www-data www-data 4096 Mar 22 14:58 app
drwxrwxrwx 2 www-data www-data 4096 Jul 19 07:04 debugbar
drwxrwxrwx 6 www-data www-data 4096 Jun 12 23:13 framework
drwxrwxrwx 2 www-data www-data 4096 Jul 23 04:40 logs
and the output of ls -la storage/logs
drwxrwxrwx 2 www-data www-data 4096 Jul 23 04:40 .
drwxrwxrwx 6 www-data www-data 4096 Jun 13 11:30 ..
-rwxrwxrwx 1 www-data www-data 96950 Jun 13 05:07 laravel-2019-06-13.log
I am attempting to run pdftk as user www-data with the following command (as root):
sudo -u www-data /snap/bin/pdftk
But I am getting this error:
cannot create user data directory: /var/www/snap/pdftk/9: Read-only
file system
(Ubuntu 18.04, PDFTK installed with SNAP).
The /var/www/snap/pdftk and /var/www/snap/pdftk/9 directories have rw permissions for the www-data user:
drwxr-xr-x 3 www-data www-data 4096 Jan 23 15:44 ./
drwxrwxrwx 4 root root 4096 Jan 23 15:44 ../
drwxrwxr-x 4 www-data www-data 4096 Jan 23 15:44 pdftk/
drwxrwxr-x 4 www-data www-data 4096 Jan 23 15:44 ./
drwxr-xr-x 3 www-data www-data 4096 Jan 23 15:44 ../
drwxrwxr-x 2 www-data www-data 4096 Jan 23 15:44 9/
drwxr-xr-x 2 www-data www-data 4096 Jan 23 15:44 common/
lrwxrwxrwx 1 www-data www-data 1 Jan 23 15:44 current -> 9/
I need to be able to run PDFTK as www-data user because I want to call PDFTK from a PHP script served by apache2, as in:
<?php
`/snap/bin/pdftk file1.pdf file2.pdf cat output file3.pdf`;
NOTE: the pdftk wrapper for PHP, mikehaertl/php-pdftk, doesn't seem to want to save files either. I tried the ->saveAs() function but no file is generated, even when attempting to write to /tmp, which should have full write permissions. No errors in apache2 error log, so I'm betting it's the same issue.
I encountered exactly the same problem! In particular, I didn't face this problem when using pdftk in Ubuntu 18.10 with pdftk already included back, but faced this problem on a server with Ubuntu 18.04.
My workaround is NOT to install pdftk via snap. I installed pdftk with debian packages, following the instruction at https://www.webdesign101.net/install-pdftk-on-ubuntu-18-04-bionic/.
Everything then just works fine.
I'm using bitbucket to host my git repository, the repo holds a test website at the moment, I have created a bitbucket webhook, so when I push to the bitbucket repo, the changes show up as live on the digitalOcean VPS, in other words.. when bitbucket receives a push, it calls the webhook php file, and that php file has a shell script that pulls from github..
the hook file
Hook path : /var/www/html/hook.php
the site folder
Site path : /var/www/html/webhooks/
the hook.php file looks like so
<?php
echo "________PHP_AUTO_PULL________";
$output = shell_exec('git -C ./webhooks/ pull https://userName:password#bitbucket.org/userName/repo.git master');
echo "<pre>$output</pre>";
?>
when I do this in terminal
php hook.php
it does the job normally, and it pulls..
but the problem is, webhooks only shows this reply
________PHP_AUTO_PULL________
indicating that it does no pull, yes I have checked, no pull occured, how to make the hook execute the file normally?
permissions and owners are provided in these listings
listing for /var/www/html/
drwxrwxr-x 3 www-data www-data 4096 Mar 28 09:21 ./
drwxrwxr-x 3 www-data www-data 4096 Mar 3 16:49 ../
-rwxrwxrwx 1 www-data root 200 Mar 28 09:05 hook.php*
-rw-rw-r-- 1 www-data www-data 20 Mar 3 16:49 info.php
drwxr-xr-x 3 root root 4096 Mar 28 09:03 webhooks/
listing for /var/www/html/webhooks/
drwxr-xr-x 3 root root 4096 Mar 28 09:03 ./
drwxrwxr-x 3 www-data www-data 4096 Mar 28 09:21 ../
-rw-r--r-- 1 root root 295 Mar 27 15:13 content.html
drwxr-xr-x 8 root root 4096 Mar 28 09:03 .git/
-rw-r--r-- 1 root root 444 Mar 27 15:13 index.html
-rw-r--r-- 1 root root 963 Mar 27 15:13 menu_1.html
-rw-r--r-- 1 root root 13 Mar 28 09:03 number.txt
my webserver is nginx
any idea why it works from terminal, but bitbucket can't have it to work?
I have managed to solve it, using :
echo shell_exec("/usr/bin/git pull https://userName:password#bitbucket.org/userName/repo.git master 2>&1");
the 2>&1 part was helping me to see errors about permissions of folders, I used
chown -R www-data .git/
and it's working fine.
I am running a Symfony3 application inside a Docker container. I have created a CommonBundle with all the resources (js, css, images). This resources are symlinked to another path as shown below:
$ docker exec -u www-data -it dockeramp_php_1 ls -la oneview_symfony/src/CommonBundle/Resources/public
total 8
drwxrwsr-x 2 www-data www-data 4096 Feb 23 21:09 .
drwxr-sr-x 5 www-data www-data 4096 Feb 23 20:54 ..
lrwxrwxrwx 1 root www-data 32 Feb 23 21:09 css -> /var/www/html/public_html/styles
lrwxrwxrwx 1 root www-data 32 Feb 23 21:09 images -> /var/www/html/public_html/images
lrwxrwxrwx 1 root www-data 28 Feb 23 21:08 js -> /var/www/html/public_html/js
The directory oneview_symfony/web does exists and it's writable by www-data as shown below:
$ docker exec -u www-data -it dockeramp_php_1 ls -la oneview_symfony/web
total 64
drwxrwsr-x 3 www-data www-data 4096 Feb 23 20:50 .
drwxrwsr-x 9 www-data www-data 4096 Feb 23 21:16 ..
-rwxrwxr-x 1 www-data www-data 3319 Feb 23 16:45 .htaccess
-rwxrwxr-x 1 www-data www-data 631 Feb 23 16:45 app.php
-rwxrwxr-x 1 www-data www-data 843 Feb 23 16:45 app_dev.php
-rwxrwxr-x 1 www-data www-data 2092 Feb 23 16:45 apple-touch-icon.png
drwxr-sr-x 2 www-data www-data 4096 Feb 23 20:50 bundles
-rw-rw-rw- 1 www-data www-data 21486 Feb 23 20:50 config.php
-rwxrwxr-x 1 www-data www-data 6518 Feb 23 16:45 favicon.ico
-rwxrwxr-x 1 www-data www-data 116 Feb 23 16:45 robots.tx
I am trying to install the assets relative or symlink switching values on the composer.json file:
{
...
"extra": {
...
"symfony-web-dir": "web",
"symfony-assets-install": "relative",
}
}
I am trying to publish the assets running the following command and ending up with the error below:
$ docker exec -u www-data -it dockeramp_php_1 php oneview_symfony/bin/console assets:install
[InvalidArgumentException]
The target directory "web" does not exist.
What I am missing here?
There is a similar issue here but without answer so far.
Can you try this command instead:
$ docker exec -u www-data -it dockeramp_php_1 php oneview_symfony/bin/console assets:install web
If that doesn't work, try the full path to the web directory.
Let us know if that works. Not sure if that will fix the problem, but please try it.
Configure variable for assets command.
Add public-dir to composer.json
"extra": {
"symfony-web-dir": "web",
"public-dir": "web",
...
},
Because assets command relies on it (view code on github)
Look:
$defaultPublicDir = 'public';
// ...
if (isset($composerConfig['extra']['public-dir'])) {
return $composerConfig['extra']['public-dir'];
}
return $defaultPublicDir;
For anyone trying to install assets in Symfony 4 with the old Symfony3 directory structure getting:
Error thrown while running command "assets:install". Message: "The target directory "public" does not exist."
The same fix Alvin Bunk provided works:
$ bin/console assets:install web
Just manually provide the old target path
You need to run the exact line
app/console assets:install or bin/console assets:install
(depends on your version) since it takes the path of the command as reference.