Modifying Wordpress official docker image to work on subdirectory - wordpress

I am planning to use Wordpress official docker image on Amazon ECS. The problem is that instead working on the root path https://www.example.com/, I need it to work on a subdirectory path https://www.example.com/blog/.
To modify this I am planning to create a new Docker image based on the official Wordpress docker image.
My current Dockerfile looks like this.
FROM wordpress:6.0.1-apache
# Copying to premium so user can access it through
# domain/blog
RUN cd /var/www/html; \
mkdir blog; \
cp !\(blog\) blog; \
# We copy the wordpress instance to subdirectory and disable
# access to the root instance.
echo "Hello World!" > /var/www/html/index.php;
However this doesn't work. When I access https://www.example.com/blog it shows Forbidden.
The log shows this
[autoindex:error] [pid 23] [client 172.30.0.1:61822] AH01276: Cannot serve directory /var/www/html/blog/: No matching DirectoryIndex (index.php,index.html) found, and server-generated directory index forbidden by Options directive
It seems that the image does not copy the wordpress library.
wordpress % docker compose exec wordpress bash
root#63d417de7f31:/var/www/html# ls
index.php blog wp-config.php wp-content
root#63d417de7f31:/var/www/html# ls -al
total 32
drwxrwxrwx 4 www-data www-data 4096 Aug 5 06:13 .
drwxr-xr-x 1 root root 4096 Aug 2 07:49 ..
-rw-r--r-- 1 root root 13 Aug 5 06:06 index.php
drwxr-xr-x 2 root root 4096 Aug 5 06:06 blog
-rw-r--r-- 1 www-data www-data 5584 Aug 5 06:13 wp-config.php
drwxrwxrwx 5 www-data www-data 4096 Aug 5 06:13 wp-content
root#63d417de7f31:/var/www/html# ls -al blog/
total 8
drwxr-xr-x 2 root root 4096 Aug 5 06:06 .
drwxrwxrwx 4 www-data www-data 4096 Aug 5 06:13 ..
root#63d417de7f31:/var/www/html# exit
What should I do?
Update 1
When I trim the Dockerfile to just the base image like this,
FROM wordpress:6.0.1-apache
the wordpress files are copied into /var/www/html.
% docker compose exec wordpress bash
root#f9ad22323268:/var/www/html# ls
index.php wp-admin wp-config-sample.php wp-includes wp-mail.php xmlrpc.php
license.txt wp-blog-header.php wp-config.php wp-links-opml.php wp-settings.php
readme.html wp-comments-post.php wp-content wp-load.php wp-signup.php
wp-activate.php wp-config-docker.php wp-cron.php wp-login.php wp-trackback.php
Update 2
I tried using this
FROM wordpress:6.0.1-apache
WORKDIR /var/www/html/blog
This copies the Wordpress installation both in /var/www/html and /var/www/html/blog. This still fits the requirement, however I want to remove the one in /var/www/html/. I tried rewriting to /var/www/html/index.php like below
FROM wordpress:6.0.1-apache
WORKDIR /var/www/html/blog
RUN echo "Hello World!" > /var/www/html/index.php
But it's not rewritten. Seems like it's being rewritten from the entrypoint
https://github.com/docker-library/wordpress/blob/master/docker-entrypoint.sh

Give Apache user access to blog directory. By adding following to Dockerfile
RUN chown -R www-data:www-data /var/www/html/blog

Related

Wordpress can't upload photos to wp-content

Running php on my Ubuntu box
The PHP process runs under my current user account named tiger
Below are the file permissions for the wp-content folder
drwxr-xr-x 15 tiger www-data 4.0K Apr 23 10:16 wp-content
When the Wordpress blog editor tries to upload photos through the Wordpress dashboard, they are presented with below error
Below is the file hierarchy for WordPress showing file permissions.
root-site-directory/ drwxr-xr-x 15 tiger www-data
`-- wp-content drwxr-xr-x 15 tiger www-data
`-- uploads drwxr-xr-x 15 tiger www-data
`-- 2022 drwxr-xr-x 15 tiger www-data
`-- 04 drwxr-xr-x 15 tiger www-data
What am I missing ?

Change file permission not working in wordpress dockerfile

