#!/bin/bash # Nginx Docker Localtest CONT_NAME="IFLRANDEVU_NGINX_LOCALTEST" # nginx docker name MOUNT_PATH="/source" # binded mount path in nginx docker SCRIPT_NAME="nginx_docker_localtest.sh" # name of the *this* file ### REMOTE RELEASE ### LATEST_RELEASE="1.4.3-ifl.2" FILE_NAME="iflrandevu-$LATEST_RELEASE.zip" DOWNLOAD_LINK=https://git.aliberksandikci.com.tr/ifl/iflrandevu/releases/download/$LATEST_RELEASE/$FILE_NAME CONFIG_FILE_CONTENT=""" * @copyright Copyleft 2023 - 2024 * @license http://opensource.org/licenses/GPL-3.0 - GPLv3 * @link https://iflpanel.com/about/iflrandevu * @since v1.4.3 * ---------------------------------------------------------------------------- */ /** * IFLRandevu Configuration File */ class Config { // ------------------------------------------------------------------------ // GENERAL SETTINGS // ------------------------------------------------------------------------ const BASE_URL = 'http://localhost:8000'; const LANGUAGE = 'turkish'; const DEBUG_MODE = FALSE; // ------------------------------------------------------------------------ // DATABASE SETTINGS // ------------------------------------------------------------------------ const DB_HOST = 'localhost'; const DB_NAME = 'iflrandevu'; const DB_USERNAME = 'root'; const DB_PASSWORD = 'root'; // ------------------------------------------------------------------------ // GOOGLE CALENDAR SYNC // ------------------------------------------------------------------------ const GOOGLE_SYNC_FEATURE = FALSE; // Enter TRUE or FALSE const GOOGLE_PRODUCT_NAME = ''; const GOOGLE_CLIENT_ID = ''; const GOOGLE_CLIENT_SECRET = ''; const GOOGLE_API_KEY = ''; } /* End of file config.php */ /* Location: ./config.php */ """ OLD_CONFIG=""" server { listen 80; server_name localhost:8000; root /usr/share/nginx/html; access_log /var/log/nginx/example.journaldev.com-access.log; error_log /var/log/nginx/example.journaldev.com-error.log error; index index.php; location / { try_files \$uri \$uri/ /index.php\$is_args\$args; } location ~ \.php\$ { fastcgi_split_path_info ^(.+\.php)(/.+)\$; fastcgi_pass unix:/var/run/php/php8.2-fpm-iflrandevu.sock; fastcgi_index index.php; include fastcgi_params; } } """ NGINX_CONFIG_FILE=""" server { listen 80; server_name localhost:8000; location / { alias /usr/share/nginx/html/; #root /usr/share/nginx/html/; index index.php; # Common parameter to increase upload size limit in conjunction with dedicated php-fpm file client_max_body_size 50M; try_files \$uri \$uri/ index.php; location ~ [^/]\.php(/|\$) { fastcgi_split_path_info ^(.+?\.php)(/.*)\$; fastcgi_pass unix:/var/run/php/php8.2-fpm-iflrandevu.sock; fastcgi_index index.php; include fastcgi_params; fastcgi_param REMOTE_USER \$remote_user; fastcgi_param PATH_INFO \$fastcgi_path_info; fastcgi_param SCRIPT_FILENAME \$request_filename; } } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } } """ PHP_FPM_CONFIG_FILE=""" [iflrandevu] user = iflrandevu group = iflrandevu chdir = /usr/share/nginx/html listen = /var/run/php/php8.2-fpm-iflrandevu.sock listen.owner = nginx listen.group = nginx listen.mode = 0660 pm = ondemand pm.max_children = 8 pm.max_requests = 500 request_terminate_timeout = 1d pm.process_idle_timeout = 10s ; Additional php.ini defines, specific to this pool of workers. php_admin_value[upload_max_filesize] = 50M php_admin_value[post_max_size] = 50M """ ############################ ############################ _RED='\033[0;31m' _NC='\033[0m \e[0m' # No Color, No Effect if [[ $1 != "docker" ]]; then if [[ $(pwd) != *iflrandevu ]]; then echo "PLEASE CHANGE DIRECTORY TO \`iflrandevu/\` BEFORE STARTING SCRIPT" exit fi docker stop $CONT_NAME docker rm $CONT_NAME echo "removed" docker run -it -d --name "$CONT_NAME" --mount type=bind,source=".",target=/source/,readonly --publish 8000:80 nginx bash echo -e "RUN SCRIPT: \`${_RED}bash $MOUNT_PATH/$SCRIPT_NAME docker${_NC}\`" docker attach $CONT_NAME --detach-keys="ctrl-k" echo "EXIT" exit elif [[ $1 == "attach" ]]; then docker start $CONT_NAME docker attach $CONT_NAME --detach-keys="ctrl-k" elif [[ $1 == "docker" ]]; then set -x echo "alias dock=\"bash /source/$SCRIPT_NAME docker\"" >>/root/.bashrc eval "$(cat /root/.bashrc | tail -n +10)" if [[ $2 == "restart" ]]; then service mariadb restart service php8.2-fpm restart sleep 1 service nginx restart echo echo echo service nginx status service mariadb status service php8.2-fpm status echo echo echo "exiting..." exit fi if [[ $2 == "reconf" ]]; then echo -e "$CONFIG_FILE_CONTENT" >"/usr/share/nginx/html/config.php" echo -e "$NGINX_CONFIG_FILE" >"/etc/nginx/conf.d/default.conf" echo -e "$PHP_FPM_CONFIG_FILE" >"/etc/php/8.2/fpm/pool.d/iflrandevu.conf" echo RECONFIGURED echo echo "exiting..." exit fi apt update apt install nano exa tree wget unzip less -y cd /usr/share/nginx/html # rm -f "50x.html" rm -f "index.html" if [[ $2 == "local" ]]; then cp -r /source/build/* /usr/share/nginx/html/ elif [[ $2 == "remote" ]]; then wget $DOWNLOAD_LINK unzip $FILE_NAME mv $FILE_NAME ../ else echo -e "${_RED}use docker local or docker remote${_NC}" fi ### CONFIGURATIONS ### apt install php php-fpm -y apt install mariadb-server php-mysql -y service mariadb start mysql -u root -e "create database iflrandevu" mysql -u root -e "set password for root@localhost = password('root');" echo -e "$CONFIG_FILE_CONTENT" >"config.php" echo -e "$NGINX_CONFIG_FILE" >"/etc/nginx/conf.d/default.conf" echo -e "$PHP_FPM_CONFIG_FILE" >"/etc/php/8.2/fpm/pool.d/iflrandevu.conf" groupadd iflrandevu useradd -g iflrandevu iflrandevu cd /usr/share/nginx/html chown iflrandevu:nginx -R . chmod 770 storage service php8.2-fpm start service nginx start service nginx status service nginx restart echo -e "${_RED}DONE! - OPEN localhost:8000 TO TEST${_NC}" fi # TODO Docker compose to run with /docker/build/docker.sh container together