<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Antwane</title>
    <description>The latest articles on Forem by Antwane (@antwaneb).</description>
    <link>https://forem.com/antwaneb</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F377027%2F5c62d5d6-0eab-449c-96ff-ce8ec5961bd7.png</url>
      <title>Forem: Antwane</title>
      <link>https://forem.com/antwaneb</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/antwaneb"/>
    <language>en</language>
    <item>
      <title>Host two different Apache and PHP versions with Docker</title>
      <dc:creator>Antwane</dc:creator>
      <pubDate>Thu, 30 Apr 2020 19:28:35 +0000</pubDate>
      <link>https://forem.com/antwaneb/host-two-different-apache-and-php-versions-with-docker-h4h</link>
      <guid>https://forem.com/antwaneb/host-two-different-apache-and-php-versions-with-docker-h4h</guid>
      <description>&lt;p&gt;For one of my personal projects, I needed to have two different different PHP versions running at the same time of my server. And those two PHP versions needed to run on different apache version because one was incompatible.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Find more articles about programming on &lt;a href="https://www.mindflash.org/"&gt;my personal blog&lt;/a&gt;, including a series of articles for &lt;a href="https://www.mindflash.org/category/coding/learn-programming"&gt;beginner programmers&lt;/a&gt;!&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;To do that you will actually need 3 containers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;1 reverse proxy with Nginx&lt;/li&gt;
&lt;li&gt;1 docker with the first version of Apache &amp;amp; PHP&lt;/li&gt;
&lt;li&gt;1 docker with the second version of Apache &amp;amp; PHP&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The reverse proxy
&lt;/h2&gt;

&lt;p&gt;Here is the docker file for your reverse proxy:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FROM debian:jessie

MAINTAINER Antwane version: 0.1

RUN apt-get update &amp;amp;&amp;amp; \
    apt-get install -y --force-yes \
            nginx \
        nano

EXPOSE 80
EXPOSE 443

ADD ./proxy.conf /etc/nginx/conf.d/proxy.conf

CMD ["nginx"]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;And here is the configuration file for the proxy:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;proxy_redirect          off;
proxy_set_header        Host            $host;
proxy_set_header        X-Real-IP       $remote_addr;
proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size    10m;
client_body_buffer_size 128k;
client_header_buffer_size 64k;
proxy_connect_timeout   90;
proxy_send_timeout      90;
proxy_read_timeout      90;
proxy_buffer_size   16k;
proxy_buffers       32   16k;
proxy_busy_buffers_size 64k;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Here's the command to launch in order to run it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker run -ti -d -p 80:80 -v /home/&amp;lt;your-user&amp;gt;/Docker/images/nginxproxy/virtualhosts:/etc/nginx/sites-enabled --name nginxproxy nginxproxy /bin/bash
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In &lt;code&gt;/home/&amp;lt;your-user&amp;gt;/Docker/images/nginxproxy/virtualhosts&lt;/code&gt;, you should put a file with the configuration of your nginx, that will redirect each website to the correct apache container:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;server {
       listen 80;

       server_name  siteZ.com;
       location / {
            proxy_pass http://apache22php53:80;
       }
}

server {
       listen 80;

       server_name  siteA.com;
       location / {
            proxy_pass http://apache24php56:80;
       }
}
server {
       listen 80;

       server_name  siteB.com;
       location / {
            proxy_pass http://apache24php56:80;
       }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  The first container
&lt;/h2&gt;

&lt;p&gt;For the purpose of the example, I will use Apache 2.2 and PHP 5.3 in the first container:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FROM debian:wheezy

MAINTAINER Antwane version: 0.1

RUN apt-get update

RUN echo "deb http://packages.dotdeb.org squeeze all" &amp;gt; /etc/apt/sources.list.d/dotdeb_squeeze.list
RUN echo "deb-src http://packages.dotdeb.org squeeze all" &amp;gt;&amp;gt; /etc/apt/sources.list.d/dotdeb_squeeze.list
RUN echo "deb http://ftp.debian.org/debian/ squeeze main contrib non-free" &amp;gt;&amp;gt; /etc/apt/sources.list.d/dotdeb_squeeze.list

RUN echo "Package: *php*" &amp;gt; /etc/apt/preferences.d/php53.pref
RUN echo "Pin: release o=packages.dotdeb.org,n=squeeze" &amp;gt;&amp;gt; /etc/apt/preferences.d/php53.pref
RUN echo "Pin-Priority: 989" &amp;gt;&amp;gt; /etc/apt/preferences.d/php53.pref

RUN apt-get update &amp;amp;&amp;amp; \
    apt-get install -y --force-yes \
            apache2 \
        php5 \
        php5-curl \
        php5-gd \
        php5-mysql \
        nano

RUN a2enmod \
            php5 \
        rewrite

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 80
EXPOSE 443

CMD /usr/sbin/apache2ctl -D FOREGROUND
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;I'm launching it using the following script :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker run -ti -d -p 2253:80 -v /home:/home -v /home/&amp;lt;your username&amp;gt;/Docker/images/apache22php53/virtualhosts:/etc/apache2/sites-enabled --name apache22php53 apache22php53 /bin/bash
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;My websites are stored in &lt;code&gt;/home/website.com/www&lt;/code&gt;, and my apache virtualhosts are stored on the host in &lt;code&gt;/home/&amp;lt;your username&amp;gt;/Docker/images/apache22php53/virtualhosts&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  The second container
&lt;/h2&gt;

&lt;p&gt;Here's the dockerfile:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FROM debian:jessie

MAINTAINER Antwane version: 0.1

RUN apt-get update &amp;amp;&amp;amp; \
    apt-get install -y --force-yes \
            apache2 \
        php5 \
        php5-curl \
        php5-gd \
        php5-mysql \
        nano

RUN a2enmod \
            php5 \
        rewrite

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 80
EXPOSE 443

CMD /usr/sbin/apache2ctl -D FOREGROUND
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;And how to run it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker run -ti -d -p 2456:80 -v /home:/home -v /home/&amp;lt;your username&amp;gt;/Docker/images/apache24php56/virtualhosts:/etc/apache2/sites-enabled --name apache24php56 apache24php56 /bin/bash
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;You can now run many different versions of Apache and PHP on the same host using Docker! The interesting point is that you can scale that as much as needed, just by deploying a new Apache container, and adding your new website to your reverse proxy!&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Find more articles about programming on &lt;a href="https://www.mindflash.org/"&gt;my personal blog&lt;/a&gt;, including a series of articles for &lt;a href="https://www.mindflash.org/category/coding/learn-programming"&gt;beginner programmers&lt;/a&gt;!&lt;/em&gt;&lt;/p&gt;

</description>
      <category>docker</category>
      <category>php</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
