Skip to content

Commit d9a2c22

Browse files
committed
php-fpm + nginx
1 parent b4ff98f commit d9a2c22

File tree

11 files changed

+934
-0
lines changed

11 files changed

+934
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM reponame/php:7.2.5-nginx-fpm_buildnumber
2+
3+
LABEL maintainer="Azure App Services Container Images <[email protected]>"
4+
5+
RUN yes | pecl install xdebug \
6+
&& echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/xdebug.ini \
7+
&& echo "xdebug.remote_enable=on" >> /usr/local/etc/php/conf.d/xdebug.ini \
8+
&& echo "xdebug.remote_autostart=off" >> /usr/local/etc/php/conf.d/xdebug.ini \
9+
&& echo "xdebug.profiler_output_dir=/home/LogFiles" >> /usr/local/etc/php/conf.d/xdebug.ini

7.2.5-nginx-fpm-xdebug/Readme.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Enabling XDebug for PHP containers in Azure App Service
2+
3+
To use the xdebug version of the PHP container in Azure App Service, set an appsetting called PHP_ZENDEXTENSIONS with the value xdebug.

7.2.5-nginx-fpm/Dockerfile

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
FROM php:7.2.5-fpm-alpine3.7
2+
LABEL maintainer="Azure App Services Container Images <[email protected]>"
3+
4+
COPY init_container.sh /bin/init_container.sh
5+
COPY hostingstart.html /home/site/wwwroot/hostingstart.html
6+
7+
RUN chmod 755 /bin/init_container.sh && \
8+
# set log directories
9+
chmod 777 /var/log && \
10+
chmod 777 /var/run && \
11+
chmod 777 /var/lock && \
12+
rm -rf /var/www/html && \
13+
rm -rf /var/log/nginx && \
14+
mkdir -p /home/LogFiles && \
15+
ln -s /home/site/wwwroot /var/www/html && \
16+
ln -s /home/LogFiles /var/log/nginx && \
17+
# Install Nginx
18+
apk update && \
19+
apk add nginx && \
20+
# user www-data should already exist
21+
chown -R www-data:www-data /var/lib/nginx && \
22+
chown -R www-data:www-data /var/www/html
23+
24+
# Define mountable directories.
25+
VOLUME ["/etc/nginx/sites-enabled", "/etc/nginx/certs", "/etc/nginx/conf.d", "/var/log/nginx"]
26+
27+
# install libraries and tools we need
28+
# best guesses
29+
RUN apk update && \
30+
apk add --no-cache openrc \
31+
libpng-dev \
32+
libjpeg-turbo-dev \
33+
postgresql-dev \
34+
libmcrypt-dev \
35+
libmcrypt \
36+
openldap-dev \
37+
ldb-dev \
38+
icu-dev \
39+
gmp-dev \
40+
imagemagick-dev \
41+
imap-dev \
42+
tidyhtml-dev \
43+
krb5-dev \
44+
gettext-dev \
45+
autoconf \
46+
make \
47+
g++ \
48+
libxslt-dev \
49+
unixodbc-dev \
50+
openssh-server \
51+
openssh \
52+
vim \
53+
curl \
54+
wget \
55+
tcptraceroute && \
56+
echo "root:Docker!" | chpasswd && \
57+
echo "cd /home" >> /etc/bash.bashrc && \
58+
pecl install imagick-beta && \
59+
pecl install mcrypt-1.0.1 && \
60+
# install php extensions
61+
docker-php-ext-configure imap --with-kerberos --with-imap-ssl && \
62+
docker-php-ext-configure pdo_odbc --with-pdo-odbc=unixODBC,/usr && \
63+
docker-php-ext-configure gd --with-png-dir=/usr --with-jpeg-dir=/usr && \
64+
docker-php-ext-install gd \
65+
mysqli \
66+
opcache \
67+
pdo \
68+
pdo_mysql \
69+
pdo_pgsql \
70+
pgsql \
71+
ldap \
72+
intl \
73+
gmp \
74+
zip \
75+
bcmath \
76+
mbstring \
77+
pcntl \
78+
calendar \
79+
exif \
80+
gettext \
81+
imap \
82+
tidy \
83+
shmop \
84+
soap \
85+
sockets \
86+
sysvmsg \
87+
sysvsem \
88+
sysvshm \
89+
pdo_odbc \
90+
wddx \
91+
xmlrpc \
92+
xsl && \
93+
docker-php-ext-enable imagick && \
94+
docker-php-ext-enable mcrypt
95+
96+
# install odbc php ext
97+
RUN apk update && \
98+
apk add unixodbc-dev
99+
100+
RUN set -x && \
101+
docker-php-source extract && \
102+
cd /usr/src/php/ext/odbc && \
103+
phpize && \
104+
sed -ri 's@^ *test +"\$PHP_.*" *= *"no" *&& *PHP_.*=yes *$@#&@g' configure && \
105+
./configure --with-unixODBC=shared,/usr && \
106+
docker-php-ext-install odbc
107+
108+
# php settings
109+
RUN { \
110+
echo 'opcache.memory_consumption=128'; \
111+
echo 'opcache.interned_strings_buffer=8'; \
112+
echo 'opcache.max_accelerated_files=4000'; \
113+
echo 'opcache.revalidate_freq=60'; \
114+
echo 'opcache.fast_shutdown=1'; \
115+
echo 'opcache.enable_cli=1'; \
116+
} > /usr/local/etc/php/conf.d/opcache-recommended.ini
117+
118+
RUN { \
119+
echo 'error_log=/var/log/nginx/php-error.log'; \
120+
echo 'display_errors=Off'; \
121+
echo 'log_errors=On'; \
122+
echo 'display_startup_errors=Off'; \
123+
echo 'date.timezone=UTC'; \
124+
} > /usr/local/etc/php/conf.d/php.ini
125+
126+
# openrc settings
127+
# https://github.com/dockage/alpine-openrc/blob/master/Dockerfile
128+
RUN sed -i 's/^\(tty\d\:\:\)/#\1/g' /etc/inittab && \
129+
sed -i \
130+
# Change subsystem type to "docker"
131+
-e 's/#rc_sys=".*"/rc_sys="docker"/g' \
132+
# Allow all variables through
133+
-e 's/#rc_env_allow=".*"/rc_env_allow="\*"/g' \
134+
# Start crashed services
135+
-e 's/#rc_crashed_stop=.*/rc_crashed_stop=NO/g' \
136+
-e 's/#rc_crashed_start=.*/rc_crashed_start=YES/g' \
137+
# Define extra dependencies for services
138+
-e 's/#rc_provide=".*"/rc_provide="loopback net"/g' \
139+
/etc/rc.conf && \
140+
# Remove unnecessary services
141+
rm -f /etc/init.d/hwdrivers \
142+
/etc/init.d/hwclock \
143+
/etc/init.d/hwdrivers \
144+
/etc/init.d/modules \
145+
/etc/init.d/modules-load \
146+
/etc/init.d/modloop && \
147+
# Can't do cgroups
148+
sed -i 's/cgroup_add_service /# cgroup_add_service /g' /lib/rc/sh/openrc-run.sh && \
149+
sed -i 's/VSERVER/DOCKER/Ig' /lib/rc/sh/init.sh
150+
151+
# Expose ports
152+
# http
153+
EXPOSE 8080
154+
# ssh
155+
EXPOSE 2222
156+
157+
COPY www.conf /usr/local/etc/php-fpm.d/www.conf
158+
# replace zz-docker
159+
COPY zz-docker.conf /usr/local/etc/php-fpm.d/zz-docker.conf
160+
COPY nginx.conf /etc/nginx/nginx.conf
161+
COPY sshd_config /etc/ssh/sshd_config
162+
COPY php-fpm.init /etc/init.d/php-fpm
163+
RUN chmod 777 /etc/init.d/php-fpm
164+
165+
ENV PHP_VERSION 7.2.5
166+
ENV WEBSITE_ROLE_INSTANCE_ID localRoleInstance
167+
ENV WEBSITE_INSTANCE_ID localInstance
168+
ENV PATH ${PATH}:/home/site/wwwroot
169+
170+
WORKDIR /home/site/wwwroot
171+
172+
ENTRYPOINT ["/bin/init_container.sh"]

