PHP exec() not working properly PHP exec() not working properly unix unix

PHP exec() not working properly


The reason why you are not able to execute ls is because of permissions.

If you are running the web server as user A , then you can only ls only those directories which have permissions for user A.

You can either change the permission of the directory or you can change the user under which the server is running by changing the httpd.conf file(i am assuming that you are using apache).

If you are changing the permissions of the directory, then make sure that you change permissions of parent directories also.

To change the web server user, follow following steps:

Open the following file:

vi /etc/httpd/conf/httpd.conf

Search for

User apacheGroup apache

Change the user and group name. After changing the user and group, restart the server using following command.

/sbin/service httpd restart

Then you will be able to execute all commands which can be run by that user.

EDIT:

The 'User' should be a non-root user in httpd.conf. Apache by default doesnot serve pages when run as root. You have to set user as a non-root user or else you will get error.If you want to force apache to run as root, then you have to set a environment variable as below:

env CFLAGS=-DBIG_SECURITY_HOLE

Then you have to rebuild apache before you can run it as root.


I have a solution:command runs from console, but not from php via exec/system/passthru.The issue is the path to command. It works with the absolute path to command

So that:

wkhtmltopdf "htm1Eufn7.htm" "pdfIZrNcb.pdf"

becomes:

/usr/local/bin/wkhtmltopdf "htm1Eufn7.htm" "pdfIZrNcb.pdf"

And now, it's works from php via execWhere command binary you can see via whereis wkhtmltopdf


I have found the issue - SELinux was blocking PHP from accessing certain functions. Putting SELinux into permissive mode has fixed the issues (although, I'd rather not have to leave SELinux in permissive mode; I'd rather find a way of allowing certain functions if I can).