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.
Related
I think I am having problems with the max children limit for php-fpm. I am trying to find something in the logs. Where can I find php-fpm.log on my server? Running phpinfo() shows this:
I cannot find anything related to php-fpm in /var/log/.
I am also trying to find the php-fpm.conf that is mentioned at https://www.php.net/manual/en/install.fpm.configuration.php. Thank you.
UPDATE 1: I found at https://github.com/rlerdorf/php7dev/issues/48 that it asks to edit /usr/local/etc/php-fpm.d/www.conf. In my case, I cannot find that file:
root#jai [/usr/local/etc]# pwd
/usr/local/etc
root#jai [/usr/local/etc]# ls -al
total 8
drwxr-xr-x. 2 root root 4096 Sep 23 2011 ./
drwxr-xr-x. 15 root root 4096 Apr 7 15:02 ../
Do I need to create it at /usr/local/etc/php-fpm.d/www.conf?
UPDATE 2: I see I have a folder called ApachePHPFPM but the file inside (default_accounts_to_fpm) is empty:
root#jai [/var/cpanel/ApachePHPFPM]# pwd
/var/cpanel/ApachePHPFPM
root#jai [/var/cpanel/ApachePHPFPM]# ls -al
total 16
drwxr-xr-x 2 root root 4096 Mar 26 04:44 ./
drwx--x--x 108 root root 12288 Apr 17 13:44 ../
-rw-r--r-- 1 root root 0 Mar 26 04:44 default_accounts_to_fpm
root#jai [/var/cpanel/ApachePHPFPM]#
UPDATE 3: My server had this file:
/usr/local/cpanel/etc/php-fpm.conf
The file contains this:
; Error log file
; Default Value: /var/log/php-fpm.log
error_log = /usr/local/cpanel/logs/php-fpm/error.log
That means that my error logs for php-fpm are located in this file: /usr/local/cpanel/logs/php-fpm/error.log.
I navigated to /usr/local/cpanel/logs/php-fpm/ but I could not find error.log:
root#jai [/usr/local/cpanel/etc]# cd /usr/local/cpanel/logs/php-fpm/
root#jai [/usr/local/cpanel/logs/php-fpm]# ls -al
total 8
drwx------ 2 root root 4096 Mar 30 2018 ./
drwx--x--x 6 root root 4096 Apr 16 15:24 ../
root#jai [/usr/local/cpanel/logs/php-fpm]#
In /opt/cpanel/ea-php73/root/etc/php-fpm.conf I found this line:
error_log = /opt/cpanel/ea-php73/root/usr/var/log/php-fpm/error.log
I see the error log files there:
root#jai [/opt/cpanel/ea-php73/root/usr/var/log/php-fpm]# pwd
/opt/cpanel/ea-php73/root/usr/var/log/php-fpm
root#jai [/opt/cpanel/ea-php73/root/usr/var/log/php-fpm]# ls -al
total 151456
drwxrwx--- 2 nobody root 4096 Apr 14 17:36 ./
drwxr-xr-x 3 root root 4096 Mar 26 04:42 ../
-rw------- 1 root root 31536068 Apr 17 17:05 error.log
-rw------- 1 root root 32102325 Mar 29 03:26 error.log-20200329
-rw------- 1 root root 51453659 Apr 5 03:36 error.log-20200405
-rw------- 1 root root 39966549 Apr 12 02:55 error.log-20200412
root#jai [/opt/cpanel/ea-php73/root/usr/var/log/php-fpm]#
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 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 trying to install a PHP-based software package in a Red Hat 7 Amazon EC2 instance (ami-8cff51fb) that has had Apache 2.4.6 and PHP 5.4.16 installed on it using yum. The installation fails because it says a particular directory needs to be writable by the webserver with 0755 or 0775 permissions.
The directory in question has 0775 permissions with root:apache ownership. I have verified that the httpd process is being run by the apache user and that the apache user is a member of the apache group.
If I edit /etc/passwd to temporarily give the apache user a login shell and then su to that account, I am able to manually create files as the apache user within the directory using the touch command.
I took a look at the source code of the installer script and identified that it's failing because PHP's is_writable() function is returning false for the directory in question. I created a separate test PHP script to isolate and verify the behaviour I'm seeing:
<?php
$dir = '/var/www/html/limesurvey/tmp';
if (is_writable($dir)) {
echo $dir, ' is writable';
} else {
echo $dir, ' is NOT writable';
}
?>
This outputs the NOT writable message. If I change $dir above to be /tmp then it correctly outputs that /tmp is writable.
If I change the directory permissions to 0777 and/or change the ownership to apache:apache then PHP still reports that the directory isn't writable. I even tried creating a /test directory set up with the same permissions and ownership and my test script still reports it as not writable.
I'm really at a loss as to explain this behaviour, so any ideas would be welcome!
Thanks in advance.
The directory listing for /var/www/html/limesurvey is given below. The tmp and upload directories have 0775 permissions as per Lime Survey's installation instructions. test.php is my test script mentioned above.
[ec2-user#ip-xx-x-x-xxx limesurvey]$ pwd
/var/www/html/limesurvey
[ec2-user#ip-xx-x-x-xxx limesurvey]$ ls -al
total 80
drwxr-xr-x. 20 root apache 4096 Mar 30 11:25 .
drwxr-xr-x. 3 root root 23 Mar 25 14:41 ..
drwxr-xr-x. 2 root apache 38 Mar 10 12:56 admin
drwxr-xr-x. 16 root apache 4096 Mar 10 12:56 application
drwxr-xr-x. 3 root apache 4096 Mar 10 12:56 docs
drwxr-xr-x. 2 root apache 4096 Mar 10 12:56 fonts
drwxr-xr-x. 19 root apache 4096 Mar 10 12:56 framework
-rw-r--r--. 1 root apache 429 Mar 10 12:56 .gitattributes
-rw-r--r--. 1 root apache 399 Mar 10 12:56 .gitignore
-rw-r--r--. 1 root apache 296 Mar 10 12:56 .htaccess
drwxr-xr-x. 4 root apache 4096 Mar 10 12:56 images
-rw-r--r--. 1 root apache 6652 Mar 10 12:56 index.php
drwxr-xr-x. 5 root apache 39 Mar 10 12:56 installer
drwxr-xr-x. 89 root apache 4096 Mar 10 12:56 locale
drwxrwxr-x. 2 root apache 39 Mar 25 14:41 logs
drwxr-xr-x. 4 root apache 49 Mar 10 12:56 plugins
-rw-r--r--. 1 root apache 61 Mar 10 12:56 README
drwxr-xr-x. 4 root apache 4096 Mar 10 12:56 scripts
-rw-r--r--. 1 root apache 380 Mar 10 12:56 .scrutinizer.yml
drwxr-xr-x. 5 root apache 4096 Mar 10 12:56 styles
drwxr-xr-x. 5 root apache 4096 Mar 10 12:56 styles-public
drwxr-xr-x. 12 root apache 4096 Mar 10 12:56 templates
-rw-r--r--. 1 root apache 159 Mar 30 11:11 test.php
drwxr-xr-x. 3 root apache 20 Mar 10 12:56 themes
drwxr-xr-x. 26 root apache 4096 Mar 10 12:56 third_party
drwxrwxr-x. 5 root apache 80 Mar 26 13:45 tmp
drwxrwxr-x. 6 root apache 79 Mar 10 12:57 upload
Running namei -l /var/www/html/limesurvey/tmp gives:
[ec2-user#ip-x-x-x-xxx ~]$ namei -l /var/www/html/limesurvey/tmp
f: /var/www/html/limesurvey/tmp
drwxr-xr-x root root /
drwxr-xr-x root root var
drwxr-xr-x root root www
drwxr-xr-x root root html
drwxr-xr-x root apache limesurvey
drwxrwxr-x root apache tmp
After much head-scratching, it transpired that SELinux was preventing the directory from being written to. I found a good tutorial that explains what's going on. I was able to fix it by running this command:
sudo chcon -R -t httpd_sys_rw_content_t tmp
in CentOS 6 above should be SELinux enable enforcing
setenforce Permissive
check the status
sestatus
refer to https://wiki.centos.org/HowTos/SELinux
to write to a directory you also need execute permissions to the dirs above.
namei -l /var/www/html/limesurvey/tmp
should show which step you do not have the correct permissions for.
HTTPDUSER=`ps aux | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\ -f1`
sudo setfacl -R -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX tmp
sudo setfacl -dR -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX tmp
Taken directly from the Symfony2 installation guide, this solves the problem with cache write access sharing between Apache and CLI tools. This might work for your tmp directory as well.
is_writable by default only checks on the user, not the group.
So even if you group is matching and has permissions is_writable will return false.
To relax this check you will need to set
safe_mode_gid = On
in the PHP config or change the user accordingly.
I am working on a compression script. it reads the directories and compress the files and folder and moves compressed files/folder to a Out folder.
When i create folders in side the Out from my php script i dont have write access to to those folders there afeter, but when tried with cmd it isn't .its like this
drwxr-xr-x 6 root root 4096 Jan 30 08:25 erik
drwxr-xr-x 6 root root 4096 Jan 27 11:39 gayan
drwxr-xr-x 5 root root 4096 Jan 27 12:00 iyan
**drwxr-xr-x 5 root root 4096 Jan 30 09:50 Samuli**
drwxrwxr-x 2 plusmedia plusmedia 4096 Jan 30 09:56 ssss
what would cause this? any solution is admire, Thanks
This is because the current user with which you are executing the php script do not have permission to write in that folder. You could switch to root user through terminal and then:
chmod 777 -R /path/to/your/Outfolder
Hope this helps you :)