I'm trying to change the user: root to www-data in Dockerfile to build wordpress image. Once I run the dockerfile and go inside the image: the permission is not changed.
This is my Dockerfile:
FROM wordpress:php7.1-apache
COPY . /var/www/html
WORKDIR /var/www/html
RUN chown -R www-data:www-data /var/www/html/
RUN chmod -R 777 /var/www/html
This is the result in the image by running that Dockerfie:
root#081507c3824e:/var/www/html# ls -lh
total 228K
-rw-r--r-- 1 root root 149 Jul 5 05:09 Dockerfile
-rw-r--r-- 1 root root 405 Jul 5 05:09 index.php
-rw-r--r-- 1 root root 20K Jul 5 05:09 license.txt
-rw-r--r-- 1 root root 7.2K Jul 5 05:09 readme.html
drwxr-xr-x 9 root root 4.0K Jul 5 05:15 wp-admin
-rw-r--r-- 1 root root 351 Jul 5 05:09 wp-blog-header.php
/var/www/html is marked a VOLUME in Dockerfile of wordpress. Your RUN instruction won't persist after the build.
You can try any of the following approaches if you want to change the permisions of /var/www/html/ directory.
You can mount a directory with modified permissions from host machine into the container.
You can create an entrypoint script which changes the permission of the directory before starting the main process.

Nginx 403 error for single file while others work

I have a simple Flask/Nginx server and 3 files in location /opt/hosting/files:
[adam#localhost]$ namei -om /opt/hosting/files
f: /opt/hosting/files
dr-xr-xr-x root root /
drwxr-xr-x root root opt
drwxr-xr-x root root hosting
drwxr-xr-x nginx nginx files
In the folder files I have 3 files: two images and a bigger zip file:
[adam#localhost]$ ls -lh /opt/hosting/files/
total 424M
-rwx-----x. 1 nginx nginx 19K 03-06 01:29 file1.jpg
-rwx-----x. 1 nginx nginx 18M 03-06 03:34 file2.png
-rwxr-xr-x. 1 nginx nginx 406M 07-07 13:07 file3.zip
I am serving these files and while the first two appear without a problem, I get 403 Forbidden for the zip file both through www and using wget. I think directories permissions are set correctly, since the two other files are fine. Zip file properties are even higher so this shouldn't be an issue as well.
I tried using chown root:root and chown 777 for file and folders and couldn't access the file anyway. After making changes I'm restarting nginx with sudo systemctl restart uwsgi. SELinux shows Enforcing.
What is the problem here?
Got it. Reading a comment by tinesoft here made me check SELinux context of files (yes, I'm running CentOS, forgot to mention that) and it was:
[adam#localhost]$ ls -lZ /opt/hosting/files
-rwx-----x. nginx nginx unconfined_u:object_r:httpd_sys_content_t:s0 file1.jpg
-rwx-----x. nginx nginx unconfined_u:object_r:httpd_sys_content_t:s0 file2.png
-rwxr-xr-x. nginx nginx unconfined_u:object_r:user_home_t:s0 file3.zip
Then, following SELinux documentation from RedHat I managed to change the type of SELinux context from user_home_t to httpd_sys_content_t using
sudo chcon -t httpd_sys_content_t file3.zip
That was it.

Unable to extract tar file - tar: extract not authorized

I am working on Solaris 10 machine. In that i cannot able to untar my file. Logs are given below. Anyone please suggest what may be the issue? I can able to create tar file but unable to untar. :(
bash-3.2# ls -lrth ConfigCheck-120614-KL.out*
-rw-r--r-- 1 root root 144K Jun 12 17:15 ConfigCheck-120614-KL.out
-rwxrwxrwx 1 root root 146K Jun 16 16:49 ConfigCheck-120614-KL.out.tar
bash-3.2# tar xvf ConfigCheck-120614-KL.out.tar
tar: extract not authorized
bash-3.2# tar tvf ConfigCheck-120614-KL.out.tar
-rw-r--r-- 0/0 147377 Jun 12 17:15 2014 ConfigCheck-120614-KL.out
Solaris 11 tar will fail with that error message if you are running as uid 0 but do not have the Media Restore profile set up in the RBAC configuration.
Unless you're trying to restore from backup, you should normally be untarring files as a normal user, not root, to avoid accidentally overwriting critical system files.

403 Error on Stylesheet - Raspberry Pi Webserver

I keep seeing a 403 error for my stylesheet which is hosted on my Rasberry Pi (webserver). I ran ls -al and this is the result:
pi#raspberrypi ~/www $ ls -al
total 16
drwxr-xr-x 2 pi root 4096 Mar 17 20:18 .
drwxr-xr-x 12 root root 4096 Mar 15 16:44 ..
-rw-r--r-- 1 pi root 644 Mar 17 20:18 index.html
-rw------- 1 pi root 329 Mar 17 20:19 stylesheet.css
The index.html data shows up when I point my browser at the ip, but there is no formatting and whenever I try to acess the css file through looking at the source code it keeps telling me theres a 403 error :(
Can anyone help a brother out??
Cheers!
You need proper permissions for the www folder, and that depends on which webserver you are running. For apache on debian the user is www-data, if your webroot is ~/www and you are user pi try these commands
Change owner to apache user recursively
Change Permissions to read for all recursively
chown -R www-data:www-data /home/pi/www
chmod -R 644 /home/pi/www

Resources