Skip to content

Commit

Permalink
add php7 version
Browse files Browse the repository at this point in the history
  • Loading branch information
develhopper committed Dec 15, 2021
1 parent ec4a9be commit 17c1b53
Show file tree
Hide file tree
Showing 7 changed files with 253 additions and 5 deletions.
10 changes: 7 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ From alpine:latest

RUN apk update && apk upgrade

RUN apk add mariadb mariadb-client \
RUN apk add mysql \
apache2 \
apache2-utils \
curl wget \
Expand All @@ -29,7 +29,11 @@ RUN apk add mariadb mariadb-client \
php8-simplexml \
php8-mbstring \
php8-xmlwriter \
php8-fileinfo
php8-fileinfo \
php8-xmlreader \
libxml2-dev \
apache2-utils \
apache2-ssl

ENV COMPOSER_HOME /tmp/composer

Expand Down Expand Up @@ -71,4 +75,4 @@ WORKDIR /var/www/localhost/htdocs/
EXPOSE 80
EXPOSE 3306

ENTRYPOINT ["/entry.sh"]
ENTRYPOINT ["/entry.sh"]
4 changes: 2 additions & 2 deletions entry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

ln -s /usr/share/webapps/phpmyadmin/ /var/www/localhost/htdocs/phpmyadmin

