Apache forbidden access with Docker - apache

I build this image on docker-compose.yml
version: '2'
services:
webserver:
build: ./docker/webserver
image: image_name
ports:
- "80:80"
- "443:443"
volumes:
- /Users/user_name/Sites/site:/var/www/html
And have this commands on Dockerfile
FROM php:7-apache
RUN apt-get update -y && apt-get install -y libpng-dev && apt-get
install -y libcurl4-openssl-dev
RUN docker-php-ext-install pdo pdo_mysql gd curl
RUN a2enmod rewrite
RUN service apache2 restart
BUT I get
Forbidden
You don't have permission to access / on this server.
Apache/2.4.10 (Debian) Server at localhost Port 80
when I go to localhost.
I work with Mac.
I have used the docker files to other project and all worked great.
what am I missing?
Log response
Cannot serve directory /var/www/html/: No matching DirectoryIndex
(index.php,index.html) found, and server-generated directory index
forbidden by Options directive

Looks like apache is not finding an index page to serve. Ensure your volume mapping is correct (enter the image with docker exec and check contents of /var/www/html folder). If your files are there, ensure that you have an index.html or index.php file for apache to be served.

If you change to apache document root to something non-standard outside of /var/www you will need to grant access in your vhost:
DocumentRoot /workspace/my-project
<Directory /workspace/my-project>
Require all granted
</Directory>

Related

Docker-compose can't start apache server

When i'm running sudo docker-compose up inside my dir, i get this error. I'm trying to make a container, that host a php website, where you can do whoami on it.
Thanks
(13)Permission denied: AH00072: make_sock: could not bind to address 0.0.0.0:80
| no listening sockets available, shutting down
| AH00015: Unable to open logs
Dockerfile:
FROM ubuntu:16.04
RUN apt update
RUN apt install -y apache2 php libapache2-mod-php
RUN useradd -d /home/cp/ -m -s /bin/nologin cp
WORKDIR /home/cp
COPY source .
USER cp
ENTRYPOINT service apache2 start && /bin/bash
docker-compose.yml
version: '2'
services:
filebrowser:
build: .
ports:
- '8000:80'
stdin_open: true
tty: true
volumes:
- ./source:/var/www/html
- ./logs:/var/log/apache2
There's a long-standing general rule in Unix-like operating systems that only the root user can open "low" ports 0-1023. Since you're trying to run Apache on the default HTTP port 80, but you're running it as a non-root user, you're getting the "permission denied" error you see.
The absolute easiest answer here is to use a prebuilt image that has PHP and Apache preinstalled. The Docker Hub php image includes a variant of this. You can use a simpler Dockerfile:
FROM php:7.4-apache
# Has Apache, mod-php preinstalled and a correct CMD already,
# so the only thing you need to do is
COPY source /var/www/html
# If you want to run as a non-root user, you can specify
RUN useradd -r -U cp
ENV APACHE_RUN_USER cp
ENV APACHE_RUN_GROUP cp
With the matching docker-compose.yml
version: '3' # version 2 vs 3 doesn't really matter
services:
filebrowser:
build: .
ports:
- '8000:80'
volumes:
- ./logs:/var/log/apache2
If you want to build things up from scratch, the next easiest option would be the Apache User directive: have your container start as root (so it can bind to port 80) but then instruct Apache to switch to the unprivileged user once it's started up. The standard php:...-apache image has an option to do this on its own which I've shown above.

docker volume, configuration files aren't generated

Same kind of issue than : what causes a docker volume to be populated?
I'm trying to share configuration file of apache in /etc/apache2 with my host, and file aren't generated automatically within the shared folder.
As minimal example:
Dockerfile
FROM debian:9
RUN apt update
#Install apache
RUN apt install -y apache2 apache2-dev
ENTRYPOINT ["apache2ctl", "-D", "FOREGROUND"]
docker-compose.yml
version: '2.2'
services:
apache:
container_name: apache-server
volumes:
- ./log/:/var/log/apache2
- ./config:/etc/apache2/ #remove it will let log generating files
image: httpd-perso2
build: .
ports:
- "80:80"
With this configuration, nor ./config nor ./log will be filled with files/folders generated by the container, even if log files should have some error (getting apache-server | The Apache error log may have more information.)
If I remove the ./config volume, apache log files will be generated properly. Any clue for which reason this can append ? How can I share apache config file ?
Having the same issue with django settings file, seem to be related to config file generated by an application.
What I tried :
- using VOLUME in Dockerfile
- running docker-compose as root or chmod 777 on folders
- Creating file within the container to those directory to see if they are created on the host (and they did)
- On host, creating shared folder chown by the user (chown by root if they are automatically generated)
- Trying with docker run, having exactly the same issue.
For specs:
- Docker version 19.03.5
- using a VPS with debian buster
- docker-compose version 1.25.3
Thanks for helping.

