在子目录

时间:2019-07-30 20:14:07

标签: php wordpress docker

我们使用Docker,Docker-compose和Webpack为php站点构建本地环境。最近,我受命使用wordpress将博客添加到本地设置中。我已经能够按照我的预期进行一切操作,但是实时重新加载站点存在一些问题。我一辈子都无法使设置正常工作,以便站点根文件和Blog子目录文件在保存时都可以实时重新加载。我可以要么工作,要么得不到,但不能两者兼得。我们使用webpack中的浏览器同步插件将看到的所有更改重新加载到dist文件夹。

我相信问题来自docker-compose文件中的卷安装。如果我仅安装wordpress wp-content文件:

volumes:
   - ./dist/blog/wp-content/uploads:/var/www/html/blog/wp-content/uploads
   - ./dist/blog/wp-content/plugins:/var/www/html/blog/wp-content/plugins
   - ./dist/blog/wp-content/themes:/var/www/html/blog/wp-content/themes

wordpress博客在保存时会更新,但不在blog /下的任何文件都不会更新。如果我在卷中安装了根文件夹,则将重新加载WordPress文件以外的所有文件。     数量:         -./dist:/var/www/html

当我执行进入Blog文件夹时,它已擦除或覆盖了整个wordpress安装,因此无法再使用WP网站。如果我的所有四行结果相同。我不确定是否有人可以帮助我,但我希望有人以前曾遇到过此问题,我感谢您能提供的任何帮助。我试图包括我的相关文件信息。让我知道是否需要添加更多

dist文件夹结构

dist/
  blog/
    wp-content/
      themes/
        custom-themes/
          .... theme-files
  index.php
  contactus.php
  about.php
  ... etc

dockerfile

FROM php:7.0-apache

# Run Linux apt (Advanced Package Tool) to and install any packages
RUN apt-get update && \
  apt-get install -y --no-install-recommends
RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli
# Enable mod_rewrite in apache modules
RUN a2enmod rewrite

# Manually set up the apache environment variables
ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_LOG_DIR /var/log/apache2
ENV APACHE_LOCK_DIR /var/lock/apache2
ENV APACHE_PID_FILE /var/run/apache2.pid

# Expose apache.
EXPOSE 80

ADD ves-apache-config.conf /etc/apache2/sites-enabled/000-default.conf

WORKDIR /var/www/html/

COPY ./dist /var/www/html/

WORKDIR /var/www/html/blog/

# Set our wordpress environment variables
ENV WORDPRESS_VERSION 5.2.2
ENV WORDPRESS_SHA1 3605bcbe9ea48d714efa59b0eb2d251657e7d5b0

# Download and unpack wordpress
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 /var/www/html/blog; \
  rm wordpress.tar.gz; \
  chown -R www-data:www-data /var/www/html/blog

RUN cp -r /var/www/html/blog/wordpress/. /var/www/html/blog/

RUN rm -rf /var/www/html/blog/wordpress.tar.gz
RUN rm -rf /var/www/html/blog/wordpress

CMD ["apache2-foreground"]

docker-compose.yml

version: "3"
services:
  server:
    # Name our container
    container_name: corporate-site
    environment:
      - COMPOSE_CONVERT_WINDOWS_PATHS=1
    depends_on:
      - database
    build:
      context: ./
    volumes:
      # - ./dist:/var/www/html
      - ./dist/blog/wp-content/uploads:/var/www/html/blog/wp-content/uploads
      - ./dist/blog/wp-content/plugins:/var/www/html/blog/wp-content/plugins
      - ./dist/blog/wp-content/themes:/var/www/html/blog/wp-content/themes
    restart: always
    ports:
      - "8080:80"
    # Logging Control
    logging:
      driver: none
  ### MYSQL DATABASE ###
  database:
    container_name: blog-database
    build:
      context: ./config/docker/database
    volumes:
      - datab:/var/lib/mysql
    restart: always
    ports:
      - "3306:3306"
volumes:
  datab:

Webpack文件

module.exports = merge(base, {
 mode: 'development',
 devtool: 'inline-source-map',
 watch: true,
 plugins: [
  new BrowserSyncPlugin({
   host: 'localhost',
   proxy: 'http://localhost:8080',
   port: 3200,
   open: true,
   files: [
    './dist/*.php',
    './dist/blog/wp-content/themes/blog/*.php',
    './dist/blog/wp-content/themes/blog/*.css'
   ]
  }),
 ]
})

0 个答案:

没有答案