Docker www-data grant write permissions to var/www - apache

I'm running a php:7.0-apache Docker image, but I have no permissions to write to /var/www/html. How is it possible to grant write rights to this user?
Dockerfile:
FROM php:7.0-apache
# PHP Extensions
RUN docker-php-ext-install pdo_mysql
# Composer
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
RUN php composer-setup.php
RUN php -r "unlink('composer-setup.php');"
RUN mv composer.phar /usr/local/bin/composer
ADD vhost-default.conf /etc/apache2/sites-enabled/000-default.conf
# Open Ports
EXPOSE 80
EXPOSE 443
Host Conf
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/html >
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>

To resolve this you will need to add an extra line in your Dockerfile like:
RUN chown www-data:www-data /var/www/html/

Sergiu's answer is not working, because your volume is bound after chown.
What you should do is that you should run chown after bound to your volume and before start the Apache.
To do that, I add chown command in the apache2-foreground script.
RUN sed -i 's/^exec /chown www-data:www-data \/var\/www\/html/\n\nexec /' /usr/local/bin/apache2-foreground
So when you start your container, it will change the permission to www-data.
PS: Your container's user should be in root or a user who can execute chown.

Related

Send Apache errorlogs from a docker container to syslog host

I have a container with apache2 and modsecurity installed.
My question is: how to send the logs generated by apache and modsecurity (stored in /var/apache2/error.log) to the host?
I have syslog within the host that already collect locally and send the logs to a remote server; I'm able to send the logs from other containers correctly but not from the apache container.
I tried several ways but unfortunately i was not able to achieve this objective:
Piping with: ErrorLog "| :514"
ErrorLog /dev/stderr
TransferLog /dev/stdout
Within dockerfile: RUN ln -sf /proc/self/fd/1 /var/log/apache2/access.log &&
ln -sf /proc/self/fd/1 /var/log/apache2/error.log
This is my current configuration:
/etc/apache2/sites-available/000-default.conf
...
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SecRuleEngine On
...
There is a default modsecurity configuration for now.
Thank you.

Host Multiple Domains on One Server/IP

