whoami returns apache instead of root - php

I'm trying to serve an application from location /usr/local/administer/. There is a index.php file inside /usr/local/administer/index.php inside that index.php file is the following code
echo exec('whoami');
The result from the above code is apache however the result should be root as per my configuration in the vhost using mod-ruid2
administer.conf
The following is the configuration that I'm currently working with.
<Directory /usr/local/administer/web>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
<VirtualHost *:80>
DocumentRoot /usr/local/administer/
ServerName administer.com
ServerAlias www.administer.com
RMode config
RUidGid root root
RGroups root
</VirtualHost>
Any suggestions or advise?

As Mike 'Pomax' Kamermans has mentioned in the comment that not to run any task via PHP with root user. You'll get into trouble. If you are logged-in as root and running whoami via PHP then root won't show up. I'm not sure why this is happening. A possible solution in my preference is:
Create another user
Replace root with the new username
Restart Apache

Related

Need some assistance with my apache2 site config file

I'm trying to get apache2 to point to a PHP based application (word press in this case but the config needs to be generic enough to work for any php application).
and it either displays some basic HTML file access page or errors with "You don't have permission". I don't really know apache and I don't know PHP at all. Here's my current site_config file as it stands(with retractions replaced with ):
<VirtualHost *:80>
ServerAdmin <app_user>#localhost
ServerName amazonaws.com/<app_name>
ServerAlias *.amazonaws.com/<app_name>
DocumentRoot /home/<app_user>/<app_location>/staging/current
<Directory /home/<app_user>/<app_location>/staging/current >
AllowOverride All
Options -Indexes
Order allow,deny
Allow from all
</Directory>
LogLevel error
ErrorLog ${APACHE_LOG_DIR}/error.log
</VirtualHost>
I would also like to make it so you can have multiple websites on the same box but I'm not sure how to change the VirtualHost arg *:80 to account for that, I just get loads of ignoring errors.
I also have the following line in my apache2.conf:
DirectoryIndex index.php index.html
Folder permissions are set to 0755 for all files & folders in the project directory
output of apache2 -v:
Server version: Apache/2.4.7 (Ubuntu)
P.s. I know nothing about PHP and very little about apache2 so for this, speak to me as a total noob.
To solve The first problem I had to change the following lines:
Order allow,deny
Allow from all
to:
Require all granted
this finally allowed apache to allow users access to the folders, the second thing was to add an alias:
Alias /<app_name> "/home/<app_user>/<app_location>/staging/current"
and it started working as expected so now my site config looks like:
Alias /<app_name>"/home/<app_user>/<app_name>/<app_environment>/current"
<Directory "/<app_name>"/home/<app_user>/<app_name>/<app_environment>/current">
AllowOverride All
Options -Indexes
Require all granted
</Directory>
<VirtualHost *:80>
DocumentRoot "/<app_name>"/home/<app_user>/<app_name>/<app_environment>/current"
ErrorLog "/var/log/apache2/<app_name>.error_log"
CustomLog "/var/log/apache2/<app_name>.access_log" combined
</VirtualHost>

How to remove public from the URL of Laravel project?

I've followed this and this answers to remove /public form the URL of my Laravel project. Now /public is removed from the URL. But my IDE (phpstorm) is throwing an error:
Does anybody know how can I fix it?
Note: I use Laravel 5.4
Change your apache vhost / host document root to projects public folder. its realted to apache config.
<VirtualHost *:80>
ServerName findexample.com
DocumentRoot c:/xampp/htdocs/find_people/public
<Directory c:/xampp/htdocs/find_people/public>
Options Indexes FollowSymLinks
AllowOverride all
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/find-people-error.log
CustomLog ${APACHE_LOG_DIR}/find-people-access.log combined
</VirtualHost>
See how to setup apache vhost on windows
You dont need to touch on any file to get what you want.
Try setting your document root to
path/to/your/laravel_app/public/
If your root is pointing to your public folder, when you access it from Browser, you will not need to use public in the url.
Remember that you must enable ModRewrite.

Apache website permissions under Centos 7

