Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Appreciate any guidance on a subdirectory deployment #370

Closed
saedabdu opened this issue Jan 30, 2019 · 6 comments
Closed

Appreciate any guidance on a subdirectory deployment #370

saedabdu opened this issue Jan 30, 2019 · 6 comments
Labels
question Usability question, not directly related to an error with the image

Comments

@saedabdu
Copy link

saedabdu commented Jan 30, 2019

Hello folks,

I'm having a hard time getting my WP deployment to properly work without any broken links trying to have it served under a subdirectory /blog.
I have used info from Codex to have those changes incorporated in the image. but no success so far.
Also in my k8s ingress i have this configuration snippet which handles the rewriting rules as follows,

nginx.ingress.kubernetes.io/configuration-snippet: |
  rewrite /blog/(.*) /$1 break;
  rewrite /wp-admin(.*) /blog/wp-admin$1 break;

I still have those 404 when trying to publish new posts.

Any guidance is extremely appreciated.

@wglambert wglambert added the question Usability question, not directly related to an error with the image label Jan 30, 2019
@tianon
Copy link
Member

tianon commented Jan 30, 2019

See #221 (comment) and #133 (comment). When you create your wordpress container, you'll want to specify a workdir of /var/www/html/blog so that WordPress is aware it is living in a /blog/ subdirectory.

@saedabdu
Copy link
Author

Thanks @tianon for your prompt response, much appreciated.

Indeed i have came across those threads #221 and #133 I made sure I have a WORKDIR in my

  • Dockerfile
FROM php:7.1-apache

# install the PHP extensions we need
RUN set -ex; \
	\
	savedAptMark="$(apt-mark showmanual)"; \
	\
	apt-get update; \
	apt-get install -y --no-install-recommends \
		libjpeg-dev \
		libpng-dev \
	; \
	\
	docker-php-ext-configure gd --with-png-dir=/usr --with-jpeg-dir=/usr; \
	docker-php-ext-install gd mysqli opcache zip; \
	\
# reset apt-mark's "manual" list so that "purge --auto-remove" will remove all build dependencies
	apt-mark auto '.*' > /dev/null; \
	apt-mark manual $savedAptMark; \
	ldd "$(php -r 'echo ini_get("extension_dir");')"/*.so \
		| awk '/=>/ { print $3 }' \
		| sort -u \
		| xargs -r dpkg-query -S \
		| cut -d: -f1 \
		| sort -u \
		| xargs -rt apt-mark manual; \
	\
	apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \
	rm -rf /var/lib/apt/lists/*

# set recommended PHP.ini settings
# see https://secure.php.net/manual/en/opcache.installation.php
RUN { \
		echo 'opcache.memory_consumption=128'; \
		echo 'opcache.interned_strings_buffer=8'; \
		echo 'opcache.max_accelerated_files=4000'; \
		echo 'opcache.revalidate_freq=2'; \
		echo 'opcache.fast_shutdown=1'; \
		echo 'opcache.enable_cli=1'; \
	} > /usr/local/etc/php/conf.d/opcache-recommended.ini

RUN { \
		echo 'upload_max_filesize=10M'; \
		echo 'post_max_size=10M'; \
	} > /usr/local/etc/php/conf.d/upload.ini

RUN a2enmod rewrite expires

VOLUME /var/www/html/blog

ENV WORDPRESS_VERSION 4.9.8

ENV WORDPRESS_SHA1 0945bab959cba127531dceb2c4fed81770812b4f

RUN set -ex; \
	curl -o wordpress.tar.gz -fSL "https://wordpress.org/wordpress-${WORDPRESS_VERSION}.tar.gz"; \
	echo "$WORDPRESS_SHA1 *wordpress.tar.gz" | sha1sum -c -; \
# upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress
	tar -xzf wordpress.tar.gz -C /usr/src/; \
	rm wordpress.tar.gz; \
	chown -R www-data:www-data /usr/src/wordpress

WORKDIR /var/www/html/blog

COPY . /var/www/html/blog/wp-content/themes/writing

RUN chown -R www-data:www-data /var/www/html/blog

COPY docker-entrypoint.sh /usr/local/bin/

RUN chmod +x /usr/local/bin/docker-entrypoint.sh

ENTRYPOINT ["docker-entrypoint.sh"]

CMD ["apache2-foreground"]

  • Volume definition in my k8s deployment
        volumeMounts:
        - name: my-blog-persistent-storage
          mountPath: /var/www/html/blog

This is what i get

Cannot serve directory /var/www/html/: No matching DirectoryIndex (index.php,index.html) found

No modifications made to the docker-entrypoint.sh.

@tianon
Copy link
Member

tianon commented Feb 1, 2019

Not sure why you're duplicating so much of this repo's source, can you elaborate?

I was able to get this to work with the following simplified Dockerfile (which should be pretty easy to extend to include your COPY for the theme you're installing, although that would likely be better to drop into /usr/src/wordpress so that it gets copied appropriately even when /var/www/html is a volume):

FROM wordpress:php7.1-apache
WORKDIR /var/www/html/blog

@tianon
Copy link
Member

tianon commented Feb 1, 2019

(Closing, since this is answered the best we can. 👍)

@earthboundkid
Copy link

My attempt to change the WORKDIR results in the homepage being served but article pages causing error script '/var/www/html/index.php' not found or unable to stat. I think the mod-rewrite is somehow not working.

@loeffel-io
Copy link

loeffel-io commented Feb 23, 2023

can confirm that it's very easy:

pkg_tar(
    name = "wp_content",
    srcs = glob(["wp-content/**"]),
    package_dir = "/usr/src/wordpress",
    strip_prefix = ".",
    visibility = ["//visibility:public"],
)

container_image(
    name = "wordpress_image",
    base = "@wordpress_6_1_apache//image",
    tars = [
        ":wp_content",
    ],
    workdir = "/var/www/html/blog",
    visibility = ["//visibility:public"],
)

siteurl and home needs to be http://localhost/blog in my case

btw: crazy how many trash solutions are out there for this problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Usability question, not directly related to an error with the image
Projects
None yet
Development

No branches or pull requests

5 participants