shell_exec not running xvfb-run in php5-fpm but this is working well under apache2 ( mod_php ) - shell-exec

shell_exec is not working for the command
xvfb-run --auto-servernum --server-num=1 /var/sjs/slimerjs /var/www/html/sjs/www.js
But this same command working well in Apache2 ( mod_php )
So why php5-fpm can't run this command?

Check your php.ini that php-fpm used. Find disable_functions directive and delete shell_exec from value.
May be user (who runnig php-fpm), haven't permission to read/execute some files. Check permission with ls -l /var/sjs/slimerjs /var/www/html/sjs/www.js command. I think, that user must have permission for execute /var/sjs/slimerjs, and reading /var/www/html/sjs/www.js. You can add permission by command chmod +x /var/sjs/slimerjs and chmod +r /var/www/html/sjs/www.js, but that's not good for security, cause any user can exec/read files. Better add user to some group, change owner group for this files, and set permission 754 for first file, and 744 for second.

Related

Commands without sudo in bash do not work

I am running a bash script and these commands in the script will not work without sudo in front of them. The script.sh is located in a folder such as /jobs/script.sh
Example of commands I am trying to run in the script.sh -
mv /var/app/myapp /var/app/myapp.old
rm file.tar.gz
tar -xzf /home/ubuntu/file.tar.gz -C /var/app/
All the above work if I add sudo in front of them.
I am trying to figure out what permissions are required for them to work without adding sudo in the script.
I have tried giving the script.sh rwx permissions and changing owner to root.
I'm learning permissions in linux, so I'm new to this. Basically what permission should the script.sh have so that I dont have to use sudo in the bash file? Any insight would greatly help.
When you run sudo <some command>, then <some command> is run by the root user (Super user do). The reason you might need to run any command using sudo is because the permissions on the files that command reads/writes/executes are such that only the "Super user" (root) has that permission.
When executing the command mv fileA fileB, the executing user would need:
Write permission to fileB if fileB already existed
Write permission to the directory containing fileB
From what you said it’s most likely you want read and write permissions you can achieve this with chmod
Chmod +[permission] filename
(+ is used to add permission you can also use - instead to remove it)
Where permissions can be:
r —> read
w—> write
x —>excecute
... and more
FOR EXAMPLE: it seems you write permissions for the first file so :
chmod +w /var/app/myapp
Will fix problem

Error creating Laravel project from command line

