0

I am implementing my simple webservice in linux using Apache, CGI(C++) and Flat File(Data).

I kept my WWW location path in /usr/share/www/ CGI location path in /usr/lib/cgi-bin/ Data location path in /usr/share/Data/

I just wanted to access my files located in WWW and Data only through my Apache server and CGI application. Sometimes I will updated my Data Files, some times I will copy some file from Data to WWW folder using CGI application. Important that my Data Files only should by accessed by my CGI application not by any other at any cost. So I decided to give permission and ownership just like following. But It could not copy a file from Data to WWW Folder.

sudo chmod 644 -R /usr/share/Data/
sudo chown www-data /usr/share/Data/

Its not working to copy a file from Data to WWW using my CGI application. What are the permission should I provide for the above 3 locations(WWW,CGI,Data) to secure my web service.

My Apache Configuration is,

<VirtualHost *:80>
        ServerName www.mytestsite.com
        ServerAdmin webmaster@localhost
        DocumentRoot /usr/share/www/
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin/">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Require all granted
        </Directory>

<Directory /usr/share/www/>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
        </Directory>

</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
  • 3
    The /usr folder in Ubuntu stands for "Unix System Resources" In other words this folder should have the operating systems files. This is probably not the right folder to keep your web data. Messing with the permissions of system files and folders are not the best ideas either. The web server data should be in the sub-directories of /var/. – user68186 Apr 12 '18 at 12:06
  • @user68186. Yes. I understand that. I will change every data from /usr later. Now I just want to know that permissions and ownership for the folders of my case. – Smith Dwayne Apr 12 '18 at 12:15
  • 1
    Remember that you nead +x to traverse a directory. Thus, all folders in the path must have +x for Apache's user. – vidarlo Apr 12 '18 at 12:19

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.