web admin noob - broke local webserver while trying to install jenkins

I just broke my local development web server while trying to install jenkins. Jenkins works. But other sites that I have built and used to access on my web server do not work.
I was following this article: https://wiki.jenkins-ci.org/display/JENKINS/Installing+Jenkins+on+Ubuntu
After following the main section to download and install jenkins, i ran the steps in the section "Setting up an Apache Proxy for port 80 -> 8080".
That's when I managed to break apache.
Here's the history of what I ran:
me#mydevbox:~$ sudo apt-get install jenkins
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
linux-image-4.2.0-34-generic linux-image-extra-4.2.0-34-generic
python-support
Use 'apt-get autoremove' to remove them.
The following extra packages will be installed:
daemon
The following NEW packages will be installed:
daemon jenkins
0 upgraded, 2 newly installed, 0 to remove and 8 not upgraded.
Need to get 64.0 MB of archives.
After this operation, 65.1 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://us.archive.ubuntu.com/ubuntu/ wily/universe daemon amd64 0.6.4-1 [98.2 kB]
Get:2 http://pkg.jenkins-ci.org/debian-stable/ binary/ jenkins 1.651.2 [63.9 MB]
Fetched 64.0 MB in 6s (9,372 kB/s)
Selecting previously unselected package daemon.
(Reading database ... 433471 files and directories currently installed.)
Preparing to unpack .../daemon_0.6.4-1_amd64.deb ...
Unpacking daemon (0.6.4-1) ...
Selecting previously unselected package jenkins.
Preparing to unpack .../jenkins_1.651.2_all.deb ...
Unpacking jenkins (1.651.2) ...
Processing triggers for man-db (2.7.4-1) ...
Processing triggers for systemd (225-1ubuntu9) ...
Processing triggers for ureadahead (0.100.0-19) ...
Setting up daemon (0.6.4-1) ...
Setting up jenkins (1.651.2) ...
initctl: Unable to connect to Upstart: Failed to connect to socket /com/ubuntu/upstart: Connection refused
[ ok ] Starting jenkins (via systemctl): jenkins.service.
ln: failed to create symbolic link ‘/run/openrc/started/jenkins’: No such file or directory
Processing triggers for systemd (225-1ubuntu9) ...
Processing triggers for ureadahead (0.100.0-19) ...
me#mydevbox:~$ sudo /etc/init.d/jenkins start
[ ok ] Starting jenkins (via systemctl): jenkins.service.
me#mydevbox:~$ sudo vim /etc/default/jenkins
me#mydevbox:~$ /etc/init.d/jenkins restart
[ ok ] Restarting jenkins (via systemctl): jenkins.service.
me#mydevbox:~$
This is what I've specified for the HTTP port in the jenkins config file:
# port for HTTP connector (default 8080; disable with -1)
HTTP_PORT=8080
After that, I ran this:
me#mydevbox:~$ sudo a2enmod proxy
Enabling module proxy.
To activate the new configuration, you need to run:
service apache2 restart
me#mydevbox:~$ sudo a2enmod proxy_http
Considering dependency proxy for proxy_http:
Module proxy already enabled
Enabling module proxy_http.
To activate the new configuration, you need to run:
service apache2 restart
me#mydevbox:~$ service apache2 restart
me#mydevbox:~$ sudo a2dissite default
ERROR: Site default does not exist!
me#mydevbox:~$ sudo a2dissite 000-default
Site 000-default disabled.
To activate the new configuration, you need to run:
service apache2 reload
me#mydevbox:~$ service apache2 reload
And then I created a jenkins.conf file in /etc/apache2/sites-available/
That file looks like this:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName ci.company.com
ServerAlias ci
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPreserveHost on
ProxyPass / http://localhost:8080/ nocanon
AllowEncodedSlashes NoDecode
</VirtualHost>
At this point, when I try to run:
http://localhost:8080/
That launches jenkins.
But I no longer can run my other sites which i launched like this:
localhost/mytestapp
The error I get is:
HTTP ERROR 404
Problem accessing /mytestapp/. Reason:
Not Found
Prior to attempting Jenkins install, I just installed apache2 and left all defaults. I would just create folders under /var/www/html and they would "just magically" appear in my browser.
Sorry for the trouble. But any help would be appreciated.
EDIT 1
I think my problem is related to this:
me#mydevbox:~$ sudo a2dissite 000-default
Site 000-default disabled.
I never noticed that in the output before. When I checked that file, it looks like that was the original conf I had.
Here's what I have in the sites-available folder:
me#mydev:/etc/apache2/sites-available$ ls -lah
total 24K
drwxr-xr-x 2 root root 4.0K May 30 11:06 .
drwxr-xr-x 8 root root 4.0K Apr 19 15:18 ..
-rw-r--r-- 1 root root 1.5K Apr 19 15:30 000-default.conf
-rw-r--r-- 1 root root 6.3K Jan 7 2014 default-ssl.conf
-rw-r--r-- 1 root root 282 May 30 11:06 jenkins.conf
me#mydev:/etc/apache2/sites-available$
So I guess I need a way to re-enable 000-default.conf and just add an entry for jenkins to use port 8080 or something like that.
Googling for examples but in the mean time, if you have any suggestions, I'd appreciate them.
Thanks.
I ran the following commands to enable both sites:
me#mydev:/etc/apache2$ sudo a2ensite 000-default
Enabling site 000-default.
To activate the new configuration, you need to run:
service apache2 reload
me#mydev:/etc/apache2$ service apache2 reload
me#mydev:/etc/apache2$ cd sites-enabled/
me#mydev:/etc/apache2/sites-enabled$ ls
000-default.conf jenkins.conf

