Wordpress can't upload photos to wp-content - wordpress

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 ?

Related

Modifying Wordpress official docker image to work on subdirectory

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

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.

Can not see 'web' folder after installing drupal using composer from git project

I have been starting Drupal project with composer using git few times so far and always have 'web' folder in the newly created files structure.
Source of the command: https://github.com/drupal-composer/drupal-project
Need a help why I do not have 'web' folder created after trying to start new Drupal project using composer from git using standard:
composer create-project drupal-composer/drupal-project:8.x-dev my_directory --no-interaction
I was expecting 'web' folder within newly created files with Drupal core files ready to install. They are not.
Files in 'my_directory' after running the above command:
drwxr-xr-x 5 ski ski 4096 Sep 4 12:23 .
drwxrwxrwx 3 root root 4096 Sep 4 12:23 ..
-rw-r--r-- 1 ski ski 2474 Sep 4 12:23 composer.json
drwxr-xr-x 4 ski ski 4096 Sep 4 12:23 drush
-rw-r--r-- 1 ski ski 746 Sep 4 12:23 .env.example
drwxr-xr-x 8 ski ski 4096 Sep 4 12:23 .git
-rw-r--r-- 1 ski ski 466 Sep 4 12:23 .gitignore
-rw-r--r-- 1 ski ski 18046 Sep 4 12:23 LICENSE
-rw-r--r-- 1 ski ski 414 Sep 4 12:23 load.environment.php
-rw-r--r-- 1 ski ski 481 Sep 4 12:23 phpunit.xml.dist
-rw-r--r-- 1 ski ski 6495 Sep 4 12:23 README.md
drwxr-xr-x 3 ski ski 4096 Sep 4 12:23 scripts
-rw-r--r-- 1 ski ski 1644 Sep 4 12:23 .travis.yml
I forgot to install some php dependencies. I also missed composer error messages. After that Drupal installs normally.
You can find all php dependencies here:
https://linuxize.com/post/how-to-install-drupal-on-ubuntu-18-04/
Normally it should work by following https://www.drupal.org/docs/develop/using-composer/using-composer-to-install-drupal-and-manage-dependencies#drupal-composer-drupal-project "To do a modified install:" paragraph.
To do that:
Run composer create-project drupal-composer/drupal-project:8.x-dev my_site_name_dir --no-interaction --no-install
Change directories to my_site_name_dir and edit the composer.json file to suit your needs
Run composer install to download Drupal 8 and all its dependencies.
WEB folder is created with composer install command.
Thanks

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

Which files do control the visibility of your website?

I run the following command at uni to my user account
chmod -R 700 *
Then, I run
chmod -R 755 public_html
My homepage remains to be "Forbidden" when I browse to it.
The permissions of my user account
4 drwx------ 5 Newbie staff 4096 2008-12-19 12:39 Desktop
4 drwx------ 10 Newbie staff 4096 2009-04-16 02:28 Documents
4 drwx------ 4 Newbie staff 4096 2008-11-28 20:48 irclogs
4 -rwx------ 1 Newbie staff 1686 2008-09-10 16:00 kieli
4 drwxr-xr-x 3 Newbie www 4096 2009-04-16 02:14 public_html
4 drwx------ 2 Newbie staff 4096 2008-09-01 08:43 Templates
4 drwx------ 4 Newbie staff 4096 2008-12-21 03:15 tmp
4 drwx------ 7 Newbie staff 4096 2008-09-03 21:39 Windows
4 drwx------ 4 Newbie staff 4096 2008-10-03 16:29 workspace
The permissions of files in public_html
4 -rwxr-xr-x 1 newbie staff 3414 2009-04-15 02:23 index.html
4 -rwxr-xr-x 1 newbie staff 2219 2008-09-16 10:46 index.html~
144 -rwxr-xr-x 1 newbie staff 140120 2009-04-14 22:16 jquery.js
4 -rwxr-xr-x 1 newbie staff 699 2009-04-15 01:05 template.css
Well, your second chmod doesn't seem to be working very well, since your public_html directory is mode 744, not 755.
You'll also need to make it so that your home directory can be "looked through" by the Web server; www user needs execute permission on the directory. chmod o+x . is probably your best bet.
Do you have an index file in the directory?
You would also need to give excute permission to the files in public_html. In the statement you are giving permissions chmod -R 755 public_html, still the permissions given is only 744. So give the execute permissions as well.
I found another bug.
My user folder had the permissions 700.
I changed it to 701.
I can now see my website.
It seems that 701 is required.

Resources