I have a site in dir /home/nbo/mysiteA. (nbo is the user)
I've create a new dir structure /var/www/mysiteB/public_html
public_html is a symlink to /home/nbo/mysiteA
httpd.conf settings:
Listen 82
<VirtualHost *:82>
ServerName mysite.com
DocumentRoot /var/www/mysiteB/public_html/
DirectoryIndex index.php
<Directory "/var/www/mysiteB/public_html/">
Options +FollowSymLinks -SymLinksIfOnwerMatch
Require all granted
AllowOverride All
</Directory>
</VirtualHost>
When I test the website I get a 403 error (Forbidden You don't
have permission to access /index.php on this server.)
I've already tried to add the nbo user to apache group.
I've already tried to change the ownership of the entire site to apache user.
What I'm missing?

Accessing files above the web server document root folder

Reading elsewhere, I have come across the concept of placing files I don't want accessible to the public above my web root folder. Doing this on my local WAMP stack works without issue, but once transferring over to my VPS (running Ubuntu 10.04.4 LTS) the PHP scripts can only see files under the root directory.
VirtualHost setup for my subdomain:
<VirtualHost *:80>
# Admin email, Server Name (domain name), and any aliases
ServerAdmin ##########.com
ServerName admin.########.com
ServerAlias www.admin.########.com
# Index file and Document Root (where the public files are located)
DirectoryIndex index.html index.php admin.php
DocumentRoot /srv/www/#######.com/public_html/admin/web_pages
<Directory /srv/www/#######.com/public_html/admin/web_pages>
Options +Indexes
AllowOverride All
</Directory>
# Log file locations
LogLevel warn
ErrorLog /srv/www/########.com/logs/error.log
CustomLog /srv/www/########.com/logs/access.log combined
</VirtualHost>
Log error given: File does not exist: /srv/www/#######.com/public_html/admin/web_pages/css, referer: http://www.admin.########.com/
(My css folder is above the web_pages folder, and is called via this path: ../css/####.css)
Is this an issue with my configuration settings, or am I attempting to do something I shouldn't be, and instead have everything I need under my web root? I would really like constants files and application logic not accessible, but css,html pages, and images are ok.
If you want to grant public access to some folders above web root, you may use Alias directive:
Alias /css/ "/srv/www/#######.com/public_html/admin/css"
<Directory /srv/www/#######.com/public_html/admin/css>
# some configuration directives here
</Directory>
After that, your css files will be accessible via new path (without ..): /css/####.css
Don't forget to switch on mod_alias Apache module

changing documentroot for apache on windows isn't working

I'm trying to change documentroot on my local windows machine to point at a sub directory below htdocs. I've changed the DocumentRoot location inside httpd.conf along with the Directory location. I've restarted Apache but prinitng out document root with PHP it still points to the default location.
Changes inside httpd.conf:
DocumentRoot "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/folder_test/website"
<Directory "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/folder_test/website">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
When I navigate to http://localhost/folder_test/website I see the following from my PHP output:
C:/Program Files/Apache Software Foundation/Apache2.2/htdocs
My PHP code:
<?php
//Get the document root
$root = getenv("DOCUMENT_ROOT") ;
Echo $root;
?>
I've restarted Apache...What am I missing?
Open the "\conf\extra\httpd-vhosts.conf" file.
Change the
<VirtualHost _default_:80>
DocumentRoot "${SRVROOT}/htdocs"
#ServerName www.example.com:80
</VirtualHost>
section to reflect the desired directory, in your case:
<VirtualHost _default_:80>
DocumentRoot "${SRVROOT}/htdocs/folder_test/website"
#ServerName www.example.com:80
</VirtualHost>
Hey if this is not answered still:
Sometimes when you change document root and other info in httpd.conf it does not reflect that it because the changes you have dont is not saved at all. In notepad++ and diffmerge it does not show that it is not saved on the contrary it shows as saved. Open it in normal notepad and when you try to replace it it says access denied. May be this is because these folder dont have the modification permission for users. Hence for this purpose you need to
Save the changes in a separate file else where with the same name
httpd.conf
Rename http.conf inside your apache root document to
httpd_backup.conf or just delete it.
now copy the new file you have created i.e. httpd.conf to apache
root document.
Go to "Open apache monitor" and restart
clear all cache and cookies in your browser and try again

Categories