7.2.5-nginx-fpm/hostingstart.html

Lines changed: 38 additions & 0 deletions
Large diffs are not rendered by default.

7.2.5-nginx-fpm/init_container.sh

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/bin/sh
2+
3+
cat >/etc/motd <<EOL
4+
_____
5+
/ _ \ __________ _________ ____
6+
/ /_\ \\___ / | \_ __ \_/ __ \
7+
/ | \/ /| | /| | \/\ ___/
8+
\____|__ /_____ \____/ |__| \___ >
9+
\/ \/ \/
10+
A P P S E R V I C E O N L I N U X
11+
12+
Documentation: http://aka.ms/webapp-linux
13+
PHP quickstart: https://aka.ms/php-qs
14+
15+
EOL
16+
cat /etc/motd
17+
18+
# Get environment variables to show up in SSH session
19+
eval $(printenv | sed -n "s/^\([^=]\+\)=\(.*\)$/export \1=\2/p" | sed 's/"/\\\"/g' | sed '/=/s//="/' | sed 's/$/"/' >> /etc/profile)
20+
21+
# start after openrc
22+
(
23+
sleep 5
24+
echo "Starting SSH ..."
25+
rc-update add sshd
26+
rc-service sshd restart
27+
) &
28+
29+
(
30+
sleep 5
31+
# make the socket
32+
mkdir -p /var/run/php && \
33+
touch /var/run/php/php-fpm.sock && \
34+
chown www-data:www-data /var/run/php/php-fpm.sock && \
35+
chmod 660 /var/run/php/php-fpm.sock
36+
37+
echo "Starting php-fpm ..."
38+
rc-service php-fpm restart
39+
) &
40+
41+
(
42+
sleep 5
43+
echo "Starting Nginx ..."
44+
rc-service nginx restart
45+
) &
46+
47+
# openrc needs to start as PID 1
48+
echo "Starting openrc ..."
49+
exec /sbin/init