I have phpList already setup and Codeigniter project that I want to add in one server.
The phpList configuration which is located /etc/httpd/conf.d/phplist.conf has:
<VirtualHost *:80>
ServerName phplist.example.com
ServerAdmin admin#example.com
DocumentRoot /var/www/phplist-3.0.5/public_html
LogLevel warn
ErrorLog /var/log/httpd/phplist_error.log
CustomLog /var/log/httpd/phplist_access.log combined
</VirtualHost>
Here is my possible setting for the CI project, but I don't know how to create one.
<VirtualHost *:80>
ServerName listcsv.com
ServerAdmin admin#listcsv.com
DocumentRoot /var/www/citest/index.php
</VirtualHost>
Below the /etc/httpd/conf/httpd.conf file has a IncludeOptional conf.d/*.conf so I think this would include the configuration file on phplist.
I don't know what settings and where configuration file should I go,
should I edit on /etc/httpd/conf/httpd.conf or just add it together with the phpList configuration at /etc/httpd/conf.d/phplist.conf?
I tried accessing phplist at http://phplist.example.com but the site cannot be reached.
I could access the phpList by going to http://server-ip-address/lists/admin on the browser.
Also, I cannot access the CI project.
I would recommend creating the directory that the virtual hosts will be stored in, as well as the directory that tells Apache that a virtual host is ready to serve the website
sudo mkdir /etc/httpd/sites-available # vhost files
sudo mkdir /etc/httpd/sites-enabled # symbolic links for vhost enabled
Tell Apache where to look for virtual hosts
sudo vim /etc/httpd/conf/httpd.conf
Add this line at the end of the file
IncludeOptional sites-enabled/*.conf
Save and exit.
For each website/domain create its own vhost
sudo vim /etc/httpd/sites-available/example1.com.conf
sudo vim /etc/httpd/sites-available/example2.com.conf
sudo vim /etc/httpd/sites-available/example3.com.conf
Enable the virtualhost
sudo ln -s /etc/httpd/sites-available/example1.com.conf /etc/httpd/sites-enabled/example1.com.conf
sudo ln -s /etc/httpd/sites-available/example2.com.conf /etc/httpd/sites-enabled/example2.com.conf
sudo ln -s /etc/httpd/sites-available/example3.com.conf /etc/httpd/sites-enabled/example3.com.conf
We done, restart your Apache server for the changes to take affect
sudo apachectl restart
Don't forget to point your domains to the web server's public IP address.

rails 4 deployment - not displaying the home page , only the list of files in public

I deployed my rails 4 app on my remote server ( Debian 7) w Capistrano3 wo any error ..
but when I hit the url in a browser ( http://www.ceramique-isabelle.fr) I can see the list of files/folders in the current release directory...
it's deployed into /var/www/rails/production/workshop on the rmeote server ,
and I have in /etc/apache2/sites-available/ceramique-isabelle.fr a vhost
<VirtualHost *:80>
ServerAdmin webmaster#webdufour.com
ServerName ceramique-isabelle.fr
ServerAlias www.ceramique-isabelle.fr
DocumentRoot /var/www/rails/production/workshop/current/public
setenv RAILS_ENV production
<Directory /var/www/rails/production/workshop/current/public>
AllowOverride All
RailsEnv production
Options -MultiViews
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/apache2/workshop_error_log
CustomLog /var/log/apache2/workshop_access_log common
</VirtualHost>
I also enabled the site a2ensite ceramique-isabelle.fr
and reloaded apache2
I forgot to reinstall Passenger afte switching from rbvm to rbenv ..
gem install passenger
rbenv rehash
sudo bash -c "source ~/.bashrc && passenger-install-apache2-module"
then modifying my apache2.conf
and restarting apache2... now up and running

Apache doesn't use DocumentRoot after upgrading to Ubuntu 13.10 (Uses default page that says "It works!")

I have various virtual hosts for my web development work, including
cnm. The
sites-available/cnm
my file says very simply:
<VirtualHost *:80>
ServerName cnm
DocumentRoot /var/www/cnm/public_html
</VirtualHost>
I upgraded to Ubuntu 13.10, and when I point my browser to cnm/, I see the
/var/www/index.html file that seems to be indicated in the default file
sites-available/000-default.conf
which says (among other things):
<VirtualHost *:80>
DocumentRoot /var/www
What do I need to do to get Apache to read my cnm document root when I browse to cnm/ ?
NOTES:
I already tried renaming my sites-available/cnm file to sites-available/cnm.conf and enabling it with a2ensite cnm and service apache2 reload. That is a good thing, but it changes nothing.
I already tried changing <VirtualHost *:80> to <VirtualHost cnm.localhost> or to <VirtualHost cnm>. That did nothing.
Ubuntu 13.10 uses apache 2.4, you should check all your apache configuration. But for this present case you should note that a2ensite and a2dissite commands won't be able to see your files in /etc/apache2/sites-available if it does not end with .conf, so rename it to sites-available/cnm.conf and run a2ensite cnm.
Then your Virtualhost definition is certainly better with *:80, it means this virtualhost is activated for all IP interfaces (*) on port 80. cnm.localhost or cnm are not valid values here, only IP numbers (Ip of your apache server) or * for all, and a port number.
Then check how you configuration is read by apache, running theses commands:
# load apache env
# be careful, there is a dot and a space
. /etc/apache2/envvars
# Check apache Virtualhosts config
apache2 -S
You should get something like:
VirtualHost configuration:
*:80 is a NameVirtualHost
default server something (/etc/apache2/sites-enabled/000-default.conf:1)
port 80 namevhost something (/etc/apache2/sites-enabled/000-default.conf:1)
port 80 namevhost cnm (/etc/apache2/sites-enabled/cnm.conf:4)
If it is ok, and if you have the right Ip in your hosts file for cnm, and you can test that with a ping, then using http://cnm/ should use the Virtualhost having cnm in the ServerName.
If you have an answer from the default Virtualhost then it means apache is not finding the name used in your Host header in the list of ServerName and ServerAlias available for that IP/port and fallbacks to the default Virtualhost. If you are really stuck (and you did not forgot to restart) you can always remove the default Virtualhost and keep only the one you are working on.
I found the answer to my issue. I needed to delete the files in /etc/apache2/sites-enabled.
Delete files in /etc/apache2/sites-enabled
Rename config files in /etc/apache2/sites-available to have a .conf ending
For each file in sites-available, run sudo a2ensite mysite.
Run sudo service apache2 reload
I couldn't find any step by step tutorial on how to make it work on my side. I gathered bits and pieces here and there, so for those who need all the steps to follow, here there are:
$ sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/local-mydefault.conf
$ sudo gedit /etc/apache2/sites-available/local-mydefault.conf
Paste the following into the local-mydefault.conf file (Change the path '/your/full/path' to where you want to have your files. And change username to your own username):
# ------------------------------------------------------
<VirtualHost *:80>
ServerName localhost
ServerAdmin webmaster#localhost
DocumentRoot /your/full/path
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /your/full/path>
DirectoryIndex index.php
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Require all granted
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
User username
Group username
# ------------------------------------------------------
Then type the following commands
$ cd /etc/apache2/sites-available/
$ sudo a2ensite local-mydefault.conf
$ sudo a2dissite 000-default.conf
$ sudo /etc/init.d/apache2 restart
I found the answer to this issue:
When upgrading to Ubuntu 13.10, the DocumentRoot does not seem to make a difference.
This is because Apache 2.4 moved the Directory configuration somewhere else. Your old .conf files still have these lines:
DocumentRoot "/var/www/myVhost"
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory "/var/www/myVhost">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
Remove (or comment out) the <Directory> directives so you only have:
DocumentRoot "/var/www/myVhost"
Now reload your settings: service apache2 reload and DocumentRoot is back. :)
Rename the file configuration "cnm" with the extension .conf
mv sites-available/cnm sites-available/cnm.conf
a2ensite sites-available/cnm.conf
And ready!
service apache2 reload
I have the same issue
on way is to disable 000-default and reload apache ,but this isn't the solution becuase you must have just one vhost at a same time :(
sudo a2dissite 000-default.conf
sudo service apache2 reload
I ran into a similar issue. My server name and my FQDN were the same to the default was running into the /var/www/html directory. I disabled the default configuration and my site worked like a breeze. Thanks #regilero.
sudo a2dissite 000-default.conf
fixed it for me.

Forbidden error in apache virtual host setup

Hello I have been looking through internet articles forums to solve my issue and so far it has been to no avail. I am trying to set up an Apache virtual host for my FuelPHP development on localhost but I keep getting slammed with the error 403 message. Here is my current setup.
#/etc/apache2/sites-enabled/000-default
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin webmaster#example.com
DocumentRoot "/home/supercomputer/Desktop/PHP/fuelProject/public"
ServerName localhost.home
<Directory "/home/supercomputer/Desktop/PHP/fuelProject/public" >
Options Indexes FollowSymLinks MultiViews Includes ExecCGI
AllowOverride All
Order Allow,Deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
I have pointed my Docroot to the public folder inside my fuelProject. Also to make sure Apache had access to the server files, I set the permissions for all of the files recursively to read, write, and execute just to be a 100% safe. Any clues as to what else could be going wrong?
PS: I am running ubuntu raring (13.04)
PSS: And I am trying to visit localhost.home and localhost.home/index.php. I also get the following warnings upon restarting the server
* Restarting web server apache2 apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
[Fri May 03 15:46:58 2013] [warn] NameVirtualHost *:80 has no VirtualHosts
... waiting apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
[Fri May 03 15:46:59 2013] [warn] NameVirtualHost *:80 has no VirtualHosts
Here is the correct way of adding Vhost for fuelphp application or any other php application
<VirtualHost *:80>
ServerName localhost.home
DocumentRoot /home/supercomputer/Desktop/PHP/fuelProject/public
ServerAdmin webmaster#localhost
<Directory /home/supercomputer/Desktop/PHP/fuelProject/public>
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
And also the below line is not required I dont know why you have added
NameVirtualHost *:80
After doing all above add a host entry to your machine to do that
sudo vi /etc/hosts
add an entry of the virtual host
127.0.0.1 localhost.home
After doing all these things
restart Apache by running
sudo /etc/init.d/apache2 restart
And just load http://localhost.home in your browser you should be able to see your site up and running .
If you still get forbidden error .you need to give permissions to your whole application folder
follow run these commands to do so
sudo chown -R www-data:www-data /home/supercomputer/Desktop/PHP
sudo chmod -R 775 /home/supercomputer/Desktop/PHP
At last add yourself to www-data group
sudo adduser yourUserName www-data
The configuration I posted were working. The problem was with permissions. I had set only my containing fuel project folder to permission 777 but for some reason apache wanted access to almost all the folders containing it. Weird I know but setting all the permissions to 777, it worked. Reading the darn apache log sure helped. If you are having a similar problem, I suggest find the apache log and ACTUALLY READ IT
Testeed on Ubuntu 14.04: I did everything above but I didn't work. I missed to allow access to the directory in my apache2.conf. This is needed if you don't use a standard directory like /var/www or /usr/share/.
<Directory /usr/local/vufind>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
This was mentioned on the4 default PHP site. It's worth reading it!