This commit is contained in:
asandikci 2024-01-06 13:27:14 +03:00
parent 1f9d520f3a
commit ac2df247fa
No known key found for this signature in database
GPG key ID: 25C67A03B5666BC1
4 changed files with 173 additions and 121 deletions

3
.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
build/*
*.tar.gz
*.zip

15
buildzip.sh Executable file
View file

@ -0,0 +1,15 @@
#!/bin/bash
rm -rf build/
mkdir build
cp -r ./* build/
cp -r ../YurdleBackend/* build/
cd build/ || exit
rm data.toml
rm README.md
rm yurdle_server.tar.gz
rm buildzip.sh
rm dockerserver.sh
rm -rf build/
sleep 1
tar czf ../yurdle_server.tar.gz ./*

View file

@ -2,24 +2,31 @@
# PHP + Nginx + SQL, Docker Local Test Server Setup/Management File # PHP + Nginx + SQL, Docker Local Test Server Setup/Management File
# Based on nginx docker because I don't know how to use docker compose .d # Based on nginx docker because I don't know how to use docker compose .d
# NOTE remote installation methods removed, just use for local tests
# TODO Make docker compose file for running components under different dockers # TODO Make docker compose file for running components under different dockers
CONTAINER_PREFIX="YURTDLE" # nginx docker name prefix CONTAINER_PREFIX="YURDLE" # nginx docker name prefix
MOUNT_PATH="/source" # binded mount path in nginx docker MOUNT_PATH="/source" # binded mount path in nginx docker
SCRIPT_NAME="dockerserver.sh" # name of the *this* file SCRIPT_NAME="dockerserver.sh" # name of the *this* file
SCRIPT_DIR="Yurtdle" # containing directory of the *this* file SCRIPT_DIR="Yurdle" # containing directory of the *this* file
DEBUG="FALSE" # debug mode
BUILD_DIR="." # build results of local source code (insert a dot (.) if you do not need to build your application) BUILD_DIR="." # build results of local source code (insert a dot (.) if you do not need to build your application)
DATABASE_TYPE="postgresql" # database type, either mysql or postgresql DATABASE_TYPE="postgresql" # database type, either mysql or postgresql
MAIN_NAME="yurtdle" # main program name MAIN_NAME="yurdle" # main program name
PORT1="8000" # TODO what is the difference between 8000 and 80 PORT1="8000" # TODO what is the difference between 8000 and 80
PORT2="80" PORT2="80"
### REMOTE RELEASE ### WEB_ROOT_DIR="/usr/share/nginx/html/" # public web root dir
LATEST_RELEASE="-" WEB_SERVER_DIR="/usr/share/nginx/server/" # private server root dir
FILE_NAME="$MAIN_NAME-$LATEST_RELEASE.zip" SECRET_SERVER="true" # add secret server to $WEB_ROOT_DIR/../$SECRET_SERVER_FOLDER
DOWNLOAD_LINK=https://git.aliberksandikci.com.tr/ifl/$MAIN_NAME/releases/download/$LATEST_RELEASE/$FILE_NAME SECRET_SERVER_LOCAL_RELATIONAL_PATH="../YurdleBackend" # local path
WEB_ROOT_DIR="/usr/share/nginx/html/" SERVER_BUILD_DIR="." # server build dir
__DB_NAME__="localdb"
__DB_USER__="dbuser"
__DB_PWD__="dbpass"
PHP_VERSION="8.2"
ACTIVE_SERVICES=("nginx" "php$PHP_VERSION-fpm" "postgresql") # services
############################ ############################
############################ ############################
@ -35,18 +42,25 @@ Usage:
COMMANDS: COMMANDS:
${_RED}ini:${_NC} initialize dock command ${_RED}ini:${_NC} initialize dock command
install: install $MAIN_NAME install: install $MAIN_NAME
local: get from local /source/
remote: get from git service
reconf : reconfigure configs reconf : reconfigure configs
debug: change application debug status [ON / OFF]
restart: restart services (nginx, $DATABASE_TYPE, php-fpm) restart: restart services (nginx, $DATABASE_TYPE, php-fpm)
update: update source files with new build on /source/ update: update source files with new build on /source/
status: see current webserver status status: see current webserver status
help: see this help text help: see this help text
root: cd to web root folder root: cd to web root folder
restall: update + reconf + restart + root
BUNDLE COMMANDS: """
complete-restart: update + reconf + restart + root
CONFIG_FILE_CONTENT="""
<?php
class Config
{
const DB_HOST = 'localhost';
const DB_NAME = '$__DB_NAME__';
const DB_USERNAME = '$__DB_USER__';
const DB_PASSWORD = '$__DB_PWD__';
}
""" """
NGINX_CONFIG_FILE=""" NGINX_CONFIG_FILE="""
@ -65,7 +79,7 @@ server {
try_files \$uri \$uri/ index.php; try_files \$uri \$uri/ index.php;
location ~ [^/]\.php(/|\$) { location ~ [^/]\.php(/|\$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)\$; fastcgi_split_path_info ^(.+?\.php)(/.*)\$;
fastcgi_pass unix:/var/run/php/php8.2-fpm-$MAIN_NAME.sock; fastcgi_pass unix:/var/run/php/php$PHP_VERSION-fpm-$MAIN_NAME.sock;
fastcgi_index index.php; fastcgi_index index.php;
include fastcgi_params; include fastcgi_params;
@ -90,7 +104,7 @@ group = $MAIN_NAME
chdir = /usr/share/nginx/html chdir = /usr/share/nginx/html
listen = /var/run/php/php8.2-fpm-$MAIN_NAME.sock listen = /var/run/php/php$PHP_VERSION-fpm-$MAIN_NAME.sock
listen.owner = nginx listen.owner = nginx
listen.group = nginx listen.group = nginx
listen.mode = 0660 listen.mode = 0660
@ -109,29 +123,99 @@ php_admin_value[upload_max_filesize] = 50M
php_admin_value[post_max_size] = 50M php_admin_value[post_max_size] = 50M
""" """
# print command HEAD
_head() {
echo -e "\n\n----------------------------------"
echo -e "${_RED}$1 HEAD${_NC}"
echo -e "----------------------------------"
}
_end() {
echo -e "----------------------------------"
echo -e "${_RED}$1 END${_NC}"
echo -e "----------------------------------\n\n"
}
_exit() { _exit() {
echo
echo
echo -e "${_RED}exiting...${_NC}" echo -e "${_RED}exiting...${_NC}"
exit exit
} }
_status() { _status() {
set +x _head "SYSTEM STATUS"
echo for var in "${ACTIVE_SERVICES[@]}"; do
echo service "$var" status
echo "----------------------------------" done
echo -e "${_RED}SYSTEM STATUS HEAD${_NC}" _end "SYSTEM STATUS"
echo "----------------------------------" }
service nginx status
service mariadb status _restart() {
service php8.2-fpm status _head "SYSTEM RESTART"
echo "----------------------------------" for var in "${ACTIVE_SERVICES[@]}"; do
echo -e "${_RED}SYSTEM STATUS HEAD${_NC}" service "$var" restart
echo "----------------------------------" sleep 2
echo done
echo _end "SYSTEM RESTART"
set -x
_status
}
_reconf() {
_head "RECONFIGURATION"
echo -e "$CONFIG_FILE_CONTENT" >"$WEB_SERVER_DIR/config.php"
echo -e "$NGINX_CONFIG_FILE" >"/etc/nginx/conf.d/default.conf"
echo -e "$PHP_FPM_CONFIG_FILE" >"/etc/php/$PHP_VERSION/fpm/pool.d/$MAIN_NAME.conf"
_end "RECONFIGURATION"
}
_update() {
_head "SOURCE UPDATE"
if [[ $SECRET_SERVER == "true" ]]; then
rsync -a --progress /source/$BUILD_DIR $WEB_ROOT_DIR
rsync -a --progress /server/$SERVER_BUILD_DIR $WEB_SERVER_DIR
else
rsync -a --progress /source/$BUILD_DIR $WEB_ROOT_DIR
fi
_end "SOURCE UPDATE"
}
_update_conf() {
if [[ $3 == "server" ]]; then
sed -i "s/\($1 * = *\).*/\1$2;/" "$WEB_SERVER_FOLDER/config.php"
else
sed -i "s/\($1 * = *\).*/\1$2;/" "$WEB_ROOT_FOLDER/config.php"
fi
}
_refresh_folders() {
rm -rf $WEB_ROOT_DIR
mkdir -p $WEB_ROOT_DIR
rm -rf $WEB_SERVER_DIR
mkdir -p $WEB_SERVER_DIR
}
_setup_database() {
if [[ $DATABASE_TYPE == "mysql" ]]; then
apt install mariadb-server php-mysql -y
service mariadb start
mysql -u root -e "create database $MAIN_NAME"
mysql -u root -e "set password for root@localhost = password('root');"
elif [[ $DATABASE_TYPE == "postgresql" ]]; then
apt install postgresql php-pgsql -y
service postgresql start
su -c "createuser $__DB_USER__;createdb -h localhost -p $__DB_PWD__ -E UTF8 -O $__DB_USER__ $__DB_NAME__;" - postgres
fi
}
_folder_permissions() {
groupadd $MAIN_NAME
useradd -g $MAIN_NAME $MAIN_NAME
cd $WEB_ROOT_DIR || exit
chown $MAIN_NAME:nginx -R .
cd $WEB_SERVER_DIR || exit
chown $MAIN_NAME:nginx -R .
} }
if [[ $# -eq 0 ]]; then if [[ $# -eq 0 ]]; then
@ -148,7 +232,12 @@ if [[ $# -eq 0 ]]; then
docker rm $CONTAINER_PREFIX docker rm $CONTAINER_PREFIX
echo "removed" echo "removed"
if [[ $SECRET_SERVER == "true" ]]; then
docker run -it -d --name "$CONTAINER_PREFIX" --mount type=bind,source=".",target=/source/,readonly --mount type=bind,source="./$SECRET_SERVER_LOCAL_RELATIONAL_PATH",target=/server/,readonly --publish $PORT1:$PORT2 nginx bash
else
docker run -it -d --name "$CONTAINER_PREFIX" --mount type=bind,source=".",target=/source/,readonly --publish $PORT1:$PORT2 nginx bash docker run -it -d --name "$CONTAINER_PREFIX" --mount type=bind,source=".",target=/source/,readonly --publish $PORT1:$PORT2 nginx bash
fi
echo -e "RUN SCRIPT: \`${_RED}bash $MOUNT_PATH/$SCRIPT_NAME docker ini${_NC}\`" echo -e "RUN SCRIPT: \`${_RED}bash $MOUNT_PATH/$SCRIPT_NAME docker ini${_NC}\`"
docker attach $CONTAINER_PREFIX --detach-keys="ctrl-k" docker attach $CONTAINER_PREFIX --detach-keys="ctrl-k"
_exit _exit
@ -163,7 +252,7 @@ elif [[ $1 == "attach" ]]; then
docker attach $CONTAINER_PREFIX --detach-keys="ctrl-k" docker attach $CONTAINER_PREFIX --detach-keys="ctrl-k"
elif [[ $1 == "docker" ]]; then elif [[ $1 == "docker" ]]; then
set -x set +x
if [[ $2 == "ini" ]]; then if [[ $2 == "ini" ]]; then
echo "alias dock=\"bash /source/$SCRIPT_NAME docker\"" >>/root/.bashrc echo "alias dock=\"bash /source/$SCRIPT_NAME docker\"" >>/root/.bashrc
@ -171,103 +260,48 @@ elif [[ $1 == "docker" ]]; then
sleep 1 sleep 1
exec bash exec bash
elif [[ $2 == "debug" ]]; then
case "$3" in
["oO"]["nN"] | ["tT"]["rR"]["uU"]["eE"] | 1) sed -i "s/\(DEBUG_MODE * = *\).*/\1TRUE;/" "$WEB_ROOT_DIR/config.php" ;;
["oO"]["fF"]["fF"] | ["fF"]["aA"]["lL"]["sS"]["eE"] | 0) sed -i "s/\(DEBUG_MODE * = *\).*/\1FALSE;/" "$WEB_ROOT_DIR/config.php" ;;
*) echo -e "$_RED please input ON or OFF $_NC" ;;
esac
elif [[ $2 == "restart" ]]; then elif [[ $2 == "restart" ]]; then
service mariadb restart _restart
sleep 3
service php8.2-fpm restart
sleep 3
service nginx restart
_status
elif [[ $2 == "reconf" ]]; then elif [[ $2 == "reconf" ]]; then
_reconf
echo -e "$CONFIG_FILE_CONTENT" >"$WEB_ROOT_DIR/config.php" elif [[ $2 == "restall" ]]; then
echo -e "$NGINX_CONFIG_FILE" >"/etc/nginx/conf.d/default.conf" _update
echo -e "$PHP_FPM_CONFIG_FILE" >"/etc/php/8.2/fpm/pool.d/$MAIN_NAME.conf"
echo RECONFIGURED
echo
_exit
elif [[ $2 == "complete-restart" ]]; then
echo "updating sources!"
rsync -a --progress /source/build/ $WEB_ROOT_DIR --exclude config.php --exclude storage
sleep 1 sleep 1
_reconf
echo -e "$CONFIG_FILE_CONTENT" >"$WEB_ROOT_DIR/config.php" sleep 1
echo -e "$NGINX_CONFIG_FILE" >"/etc/nginx/conf.d/default.conf" _restart
echo -e "$PHP_FPM_CONFIG_FILE" >"/etc/php/8.2/fpm/pool.d/$MAIN_NAME.conf" root
echo RECONFIGURED
echo
service mariadb restart
sleep 3
service php8.2-fpm restart
sleep 3
service nginx restart
_status
elif [[ $2 == "update" ]]; then elif [[ $2 == "update" ]]; then
echo "updating sources!" _update
rsync -a --progress /source/build/ $WEB_ROOT_DIR --exclude config.php --exclude storage
elif [[ $2 == "status" ]]; then elif [[ $2 == "status" ]]; then
_status _status
elif [[ $2 == "install" ]]; then elif [[ $2 == "install" ]]; then
if [[ $# -eq 2 || ! ($3 == "local" || $3 == "remote") ]]; then
echo -e "use $_RED dock install local $NC or $_RED dock install remote"
_exit
fi
sleep 1 sleep 1
set -x
_refresh_folders
apt update apt update
apt install nano exa tree wget unzip less rsync -y apt install nano exa tree wget unzip less rsync -y
rm -rf $WEB_ROOT_DIR
mkdir -p $WEB_ROOT_DIR
cd $WEB_ROOT_DIR || exit cd $WEB_ROOT_DIR || exit
if [[ $3 == "local" ]]; then
cp -r /source/$BUILD_DIR/* $WEB_ROOT_DIR/ cp -r /source/$BUILD_DIR/* $WEB_ROOT_DIR/
elif [[ $3 == "remote" ]]; then if [[ $SECRET_SERVER == "true" ]]; then
wget "$DOWNLOAD_LINK" cp -r /server/$BUILD_DIR/* $WEB_SERVER_DIR/
sleep 3
unzip $FILE_NAME
mv $FILE_NAME ../
else
echo -e "${_RED}use docker local or docker remote${_NC}"
fi fi
### CONFIGURATIONS ### apt install php php-fpm php-cli -y
apt install php php-fpm -y
if [[ $DATABASE_TYPE == "mysql" ]]; then
apt install mariadb-server php-mysql -y
service mariadb start
mysql -u root -e "create database $MAIN_NAME"
mysql -u root -e "set password for root@localhost = password('root');"
elif [[ $DATABASE_TYPE == "postgresql" ]]; then
apt install postgresql php-pgsql -y
fi
echo -e "$CONFIG_FILE_CONTENT" >"$WEB_ROOT_DIR/config.php" _setup_database
echo -e "$NGINX_CONFIG_FILE" >"/etc/nginx/conf.d/default.conf"
echo -e "$PHP_FPM_CONFIG_FILE" >"/etc/php/8.2/fpm/pool.d/$MAIN_NAME.conf"
groupadd $MAIN_NAME
useradd -g $MAIN_NAME $MAIN_NAME
cd $WEB_ROOT_DIR || exit
chown $MAIN_NAME:nginx -R .
chmod 770 storage
service php8.2-fpm start _reconf
service nginx start
service nginx status _folder_permissions
service nginx restart
set +x
_restart
sleep 1
echo -e "${_RED}DONE! - OPEN localhost:$PORT1 TO TEST${_NC}" echo -e "${_RED}DONE! - OPEN localhost:$PORT1 TO TEST${_NC}"
elif [[ $2 == "help" ]]; then elif [[ $2 == "help" ]]; then
echo -e "$HELP!" echo -e "$HELP!"

View file

@ -4,19 +4,19 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="İzmir Fen Lisesi için Yurtdle"> <meta name="description" content="İzmir Fen Lisesi için Yurdle">
<meta name="keywords" content="yurtdle,wordle,ifl,izmirfen"> <meta name="keywords" content="yurdle,wordle,ifl,izmirfen">
<meta name="author" content="Aliberk Sandıı"> <meta name="author" content="Aliberk Sandıı">
<link rel="stylesheet" href="/assets/css/main.css"> <link rel="stylesheet" href="/assets/css/main.css">
<title>Yurtdle | İFL</title> <title>Yurdle | İFL</title>
</head> </head>
<body> <body>
<div class="main-scrollable"> <div class="main-scrollable">
<header class="centered"> <header class="centered">
<h1 class="centered">Yurtdle</h1> <h1 class="centered">Yurdle</h1>
</header> </header>
<article class="sections"> <article class="sections">
@ -25,7 +25,7 @@
<label style="margin-bottom:1vh;" for="mainInput">Yurtlu Öğrencinin İsmini Giriniz</label> <label style="margin-bottom:1vh;" for="mainInput">Yurtlu Öğrencinin İsmini Giriniz</label>
<input class="input" type="text" id="mainInput" name="mainInput" /> <input class="input" type="text" id="mainInput" name="mainInput" />
</form> </form>
<div style="margin-top:10vh;text-align:center;">Veri Sorumlusu: Ömer Arda Muratoğlu.<br>Her türlü kaldırılmasını, eklenmesini ve/veya değiştirilmesi istediğiniz veriler için kendisi ile iletişime geçiniz !</div> <div style="margin-top:auto;text-align:center;">Veri Sorumlusu: Ömer Arda Muratoğlu.<br>Her türlü kaldırılmasını, eklenmesini ve/veya değiştirilmesi istediğiniz veriler için kendisi ile iletişime geçiniz !</div>
</div> </div>
</article> </article>