I have ubuntu 16 and I am trying to work with docker by using PHP 7.4 using this article https://linuxhint.com/lamp_server_docker/ .
Everything is working expect from http://localhost:8080/ as it keeps saying "403 Forbidden".
Here below is how my docker-compose.yaml
looks like. Created a folder and files inside /var/www/html/docker2
.
version: "3.7"
services:
web-server:
build:
dockerfile: php.Dockerfile
context: .
restart: always
volumes:
- myapp:/home/user/Desktop/project
ports:
- "8080:80"
mysql-server:
image: mysql:8.0.19
restart: always
environment:
MYSQL_ROOT_PASSWORD: secret
volumes:
- mysql-data:/var/lib/mysql
phpmyadmin:
image: phpmyadmin/phpmyadmin:5.0.1
restart: always
environment:
PMA_HOST: mysql-server
PMA_USER: root
PMA_PASSWORD: secret
ports:
- "5000:80"
volumes:
mysql-data:
myapp:
external: true
As you can see I have created my project at home/user/Desktop/project
and I have already done sudo chmod -R 755 /home/user/Desktop/
and also opened 000-default.conf
by going at /etc/apache2/sites-available/000-default.conf
and added below code.
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /home/user/Desktop/project
<Directory /home/user/Desktop/project>
Require all granted
</Directory>
</VirtualHost>
I have also created index.php
file at /home/user/Desktop/project/index.php
and added below code to test.
When I do docker-compose up -d
, all services getting started .. I am also able to go to my new phpmyadmin with 5000
port http://my.i.p.address:5000/
but when I am trying to go here http://localhost:8080/
it keeps saying 403 Forbidden
. I have also set the permission sudo chmod -R 755 /home/user/Desktop/
and restarted both apache – sudo service apache2 restart
and docker – docker-compose restart
but no luck.
<?php
phpinfo();
?>
Can anyone guide me how to solve this ?
Thanks in advance.
2
Answers
It looks like you have set up your Apache configuration correctly, but the issue might be related to the ownership and permissions of the files and directories inside your project folder.
Here are a few steps you can take to troubleshoot and resolve the issue:
Check Ownership:
Ensure that the files and directories in your project folder are owned by the correct user. Run the following command to change ownership recursively to your user:
sudo chown -R $USER:$USER /home/user/Desktop/project
Replace $USER with your actual username.
Check Permissions:
Make sure that the permissions are set correctly. Run the following command to set the correct permissions:
Check the Apache error logs for any specific error messages. You can view the error log using the following command:
Look for any error messages related to permissions or access issues.
After making changes to your Apache configuration or file permissions, reload the Apache service to apply the changes:
Alternatively, you can restart Apache:
If you are using Docker volumes, ensure that the Docker container has the correct permissions to read from the volume. You may need to adjust the user or group within the Docker container to match the permissions on the host.
After making these changes, try accessing http://localhost:8080 again. If the issue persists, check the Apache error logs for any new error messages, as they can provide valuable information about the problem. Adjust the permissions accordingly until the issue is resolved.
This issue might be related to file permissions or configuration settings. You can try the permissions below.
create the docker group and add your user:
and then log out and log back in so that your group membership is re-evaluated.
Have a look at the link below
https://docs.docker.com/engine/install/linux-postinstall/