Setting path variable for apache user on Amazon EC2 - linux

I can't add /usr/local/bin to the apache users PATH variable. The user doesn't have a .profile, I can't su to the user, I can't export to the PATH from php using exec and adding
SetEnv PATH /usr/local/bin
To either the http.conf or the .htaccess file doesn't make a difference. I can't find the envvars file to change that but I suspect there's some other problem.
I have restarted apache, and indeed my server.

Ended up following what Alfe suggested in his answer, except rather than in the /etc/init.d/httpd file (which could be overwritten easily on update) I added to /etc/sysconfig/httpd:
export PATH=${PATH:+$PATH:}/usr/local/bin

Have a look at the /etc/passwd to see which login shell the apache user has (on EC2 Ubuntu instances it should be /bin/sh which is a link to /bin/dash). Then have a look at the man page of that shell and find out which configuration files are read upon login. (For /bin/dash that would be .login in the user's home directory.) In those you should be able to extend your $PATH as you like.
EDIT:
Since you seem to have no login shell for that user: Have a look at the /etc/init.d/* scripts which start the system services. Apache will be one of them. They are started as root and may change the current user (e. g. to the apache user). In there you might be able to adjust the PATH as you like it.
Patching those scripts, however, is not considered typical configuration. Updates might overwrite what ever you patch there.

Related

Setting PATH environmental variables permanently Centos Web Panel Install... Works from SSH, not Webpage

My zip function isn't working when being called from a php script, but works straight from the SSH prompt.
code in the PHP file that returns nothing var_dump( exec('zip -r domains.zip "domains"') );
code in the php file which works as expected var_dump( exec('/usr/bin/zip -r domains.zip "domains"') );
I've added the path to /etc/profile, I've added it to my ~/.bashrc but can't get the web user to be able to use it.
I'm new to this and it's a VPS so I'm not sure where to go from here.
Ensure that permissions are adequate on the files being accessed - you want to ensure that the user accessing them is able to execute them.

Linux, command line program's config file on home-dir-less setup

Several programs for Linux invoked from terminal/shell use config file where options normally put to program's invocation command line string are put. For instance Vim, for instance curl and their config files ~/.vimrc, ~/.curlrc.
If to take curl and Vim they look for such file in the home directory (it works this way at least according to their man pages).
However I know Linux setups without home directories. For example a NAS.
The known NAS houses several shared volumes / directories to be accessed from client devices via several protocols and by registered users. By default however the NAS does not create home directory for each user newly registered. The administrator hesitate to enable the option "create home directory for this user" if such is needed only for the above purpose.
Is then the usage of program's config file on such setup not possible at all?
To quote from the curl manual:
When curl is invoked, it always (unless -q is used) checks for a
default config file and uses it if found. The default config file is
checked for in the following places in this order:
1) curl tries to find the "home dir": It first checks for the
CURL_HOME and then the HOME environment variables. Failing that, it
uses getpwuid() on Unix-like systems (which returns the home dir given
the current user in your system). On Windows, it then checks for the
APPDATA variable, or as a last resort the '%USERPROFILE%\Application
Data'.
2) On windows, if there is no _curlrc file in the home dir, it checks
for one in the same dir the curl executable is placed. On Unix-like
systems, it will simply try to load .curlrc from the determined home
dir.
So no home directory is needed to store the config files as long, in the case of curl, the variable CURL_HOME, which can point to any location, is set.
Other programs have similar mechanisms.
But I am asking myself: Can one can log in (via ssh?) as a user without a home directory?

Apache httpd cant write to /etc/sysconfig/network-scripts/

Im trying to use a script ,thats started by apache through the server, to change the ifcfg-eth0 file in network-scripts.
I have SELinux disabled so thats not the issue. Also I changed the whole /etc/ group and user to apache, yet it still did not work.
The script does work if I put the file in /var/www/cgi-bin.
I also get a permission denied error in the apache log file.
I can't bring myself to help you make Apache write to files in /etc/sysconfig/network-scripts/. But there is another option: create a symlink from /etc/sysconfig/network-scripts/ifcfg-eth0 to a file that Apache can write to, for example:
mv /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0.bak
ln -s /var/www/cgi-bin/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0
This way, your (ahem, dangerous) CGI script can rewrite the file in /var/www/cgi-bin, and the system can get the network settings from it.

what is the use of "wgetrc" command in wget download

What is purpose of "wgetrc" in the below commands.
-sh-3.00$ WGETRC=/hom1/spyga/spp/wgetrc_local wget --directory-prefix=/home1/spyga/spp/download ftp://127.0.0.1/outgoing/DATA.ZIP
wgetrc_local files having the credentials of ftp server.
normally i am downloading the files from ftp server using below command.
-sh-3.00$ wget --ftp-user=xyz--ftp-password=12345 ftp://localhost/outgoing/DATA.ZIP
what is the different between above commands.
Please help me out to understand the commands.
Thanks you.
The first command simply specifies an alternative configuration file to use instead of the default ~/.wgetrc. You could also specify it using --config=/hom1/spyga/spp/wgetrc_local as argument to wget.
This file can contain wgetrc commands that change the behaviour of wget. In this case it's probably done so user and passwords don't have to be supplied on the command line. Specially on multiuser systems it is a security risk to pass passwords on the command line, as that can possibly be viewd by other users, so it's a little better to store them in a file with restricted access permissions instead. This way only processes started by the owner of the file can access it.
Another use of the wget startup file is to change it's default settings, user agent etc...
It's all documented here.

Apache 2: calling 'a2ensite' from a bash script in Linux

I am currently writing an admin page for my webserver, to make it easier on myself to create new apache domains from my browser. Everything is pretty much working as I want it to, except for one thing.
To elaborate: I have a cron job on my server running a bash script as root that checks a file containing a list of domain names that I want to be created. If the file contains a domain name, it automatically creates a new virtual host for this domain, edits my hosts file, and restarts the server. This all works perfectly, however what I would like for the script to do, is that it activates the domain that it automatically creates before it restarts the server. I tried doing this using apache 2's a2ensite command, however the script returns an error saying the command is not found.
Is there a way to call this command from a bash script, or is there an alternative to this command that I can call?
Any help would be greatly appreciated.
$ which a2ensite
/usr/sbin/a2ensite
Usually, cron has a quite restrictive $PATH, not including /usr/sbin or /sbin, which are system binaries (for use by root). It's always a good idea to use fully qualified path names. So either call /usr/bin/a2ensite in your script, or define a variable:
A2ENSITE=/usr/sbin/a2ensite
...
${A2ENSITE} new-domain.com

Resources