cp -r /root/.etc/apache2 /root/.etc/php8 /etc
cp -r /root/.etc/* /etc

# start apache
echo "Starting httpd"
Expand Down Expand Up @@ -57,4 +57,4 @@ echo "Done query"
# start mysql
# nohup mysqld_safe --skip-grant-tables --bind-address 0.0.0.0 --user mysql > /dev/null 2>&1 &
echo "Starting mariadb database"
exec /usr/bin/mysqld --user=root --bind-address=0.0.0.0
exec /usr/bin/mysqld --user=root --bind-address=0.0.0.0
2 changes: 2 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ echo "Installing Lampine"
mkdir -p ~/.local/bin

cp lampine.sh ~/.local/bin/lampine
cp php7/lampine.sh ~/.local/bin/lampine7

cp lampinerc ~/.lampinerc
cp php7/lampinerc ~/.lampinerc7

. ~/.lampinerc

Expand Down
80 changes: 80 additions & 0 deletions php7/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
From alpine:latest

RUN apk update && apk upgrade

RUN apk add mysql \
apache2 \
apache2-utils \
curl wget \
tzdata \
php7-apache2 \
php7-cli \
php7-phar \
php7-zlib \
php7-zip \
php7-bz2 \
php7-ctype \
php7-curl \
php7-pdo_mysql \
php7-mysqli \
php7-json \
php7-xml \
php7-dom \
php7-iconv \
php7-session \
php7-intl \
php7-gd \
php7-opcache \
php7-tokenizer \
php7-simplexml \
php7-mbstring \
php7-xmlwriter \
php7-fileinfo \
php7-xmlreader \
libxml2-dev \
apache2-utils \
apache2-ssl \
php7-sodium \
php7-exif

ENV COMPOSER_HOME /tmp/composer

RUN ln -sf /usr/bin/php7 /usr/bin/php && php -r "readfile('http://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer

RUN mkdir -p /usr/share/webapps/ && cd /usr/share/webapps/ && \
wget https://files.phpmyadmin.net/phpMyAdmin/5.1.1/phpMyAdmin-5.1.1-english.tar.gz > /dev/null 2>&1 && \
tar zxvf phpMyAdmin-5.1.1-english.tar.gz > /dev/null 2>&1 && \
rm phpMyAdmin-5.1.1-english.tar.gz && \
mv phpMyAdmin-5.1.1-english phpmyadmin && \
chmod -R 777 /usr/share/webapps/

RUN mkdir -p /run/mysqld && chown -R mysql:mysql /run/mysqld /var/lib/mysql && \
mkdir -p /run/apache2 && chown -R apache:apache /run/apache2 && chown -R apache:apache /var/www/localhost/htdocs/ && \
sed -i 's#\#LoadModule rewrite_module modules\/mod_rewrite.so#LoadModule rewrite_module modules\/mod_rewrite.so#' /etc/apache2/httpd.conf && \
sed -i 's#ServerName www.example.com:80#\nServerName localhost:80#' /etc/apache2/httpd.conf && \
sed -i 's/skip-networking/\#skip-networking/i' /etc/my.cnf.d/mariadb-server.cnf && \
sed -i '/mariadb\]/a log_error = \/var\/lib\/mysql\/error.log' /etc/my.cnf.d/mariadb-server.cnf && \
sed -i -e"s/^bind-address\s*=\s*127.0.0.1/bind-address = 0.0.0.0/" /etc/my.cnf.d/mariadb-server.cnf && \
sed -i '/mariadb\]/a skip-external-locking' /etc/my.cnf.d/mariadb-server.cnf && \
sed -i '/mariadb\]/a general_log = ON' /etc/my.cnf.d/mariadb-server.cnf && \
sed -i '/mariadb\]/a general_log_file = \/var\/lib\/mysql\/query.log' /etc/my.cnf.d/mariadb-server.cnf

RUN sed -i 's#display_errors = Off#display_errors = On#' /etc/php7/php.ini && \
sed -i 's#upload_max_filesize = 2M#upload_max_filesize = 100M#' /etc/php7/php.ini && \
sed -i 's#post_max_size = 8M#post_max_size = 100M#' /etc/php7/php.ini && \
sed -i 's#session.cookie_httponly =#session.cookie_httponly = true#' /etc/php7/php.ini && \
sed -i 's#error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT#error_reporting = E_ALL#' /etc/php7/php.ini

RUN sed -i '/PS1/c\PS1="\\[\\e[0;32m\\]lampine(\\u) \\e[m: \\[\\e[36m\\][ \\[\\e[m\\]\\w \\[\\e[36m\\]]\\n\\[\\e[0;31m\\]\\$\\->\\[\\e[m\\] "' /etc/profile && \
sed -i "/umask/c\umask 002" /etc/profile && mkdir /root/.etc

COPY entry.sh /entry.sh

RUN chmod u+x /entry.sh

WORKDIR /var/www/localhost/htdocs/

EXPOSE 80
EXPOSE 3306

ENTRYPOINT ["/entry.sh"]
60 changes: 60 additions & 0 deletions php7/entry.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/sh

ln -s /usr/share/webapps/phpmyadmin/ /var/www/localhost/htdocs/phpmyadmin

cp -r /root/.etc/* /etc

# start apache
echo "Starting httpd"
httpd
echo "Done httpd"


# check if mysql data directory is nuked
# if so, install the db
echo "Checking /var/lib/mysql folder"
if [ ! -f /var/lib/mysql/ibdata1 ]; then
echo "Installing db"
mariadb-install-db --user=mysql --ldata=/var/lib/mysql > /dev/null
echo "Installed"
fi;

# from mysql official docker repo
if [ -z "$MYSQL_ROOT_PASSWORD" -a -z "$MYSQL_RANDOM_ROOT_PASSWORD" ]; then
echo >&2 'error: database is uninitialized and password option is not specified '
echo >&2 ' You need to specify one of MYSQL_ROOT_PASSWORD, MYSQL_RANDOM_ROOT_PASSWORD'
exit 1
fi

# random password
if [ ! -z "$MYSQL_RANDOM_ROOT_PASSWORD" ]; then
echo "Using random password"
MYSQL_ROOT_PASSWORD="$(pwgen -1 32)"
echo "GENERATED ROOT PASSWORD: $MYSQL_ROOT_PASSWORD"
echo "Done"
fi

tfile=`mktemp`
if [ ! -f "$tfile" ]; then
return 1
fi

cat << EOF > $tfile
USE mysql;
DELETE FROM user;
FLUSH PRIVILEGES;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY "$MYSQL_ROOT_PASSWORD" WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION;
UPDATE user SET password=PASSWORD("") WHERE user='root' AND host='localhost';
FLUSH PRIVILEGES;
EOF

echo "Querying user"
/usr/bin/mysqld --user=root --bootstrap --verbose=0 < $tfile
rm -f $tfile
echo "Done query"

# start mysql
# nohup mysqld_safe --skip-grant-tables --bind-address 0.0.0.0 --user mysql > /dev/null 2>&1 &
echo "Starting mariadb database"
exec /usr/bin/mysqld --user=root --bind-address=0.0.0.0
87 changes: 87 additions & 0 deletions php7/lampine.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/bin/bash

guide(){
echo -e "Help: \n"
echo -e "lampine (start|stop|config|status|reload|sh|shroot) [local_port:port] \n"
echo -e "ex: lampine start 8000:8000"
echo "ex: lampine start"
}

if [ $# -eq 0 ];then
guide
exit
fi

if [ ! -f ~/.lampinerc7 ];then
echo "~/.lampinerc not found please reinstall"
exit
fi


. ~/.lampinerc7

if [ ! -d $document_root ]
then
mkdir -p $document_root
fi

if [ ! -d $data_dir ]
then
mkdir -p $data_dir
fi

if [ ! -d $apache_conf ]
then
mkdir -p $apache_conf
fi

if [ ! -d $composer_home ]
then
mkdir -p $composer_home
fi

if [ "$1" == "start" ];then
append=""
if [[ $# -eq 2 ]] && [[ "$2" =~ ^[0-9]+\:[0-9]+$ ]];then
append=" -p $2"
fi
echo -e "Starting ... \n"
echo "Document root: $document_root"
echo "Mysql data directory: $data_dir"
echo "Mysql password: $mysql_password"
echo "Apache config dir: $apache_conf"
echo "Composer home: $composer_home"
echo "Apache local port: $apache_port"
echo -e "Mysql local port: $mysql_port \n"
docker run -d --rm -v $document_root:/var/www/localhost/htdocs/ \
-v $etc_dir:/root/.etc -v $data_dir:/var/lib/mysql -v $composer_home:/tmp/composer \
-e MYSQL_ROOT_PASSWORD=$mysql_password -p $apache_port:80 -p $mysql_port:3306 $append \
--name lampine7 develhopper/lampine7:latest 2>/dev/null

if [ $? -eq 125 ];then
echo -e "somthing is wrong. please make sure docker service is running\nor maybe container is already running"
fi

elif [ "$1" == "stop" ];then
echo "Stoping server ..."
docker stop lampine7 >/dev/null 2>&1

elif [ "$1" == "config" ];then
vi ~/.lampinerc
elif [ "$1" == "status" ];then
docker stats lampine7 --no-stream 2>/dev/null
if [ $? -ne 0 ];then
echo "server is not running"
fi
elif [ "$1" == "sh" ];then
docker exec -it --user $UID:$UID lampine7 ash -l
elif [ "$1" == "shroot" ];then
docker exec -it lampine7 ash -l
elif [ "$1" == "reload" ];then
docker exec lampine7 cp -r /root/.etc/* /etc/
docker exec lampine7 pkill httpd
docker exec lampine7 httpd
echo -e "\nApache Reloaded \n"
else
guide
fi
15 changes: 15 additions & 0 deletions php7/lampinerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
document_root=~/work/www

data_dir=~/.local/share/lampine/mysql_data

etc_dir=~/.local/share/lampine/etc7

php_config=~/.local/share/lampine/etc/php7

mysql_password=password

composer_home=~/.composer

apache_port=80

mysql_port=3306

0 comments on commit 17c1b53

Please sign in to comment.