Share folders Docker

I'm used to develop on vagrant but docker looks faster so I just tried it. This seems really good but I need to share the folders between my host and docker to easily update my code without recompiling docker.
I tried to add:
VOLUME /Users/ajouve/dev/test/test:/var/www/test
or
VOLUME /Users/ajouve/dev/test/test:/var/www/test:rw
in my dockerfile but the folders are nos sync
This is my complete dockfile
FROM ubuntu:12.04
MAINTAINER ajouve version: 0.1
RUN apt-get update && apt-get install -y apache2 && apt-get clean && rm -rf /var/lib/apt/lists/*
RUN mkdir /var/www/test
VOLUME /Users/ajouve/dev/test/test:/var/www/test:rw
COPY test.conf /etc/apache2/sites-availables/
RUN ln -s /etc/apache2/sites-availables/test.conf /etc/apache2/sites-enabled/test.conf
ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_LOG_DIR /var/log/apache2
EXPOSE 80
CMD ["/usr/sbin/apache2", "-D", "FOREGROUND"]
this is the test.conf
<VirtualHost *:80>
ServerName test.local
DocumentRoot /var/www/test
<Directory /var/www/test>
# enable the .htaccess rewrites
AllowOverride All
Order allow,deny
Allow from All
</Directory>
ErrorLog /var/log/apache2/test-error.log
CustomLog /var/log/apache2/test-access.log combined
</VirtualHost>
I have an empty folder when I'm trying to access to the server via a browser
You can bind the folder when you start your docker instance
with -v /src/dockerShared/:/usr/local/src
have a Look here for a example
Your host folder have to be owned by the same uid:gid of the folder inside the container.

phpmyadmin "Not Found" after install on Apache, Ubuntu

Setting up a development environment with Ubuntu 14.04 running in VirtualBox, following this guide: http://klau.si/dev
After installing phpmyadmin, it seems I should be able to access it at http://localhost/phpmyadmin but apache returns a Not Found error. Did this guide leave out a configuration step somewhere? I have already tried restarting the apache service.
There is no phpmyadmin.conf file in apache2/sites-enabled or apache2/sites-available, is this required?
If so, where can I find these files?
using 127.0.0.1 instead of localhost returns the same error. The default apache page at http://localhost works just fine.
the console in the browser shows nothing of value, simply Not Found.
I have also tried rerunning the install script with dpkg-reconfigure -plow phpmyadmin
This issue was resolved thanks to this guide: https://help.ubuntu.com/community/ApacheMySQLPHP#Troubleshooting_Phpmyadmin_.26_mysql-workbench by adding
Include /etc/phpmyadmin/apache.conf
...to the /etc/apache2/apache2.conf file and restarting the service.
Try this
sudo ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf-available/phpmyadmin.conf
sudo a2enconf phpmyadmin.conf
sudo systemctl restart apache2
sudo dpkg-reconfigure -plow phpmyadmin
Select No when asked to reconfigure the database. Then when asked to choose apache2, make sure to hit space while [ ] apache2 is highlighted. An asterisk should appear between the brackets. Then hit Enter. Phpmyadmin should reconfigure and now http://localhost/phpmyadmin should work. for further detail https://www.howtoforge.com/installing-apache2-with-php5-and-mysql-support-on-ubuntu-13.04-lamp
The easiest way to do in ubuntu (I tested in ubuntu-20.04):
Step 1. Open the file:
sudo nano /etc/apache2/apache2.conf
Step 2: Add the following line at the end of file:
Include /etc/phpmyadmin/apache.conf
Step 3: Restart apache2:
sudo systemctl restart apache2.service
Create a link in /var/www like this:
sudo ln -s /usr/share/phpmyadmin /var/www/
Note: since 14.04 you may want to use /var/www/html/ instead of /var/www/
If that's not working for you, you need to include PHPMyAdmin inside apache configuration.
Open apache.conf using your favorite editor, mine is nano :)
sudo nano /etc/apache2/apache2.conf
Then add the following line:
Include /etc/phpmyadmin/apache.conf
For Ubuntu 15.04 and 16.04
sudo ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf-available/phpmyadmin.conf
sudo a2enconf phpmyadmin.conf
sudo service apache2 reload
Finally I got the solution
sudo ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf-available/phpmyadmin.conf
sudo a2enconf phpmyadmin
sudo service apache2 reload
More about
https://askubuntu.com/questions/55280/phpmyadmin-is-not-working-after-i-installed-it
Create a link in /var/www/html like this to fix the error:
sudo ln -s /usr/share/phpmyadmin /var/www/html
For anyone still running into issues with this- check that you're actually using apache! I knocked my head against this for 20 minutes or so before I remembered...I use NginX on this server...=). #john-smith, this one's for you buddy.
To get it working on nginx, all you should have to do is create a sim link and restart php:
sudo ln -s /usr/share/phpmyadmin /var/www/html
Note that for you, it may be /var/www/ and not /var/www/html, depending on your dir structure.
sudo ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf-available/phpmyadmin.conf
sudo ln -s /usr/share/phpmyadmin /var/www/html/phpmyadmin
sudo service apache2 restart
Run above commands issue will be resolved.
Run the following command in terminal:
sudo ln -s /usr/share/phpmyadmin /var/www/html/
It seems like sometime during the second half of 2018 many php packages such as php-mysql and phpmyadmin were removed or changed. I faced that same problem too. So you'll have to download it from another source or find out the new packages
You will need to configure your apache2.conf to make phpMyAdmin works.
sudo nano /etc/apache2/apache2.conf
Then add the following line to the end of the file.
Include /etc/phpmyadmin/apache.conf
Then restart apache
sudo service apache2 restart
I had the same issue where these fixes didn't work.
I'm on Ubuntu 20.04 using hestiaCP with Nginx.
Today after adding
Include /etc/phpmyadmin/apache.conf
into both Apache and Nginx, Nginx failed to restart. It was having an issue with "proxy_buffers" value.
Yesterday I had to modify the Nginx config to add and increase these values so Magento 2.4 would run. Today I altered "proxy_buffers" again
proxy_buffers 3 64k;
proxy_buffer_size 128k;
proxy_busy_buffers_size 128k;
After the second alteration and the removal of "Include /etc/phpmyadmin/apache.conf" from both Apache and Nginx, Magento 2.4 and PHPMyAdmin are working as expected.
I didn't try Rashmi Jain's symlink answer. It seems like it would work. But if it doesn't work for you, perhaps try this.
I just created the file `/etc/apache2/conf-available/phpmyadmin.conf' and added this line to it:
Include /etc/phpmyadmin/apache.conf
(rather than putting it into /etc/apache2/apache2.conf as in Anonymous Man's answer)
Then:
sudo a2enconf phpmyadmin
sudo systemctl reload apache2
I had the same problem after installing mysql, apache2, php and finally phpmyadmin after each other. In my case it was solved by restarting apache2 (no need to update any configuration file):
sudo systemctl restart apache2
#John smith, I was facing the same issue of not being able to access phpmyadmin for 3 days, I found the solution.
-- Get xampp, check this tutorial https://youtu.be/VHfij95yOpo
-- Run this command before starting xampp app
sudo /etc/init.d/apache2 stop
sudo service mysql stop
That's it, it worked for me
first go to the location of phpmyadmin via terminal then type this
code php -S localhost:8001
First check PhpMyAdmin is install or not. If it is installed then search PhpMyadmin folder. After search cut and paste that folder in location Computer->var->www->html->paste folder. Open browser and type localhost/phpMyAdmin and login using username and password.
If you are having this problem in 2019, go to your 000-default.conf file, by typing this subl /etc/apache2/sites-enabled/000-default.conf (in your terminal to open the file in sublime editor)
When the file loads, locate "The ServerName directive sets the request scheme" and place this "Include /etc/phpmyadmin/apache.conf" on top .
Then restart your apache with the command...service apache2 restart That will certainly fix the issue. Hope it helps!