7.2.5-nginx-fpm/nginx.conf

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
user www-data;
2+
worker_processes 1;
3+
daemon on;
4+
5+
error_log /dev/stdout warn;
6+
pid /var/run/nginx.pid;
7+
8+
events {
9+
worker_connections 1024;
10+
}
11+
12+
http {
13+
include /etc/nginx/mime.types;
14+
default_type application/octet-stream;
15+
sendfile on;
16+
access_log /dev/stdout;
17+
keepalive_timeout 3000;
18+
server {
19+
listen 8080;
20+
root /var/www/html;
21+
index index.php index.htm index.html hostingstart.html;
22+
server_name localhost;
23+
client_max_body_size 32m;
24+
error_page 500 502 503 504 /50x.html;
25+
location = /50x.html {
26+
root /var/lib/nginx/html;
27+
}
28+
location ~ [^/]\.php(/|$) {
29+
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
30+
if (!-f $document_root$fastcgi_script_name) {
31+
return 404;
32+
}
33+
34+
# Mitigate https://httpoxy.org/ vulnerabilities
35+
fastcgi_param HTTP_PROXY "";
36+
37+
fastcgi_pass unix:/var/run/php/php-fpm.sock;
38+
# fastcgi_pass 127.0.0.1:9000;
39+
fastcgi_index index.php;
40+
41+
# include the fastcgi_param setting
42+
include fastcgi_params;
43+
44+
# SCRIPT_FILENAME parameter is used for PHP FPM determining
45+
# the script name. If it is not set in fastcgi_params file,
46+
# i.e. /etc/nginx/fastcgi_params or in the parent contexts,
47+
# please comment off following line:
48+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
49+
}
50+
}
51+
}

0 commit comments

Comments
 (0)