8

I have a docker setup with some websites for localhost. I use Smarty as my template engine and it requires to have a writable templates_c folder. Any idea how I can make this folder writable?

The error is as following:

PHP Fatal error:  Smarty error: unable to write to $compile_dir 
'/var/www/html/sitename.local/httpdocs/templates_c'. 
Be sure $compile_dir is writable by the web server user. in 
/var/www/html/sitename.local/httpdocs/libs/Smarty.class.php on 
line 1093

I know this could be set manually with linux but I am looking for an automatic global solution since I have many websites who have this issue

Also worth mentioning I am using a pretty clean docker-compose.yml

php56:
  build: .
  dockerfile: /etc/docker/dockerfile_php_56
  volumes:
    - ./sites:/var/www/html
    - ./etc/php:/usr/local/etc/php
    - ./etc/apache2/apache2.conf:/etc/apache2/conf-enabled/apache2.conf
    - ./etc/apache2/hosts.conf:/etc/apache2/sites-enabled/hosts.conf
  ports:
    - "80:80"
    - "8080:8080"
  links:
    - mysql


mysql:
  image: mysql
  ports:
    - "3306:3306"
  environment:
    - MYSQL_ROOT_PASSWORD=MY_PASSWORD
    - MYSQL_DATABASE=YOUR_DATABASE_NAME
  volumes: 
    - ./etc/mysql:/docker-entrypoint-initdb.d

With a small dockerfile for basics:

FROM php:5.6-apache

RUN /usr/local/bin/docker-php-ext-install mysqli mysql
RUN    docker-php-ext-configure mysql --with-libdir=lib/x86_64-linux-gnu/ \
    && docker-php-ext-install mysql
RUN a2enmod rewrite

https://github.com/wesleyd85/docker-php7-httpd-apache2-mysql (but then with php 5.6)

Wesley
  • 314
  • 1
  • 4
  • 12
  • Is your Docker daemon is running on a Linux host or some Mac boot2docker/docker-machine kind of setup ? – Armin Braun Mar 03 '16 at 00:29
  • It is working on OSX with docker/docker-machine and docker-compose – Wesley Mar 03 '16 at 00:34
  • Let me guess :), you're running this from a folder that is not in your user's home directory ? If so put the setup in your home directory and you should be good with an 80% chance :) – Armin Braun Mar 03 '16 at 00:35
  • With home do you mean /home in the terminal or the home folder in finder in OSX for example? – Wesley Mar 03 '16 at 00:41
  • The home in finder. Basically the folder you get to when you run `cd ~` :) Just put your setup in some subfolder below that. – Armin Braun Mar 03 '16 at 00:43
  • Yeah unfortunately that is already where everything is running – Wesley Mar 03 '16 at 00:44
  • 1
    Check this out then: http://stackoverflow.com/questions/33575351/docker-machine-on-mac-cannot-see-mounted-volumes-on-docker-host-docker-machine Same problem solved for someone else in there already :) Most likely the `usermod` part of things applied to your php container/image will do the trick, just CTRL+F for usermod :) – Armin Braun Mar 03 '16 at 00:48

1 Answers1

12

I solved the same problem with the solution here: Running docker on Ubuntu: mounted host volume is not writable from container

Just need to add:

RUN chmod a+rwx -R project-dir/smarty.cache.dir

to Dockerfile

Community
  • 1
  • 1
Mork
  • 365
  • 5
  • 18