I installed phpmyadmin, node.js and composer.
In the terminal, I wrote: composer global require "laravel / installer" and after, to create my project I wrote: laravel new laravel (the name of my project is laravel) and when I do enter I have these Errors that appear.
try to run as admin, change the permission to that folder or change the owner of that folder. Cause the error is saying that you don't have permissions to write in that folder.
To run as admin:
UNIX OS
prepend sudo to your command (but you shouldn't use composer as admin)
WINDOWS
Launch command line with this cli
runas /noprofile /user:Administrator cmd or right click on cmd application and run as administrator
To change permission:
run chmod XXX FOLDERNAME where XXX are the permission codes, 777 allow everyone to read/write. FOLDERNAME its the name of the folder or of the file.
To change owner:
run chown -R user:group FOLDERNAME
try with chown -R marc:marc FOLDERNAME the -R flag applies the ownership to the subfolders/files

How disable need to sudo? Setting root to admi, sudivo, and disabling SIP didn't work

I am having to type "sudo" before most terminal commands, and am also getting EACCES errors sometimes even when using sudo when chained to a secondary file/folder.
I've done the standard setting of root user to admin, added my username with all permissions in visudo, and successfully disabled SIP. It may have to do with permissions I may have changed when I first got my Mac years ago.
Does anybody have any ideas as to what could be wrong?
Sometimes you use sudo command1, you also encountered permission denied. It's because the command1 will invoke another process which don't have root prividge. In this situation you can put command in a script, and use sudo bash script, or su to change to root user. And sometimes sudo filename also permission denied, it's that you not have the x priviledge, you can sudo chmod 744 filename, then execute the command.
methods to avoid type sudo passward every minutes.
method 1 recomended. sudo -i
method2 use sudo visudo or sudo vim /etc/sudoers and put this in it. this will make username user neednot to pass passward when use sudo.
username ALL=(ALL) NOPASSWD: ALL
you can refer here for config for one command
hope helps.
Log in and open your terminal app. Run these two commands:
sudo echo >> /etc/sudoers
sudo echo "$(id -u -n) ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
Now you can run sudo without a password. Do normal stuff under your regular account and when you want to run as root for a while do:
sudo bash
macOS includes a "root user" that can be enabled using Directory Utility. Have a look at the following article from Apple: Enabling and using the "root" user in OS X. The article, while not explicitly saying it, implies that using the root user is the same thing as sudo.
The Apple article includes some warnings about use of the root user, but if you think about it, it's no more risky than deliberately disabling the password required by sudo. Either way you're creating an unrestricted path to root-level functions, so do be careful about it!
None of these solutions worked as things are. Ended up wiping my computer's hard drive and permissions settings went back to normal.

Get permission to work with files on my Amazon EC2 Ubuntu server using FTP-WinSCP

I have an Ubuntu server on Amazon, I installed everything for working with it (php, mysql, phpmyadmin, apache..), The problem is that I cant move around or edit files using the FTP.
I get the error message:
Permission denied.
Error code: 3
Error message from server: Permission denied
from my WINSCP.
The only way I can trancefer/edit file is using 'putty' with the sudo/nano command.
I found a lot of information about this on google, but there are no updated soulution I can find. Linux isn't my usual work-space.
How do I get the permissions working for the WINSCP ?
A lot of answers say to change permissions on /var/www/ ... however AWS shortcuts out of the WWW folder and into the /var/app/current/ directory. If all else fails try:
sudo chown -R -v ec2-user /var/app/current/
On Ubuntu image in AWS, default user is ubuntu. Instead of using system folders like /var/... better to use /home/your_folder. Then change the ownership using {chown} command. For eg.
$ sudo chown -R -v ubuntu /home/your_folder/
This will change the ownership of 'your_folder' and contents inside it from 'root' user to 'ubuntu'. Then Winscp should be able to upload/delete/create files using SFTP/FTP etc..
I had the same issues. The solution is: You can solve this by changing WordPress ownership type:
sudo chown -R www-data:ubuntu /var/www/wordpress
Then, Change the right permission for the particular files and directories, type command
sudo find /var/www/wordpress/ -type d -exec chmod 755 {} \;
sudo find /var/www/wordpress/ -type f -exec chmod 644 {} \;
Apart from this, set the following important files to chmod 600 so that only the owner can fully read and write access to these files:
sudo chmod 600 /var/www/wordpress/wp-config.php
sudo chmod 600 /var/www/wordpress/.htaccess
Then everything will work. You will be able to access your wordpress files
for me using free tier from cloud providers will not give you root access, to fix this you have to change folder permission from SSH or try this solution
OS: windows 10 Pro
Open WinSCP instead of SFTP you select SCP go to advance settings click on SCP/Shell and change the shell option to sudo su -
Now you will be able to get permission.
Change file permision by command chmod 777 /var/app/current/ and transfer files to the directory

modify file content

I'm installing a lighttpd server on a remote machine using a bash script. After installation, I need to configure the port for the server. The system says I don't have permission to modify the file /etc/lighttpd/lighttpd.conf even though I do
sudo echo "server.bind=2000" >> /etc/lighttpd/lighttpd.conf
How shall I modify this?
What you're doing is running echo as root, then trying to append its output to the config file as the normal user.
What you want is sudo sh -c 'echo "server.bind=2000" >> /etc/lighttpd/lighttpd.conf'
Try to change the file permission using chmod
$ sudo chmod a+x /etc/lighttpd/lighttpd.conf
If you don't have the right to change the file /etc/lighttpd/lighttpd.conf check the man page of lighthttpd. If you can start it with a different config file, then create a config file somewhere and start lighthttpd with it.
The problem is that the bit on the right of >> is not run under sudo. Either use sudo -i to bring up a root shell a superuser and run the command, or just use an editor as mentioned before.

Resources