Here you can configure the URL to redirect in case the keyword is not found in database.
41 | 45 | HTML; 46 | } 47 | 48 | // Update option in database 49 | function dp_config_update_option() { 50 | $in = $_POST['fallback_url']; 51 | 52 | if( $in ) { 53 | // Validate test_option. ALWAYS validate and sanitize user input. 54 | // Here, we want an string 55 | $in = strval( $in); 56 | 57 | // Update value in database 58 | yourls_update_option( 'fallback_url', $in ); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /conf/opt/yourls/user/config.php: -------------------------------------------------------------------------------- 1 | str_replace('"', '', getenv('YOURLS_ADMIN_PASSWORD')), 67 | // 'username2' => 'password2', 68 | // You can have one or more 'login'=>'password' lines 69 | ]; 70 | 71 | /** URL shortening method: either 36 or 62 72 | ** 36: generates all lowercase keywords (ie: 13jkm) 73 | ** 62: generates mixed case keywords (ie: 13jKm or 13JKm) 74 | ** For more information, see https://yourls.org/urlconvert */ 75 | define( 'YOURLS_URL_CONVERT', getenv('YOURLS_URL_CONVERT') ?: 36 ); 76 | 77 | /** Debug mode to output some internal information 78 | ** Default is false for live site. Enable when coding or before submitting a new issue */ 79 | define( 'YOURLS_DEBUG', getenv('YOURLS_DEBUG') ?: false ); 80 | 81 | /** 82 | * Reserved keywords (so that generated URLs won't match them) 83 | * Define here negative, unwanted or potentially misleading keywords. 84 | */ 85 | $yourls_reserved_URL = [ 86 | 'porn', 'faggot', 'sex', 'nigger', 'fuck', 'cunt', 'dick', 87 | ]; 88 | 89 | /* 90 | ** Personal settings would go after here. 91 | */ 92 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # PHP versions support: 2 | # +--------+ -----------------+----------------------+------------------------+ 3 | # | Branch | Initial Releasae | Active Support Until | Security Support Until | 4 | # +--------+ -----------------+----------------------+------------------------+ 5 | # | 8.1 | Nov 25, 2021 | Nov 25, 2023 | Dec 31, 2025 | 6 | # | 8.2 | Dec 8, 2022 | Dec 31, 2024 | Dec 31, 2026 | 7 | # | 8.3 | Nov 23, 2023 | Dec 31, 2025 | Dec 31, 2027 | 8 | # | 8.4 | Nov 21, 2024 | Dec 31, 2026 | Dec 31, 2028 | 9 | # +--------+ -----------------+----------------------+------------------------+ 10 | # - https://www.php.net/supported-versions.php 11 | # - https://php.watch/versions 12 | # 13 | # Container image source: 14 | # - https://hub.docker.com/_/php/tags?page=1&name=8.3-apache-bookworm 15 | 16 | FROM php:8.3-apache-bookworm AS yourls 17 | 18 | RUN sed -i -e '/^ServerTokens/s/^.*$/ServerTokens Prod/g' \ 19 | -e '/^ServerSignature/s/^.*$/ServerSignature Off/g' \ 20 | /etc/apache2/conf-available/security.conf 21 | 22 | RUN echo "expose_php=Off" > /usr/local/etc/php/conf.d/php-hide-version.ini 23 | 24 | RUN apt update && \ 25 | apt install -y --no-install-recommends libonig-dev && \ 26 | apt install -y tzdata 27 | 28 | RUN docker-php-ext-install pdo_mysql mysqli mbstring && \ 29 | a2enmod rewrite ssl 30 | 31 | ENV YOURLS_VERSION 1.9.2 32 | ENV YOURLS_PACKAGE https://github.com/YOURLS/YOURLS/archive/${YOURLS_VERSION}.tar.gz 33 | ENV YOURLS_CHECKSUM 62a95ba766d62f3305d75944cbfe12d5a90c08c88fbf2f6e67150d36412b916f 34 | 35 | RUN mkdir -p /opt/yourls && \ 36 | curl -sSL ${YOURLS_PACKAGE} -o /tmp/yourls.tar.gz && \ 37 | echo "${YOURLS_CHECKSUM} /tmp/yourls.tar.gz" | sha256sum -c - && \ 38 | tar xf /tmp/yourls.tar.gz --strip-components=1 --directory=/opt/yourls && \ 39 | rm -rf /tmp/yourls.tar.gz 40 | 41 | WORKDIR /opt/yourls 42 | 43 | ADD https://github.com/YOURLS/timezones/archive/master.tar.gz \ 44 | /opt/timezones.tar.gz 45 | ADD https://github.com/dgw/yourls-dont-track-admins/archive/master.tar.gz \ 46 | /opt/dont-track-admins.tar.gz 47 | ADD https://github.com/timcrockford/302-instead/archive/master.tar.gz \ 48 | /opt/302-instead.tar.gz 49 | ADD https://github.com/YOURLS/force-lowercase/archive/master.tar.gz \ 50 | /opt/force-lowercase.tar.gz 51 | ADD https://github.com/guessi/yourls-mobile-detect/archive/refs/tags/3.0.0.tar.gz \ 52 | /opt/mobile-detect.tar.gz 53 | ADD https://github.com/YOURLS/dont-log-bots/archive/master.tar.gz \ 54 | /opt/dont-log-bots.tar.gz 55 | ADD https://github.com/guessi/yourls-dont-log-health-checker/archive/master.tar.gz \ 56 | /opt/dont-log-health-checker.tar.gz 57 | 58 | RUN for i in $(ls /opt/*.tar.gz); do \ 59 | plugin_name="$(basename ${i} '.tar.gz')" ; \ 60 | mkdir -p user/plugins/${plugin_name} ; \ 61 | tar zxvf /opt/${plugin_name}.tar.gz \ 62 | --strip-components=1 \ 63 | -C user/plugins/${plugin_name} ; \ 64 | done 65 | 66 | ADD conf/ / 67 | 68 | # security enhancement: remove sample configs 69 | RUN rm -rf user/config-sample.php \ 70 | user/plugins/sample* && \ 71 | (find . -type d -name ".git" -exec rm -rf {} +) 72 | 73 | FROM yourls AS noadmin 74 | 75 | # security enhancement: leave only production required items 76 | # ** note that it will still available somewhere in docker image layers 77 | RUN rm -rf .git pages admin js css images sample* *.md \ 78 | user/languages \ 79 | user/plugins/random-bg \ 80 | yourls-api.php \ 81 | yourls-infos.php && \ 82 | sed -i '/base64/d' yourls-loader.php && \ 83 | (find . -type f -name "*.html" ! -name "index.html" -delete) && \ 84 | (find . -type f -name "*.json" -o -name "*.md" -o -name "*.css" | xargs rm -f) && \ 85 | (find . -type f -exec file {} + | awk -F: '{if ($2 ~/image/) print $1}' | xargs rm -f) 86 | 87 | FROM yourls AS theme 88 | 89 | # please be awared that "Flynntes/Sleeky" here have no update for years 90 | # you should take your own risk if you choose to have theme included 91 | # - https://github.com/Flynntes/Sleeky/releases 92 | # - https://github.com/Flynntes/Sleeky/issues 93 | 94 | WORKDIR /opt/yourls 95 | 96 | # sample configuration to integrate theme Sleeky-v2.5.0 97 | # - ref: https://github.com/Flynntes/Sleeky#quick-start 98 | ADD https://github.com/Flynntes/Sleeky/archive/refs/tags/v2.5.0.tar.gz \ 99 | /opt/theme-sleeky.tar.gz 100 | 101 | RUN mkdir -p /tmp/sleeky-extracted && \ 102 | tar zxvf /opt/theme-sleeky.tar.gz \ 103 | --strip-components=1 \ 104 | -C /tmp/sleeky-extracted && \ 105 | mv -vf /tmp/sleeky-extracted/sleeky-backend user/plugins/theme-sleeky && \ 106 | mv -vf /tmp/sleeky-extracted/sleeky-frontend . && \ 107 | rm -rvf /tmp/sleeky-extracted 108 | 109 | # NOTE: you will need to activate the theme manually 110 | 111 | # Uncomment the line below to include your own "config.php" setup 112 | # ADD path-to-your-config/config.php /opt/yourls/user/config.php 113 | # 114 | # ref: https://github.com/YOURLS/YOURLS/blob/1.9.2/user/config-sample.php -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Dockerize YOURLS - Your Own URL Shortener 2 | 3 | [](https://hub.docker.com/r/guessi/docker-yourls/) 4 | [](https://hub.docker.com/r/guessi/docker-yourls/) 5 | [](https://hub.docker.com/r/guessi/docker-yourls/) 6 | 7 | ## Before start, things you need to know... 8 | 9 | ### Difference between Official Build and why this project exist? 10 | 11 | Back in 2017, I was a user of YOURLS (_Great thanks to upstream maintainers_). I found it's hard to build YOURLS into container image so I publish my customized YOURLS image build and scripts on [May 7, 2017](https://github.com/guessi/docker-yourls/commit/de4781444ee64edb12abaa3af401b383208817e4). Around half year later, [upstream YOURLS maintainers](https://github.com/YOURLS/YOURLS/graphs/contributors) published an official repo called "[YOURLS/docker](https://github.com/YOURLS/docker)" to build container images for YOURLS project on [Nov 11, 2017](https://github.com/YOURLS/docker/commit/75e37b0cabe62ba4d4691c2d0eb883f4a811c727). So it became two different image repositories. 12 | 13 | ### Should I use it or maybe Official build is better? 14 | 15 | Ideally, official build should receive better support and it is always encourage to try Official Build first. The main differences between two projects is the way image build and w/wo plugins pre-loaded. 16 | 17 | As time goes by, please take this project as a quick start guide for YOURLS and please don't get me wrong, I'm not pushing you away (existed users), if you still like this project? it is always welcome to stay here :-) 18 | 19 | 20 | ## Integrated Items 21 | 22 | * [Yourls](http://yourls.org) - 1.9.2 23 | 24 | | Container image tag | Mobile-Detect version | PHP version | OS version | Remark | 25 | |:-------------------------|:-----------------------|:------------|:-----------|:--------------------------------------------| 26 | | 1.9.2-8 (alias of 1.9.2) | 3.74.3 | PHP 8.3 | Debian 12 | `dont-log-crawlers` removed | 27 | | 1.9.2-7 | 3.74.3 | PHP 8.3 | Debian 12 | Multi-platform support, linux/{amd64,arm64} | 28 | | 1.9.2-6 | 3.74.3 | PHP 8.3 | Debian 12 | deprecated, no code change, regular build | 29 | | 1.9.2-5 | 3.74.3 | PHP 8.3 | Debian 12 | deprecated, no code change, regular build | 30 | | 1.9.2-4 | 3.74.3 | PHP 8.3 | Debian 12 | deprecated, no code change, regular build | 31 | | 1.9.2-3 | 3.74.3 | PHP 8.3 | Debian 12 | deprecated | 32 | | 1.9.2-2 | 2.8.45 | PHP 8.0 | Debian 10 | deprecated | 33 | | 1.9.2-1 | 2.8.41 | PHP 8.0 | Debian 10 | deprecated | 34 | 35 | ## Integrated Plugins 36 | 37 | * [timezones](https://github.com/YOURLS/timezones) 38 | * [302-instead](https://github.com/timcrockford/302-instead) 39 | * [dont-track-admins](https://github.com/dgw/yourls-dont-track-admins) 40 | * [fallback_url_config](http://diegopeinador.com/fallback-url-yourls-plugin) 41 | * [force-lowercase](https://github.com/YOURLS/force-lowercase) 42 | * [mobile-detect](https://github.com/guessi/yourls-mobile-detect) 43 | * [dont-log-bots](https://github.com/YOURLS/dont-log-bots) 44 | * [dont-log-crawler](https://github.com/luixxiul/dont-log-crawlers) - removed after 1.9.2-8 due to project link is dead. 45 | * [dont-log-health-checker](https://github.com/guessi/yourls-dont-log-health-checker) 46 | 47 | 48 | ## Usage 49 | 50 | > [!IMPORTANT] 51 | > You should always change the default username/password pairs for both MySQL and YOURLS. 52 | 53 | To run YOURLS service with customized config 54 | 55 | $ vim env.mysql 56 | $ vim env.yourls 57 | $ docker compose up [--build] [-d] 58 | 59 | 60 | ## Dashboard 61 | 62 | * Default Login Page: http://localhost/admin/ 63 | * Default Username: **see env.yourls** 64 | * Default Password: **see env.yourls** 65 | 66 | 67 | ## Advanced 68 | 69 | ### Create database backup 70 | 71 | Execute `backup.sh` to get regular backup 72 | 73 | 74 | ### Restore backup from backup file 75 | 76 | Make sure there is no container running 77 | 78 | $ docker compose down 79 | $ docker ps 80 | 81 | Cleanup "mysql-data" volume 82 | 83 | $ docker volume rm yourls_mysql-data 84 | 85 | Make sure there is no sql file under "mysql-initdb" volume 86 | 87 | $ rm -vf ./volumes/docker-entrypoint-initdb.d/* 88 | 89 | Move the backup sql file to "mysql-initdb" volume 90 | 91 | $ cp -vf ./mysql-dump-YYYYMMDD-hhmmss.sql ./volumes/docker-entrypoint-initdb.d/ 92 | $ docker compose up -d 93 | 94 | 95 | ## FAQ 96 | 97 | ### Why there would have no homepage for YOURLS? 98 | 99 | Check the answer at the link below 100 | - https://github.com/orgs/YOURLS/discussions/3638#discussioncomment-7192119 101 | 102 | ### How can I use non-default password or variables? 103 | 104 | simply modify the variables inside `env.*` before your first run. 105 | 106 | ### Limitations for environment files 107 | 108 | 1. The value of `YOURLS_DB_PASS` inside `env.yourls` **SHOULD BE** exactly the same as `MYSQL_PASSWORD` in `env.mysql`. 109 | 2. The value of `YOURLS_DB_USER` inside `env.yourls` **SHOULD BE** exactly the same as `MYSQL_USER` in `env.mysql. 110 | 3. All variables inside `env.mysql` and `env.yourls` **SHOULD NOT** contain `'=' (equal sign)`, `' ' (space)`, `'#' (number sign)`. 111 | 112 | ### Why it will show `Could not auto-encrypt passwords.` when log into admin page? 113 | 114 | Check the FAQ for YOURLS for more details 115 | - https://yourls.org/docs/guide/essentials/credentials#faq 116 | 117 | ### Why it will show `Could not write file .htaccess in YOURLS root directory.`? 118 | 119 | It should only happen at 1st time deployment, you may safely ignore it. 120 | 121 | ### Any others? 122 | 123 | Here are some useful links for you 124 | - https://yourls.org/docs 125 | - https://yourls.org/docs/category/troubleshooting 126 | - https://github.com/orgs/YOURLS/discussions 127 | --------------------------------------------------------------------------------