Sfoglia il codice sorgente

Dynamically determine the wordpress memory limit

If we have 256M (default), then we give it 64M
If we have 512M, then we give it 128M
If we have 1024M, then we give it 256M
and so on.

next_power_of_2(memory_limit_mb/5 apache workers)

note that the default wp memory limit is 32M

part of #23
Girish Ramakrishnan 7 anni fa
parent
commit
4c5a84ac32
3 ha cambiato i file con 12 aggiunte e 5 eliminazioni
  1. 3 0
      Dockerfile
  2. 0 5
      apache2-wordpress.conf
  3. 9 0
      start.sh

+ 3 - 0
Dockerfile

@@ -43,10 +43,13 @@ RUN a2enmod rewrite
 RUN crudini --set /etc/php/7.0/apache2/php.ini PHP upload_max_filesize 500M && \
     crudini --set /etc/php/7.0/apache2/php.ini PHP post_max_size 500M && \
     crudini --set /etc/php/7.0/apache2/php.ini PHP max_input_vars 1800 && \
+    crudini --set /etc/php/7.0/apache2/php.ini PHP memory_limit 64M && \
     crudini --set /etc/php/7.0/apache2/php.ini Session session.save_path /run/wordpress/sessions && \
     crudini --set /etc/php/7.0/apache2/php.ini Session session.gc_probability 1 && \
     crudini --set /etc/php/7.0/apache2/php.ini Session session.gc_divisor 100
 
+RUN mv /etc/php/7.0/apache2/php.ini /etc/php/7.0/apache2/php.ini.orig && ln -sf /run/php.ini /etc/php/7.0/apache2/php.ini
+
 ADD start.sh /app/code/start.sh
 
 CMD [ "/app/code/start.sh" ]

+ 0 - 5
apache2-wordpress.conf

@@ -8,11 +8,6 @@
         Options +FollowSymLinks
         AllowOverride All
         Require all granted
-
-        <IfModule mod_php7.c>
-            php_value memory_limit 64m
-        </IfModule>
-
     </Directory>
 
     # some directories must be protected

+ 9 - 0
start.sh

@@ -26,6 +26,15 @@ sed -e "s/##MYSQL_DATABASE/${MYSQL_DATABASE}/" \
     -e "s/##TABLE_PREFIX/${table_prefix}/" \
     /app/code/wp-config.php.template > /run/wordpress/wp-config.php # sed -i seems to destroy symlink
 
+# Generate php.ini
+memory_limit=$(cat /sys/fs/cgroup/memory/memory.limit_in_bytes) # this is the RAM. we have equal amount of swap
+memory_limit_mb=$((memory_limit*2/1024/1024/5)) # we have 5 apache workers
+php_memory_limit=$(echo ${memory_limit_mb} | awk '{ print 2^(int(log($0)/log(2))+1) }') # next power of 2
+
+echo "Setting PHP memory limit to ${php_memory_limit}M"
+cp /etc/php/7.0/apache2/php.ini.orig /run/php.ini
+crudini --set /run/php.ini PHP memory_limit "${php_memory_limit}M"
+
 # Used for wp rewrite
 touch /app/data/htaccess