├── .env ├── .github └── workflows │ └── ci.yml ├── .gitignore ├── LICENSE ├── README.md ├── build.sh ├── config ├── nginx │ ├── cfg │ │ ├── nginx-custom-configs.conf │ │ └── nginx-wp-hardening.conf │ └── tpl │ │ ├── nginx-http.conf.template │ │ └── nginx-https.conf.example └── php.conf.ini ├── data └── certbot │ ├── conf │ └── .placeholder │ └── www │ └── .placeholder ├── docker-compose-build.yml ├── docker-compose-dev.yml ├── docker-compose-prod.yml ├── dump_mysql.sh ├── init_letsencrypt.sh ├── mysql-dumps └── .placeholder ├── push.sh ├── wordpress-sql └── .placeholder ├── wordpress-src └── .placeholder └── wordpress ├── Dockerfile └── adduser.sh /.env: -------------------------------------------------------------------------------- 1 | # env - PROD or DEV 2 | ENV=PROD 3 | 4 | # wordpress 5 | WORDPRESS_IMAGE=wordpress 6 | WORDPRESS_PROD_VERSION=php7.4-fpm 7 | WORDPRESS_DEV_VERSION=php7.4 8 | WORDPRESS_CLI_VERSION=cli-php7.4 9 | WORDPRESS_DB_NAME=wordpress 10 | WORDPRESS_TABLE_PREFIX=wp_ 11 | WORDPRESS_DB_HOST=mysql 12 | WORDPRESS_DB_USER=wordpress 13 | WORDPRESS_DB_PASSWORD=password 14 | 15 | # mariadb 16 | MARIADB_VERSION=latest 17 | MYSQL_ROOT_PASSWORD=s3cretPassW0rd 18 | MYSQL_DATA_DIR=./wordpress-sql 19 | MYSQL_DUMP_DIR=./mysql-dumps 20 | 21 | # nginx - nginx:latest 22 | NGINX_VERSION=latest 23 | SERVER_NAME=example.com 24 | SERVER_ALT_NAME=www.example.com 25 | WP_CONTAINER_NAME=wordpress 26 | SECURE_SUBNET=192.168.0.0/16 27 | 28 | # volumes on host 29 | NGINX_CONF_DIR=./config/nginx/cfg/ 30 | NGINX_TEMPLATE_DIR=./config/nginx/tpl/ 31 | WORDPRESS_DATA_DIR=./wordpress-src 32 | 33 | # build options 34 | WORDPRESS_UID=1000 35 | WORDPRESS_GID=1000 36 | WORDPRESS_USER=app 37 | WORDPRESS_GROUP=app 38 | CUSTOM_WORDPRESS_IMAGE=my-wordpress 39 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: Wordpress CI 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | pull_request: 8 | branches: 9 | - master 10 | 11 | jobs: 12 | 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | 17 | steps: 18 | - uses: actions/checkout@v2 19 | - name: Bringup the environment 20 | run: docker-compose -f docker-compose-dev.yml --env-file .env up -d 21 | - name: Sleep for 30 seconds 22 | uses: jakejarvis/wait-action@master 23 | with: 24 | time: '30s' 25 | - name: List all containers 26 | run: docker ps -a 27 | - name: Setup wordpress 28 | run: docker-compose -f docker-compose-dev.yml run --rm wordpress-cli wp core install --url=http://localhost --title=test --admin_user=admin --admin_email=test@example.com 29 | - name: Testing connection to wordpress 30 | run: docker-compose -f docker-compose-dev.yml exec -T wordpress curl -L --retry 10 --retry-connrefused -I http://localhost -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | data/* 2 | wordpress-sql/* 3 | wordpress-src/* 4 | mysql-dumps/* -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # wordpress-docker 2 | 3 | [![Wordpress CI](https://github.com/garutilorenzo/wordpress-docker/actions/workflows/ci.yml/badge.svg)](https://github.com/garutilorenzo/wordpress-docker/actions/workflows/ci.yml) 4 | [![GitHub issues](https://img.shields.io/github/issues/garutilorenzo/wordpress-docker)](https://github.com/garutilorenzo/wordpress-docker/issues) 5 | ![GitHub](https://img.shields.io/github/license/garutilorenzo/wordpress-docker) 6 | [![GitHub forks](https://img.shields.io/github/forks/garutilorenzo/wordpress-docker)](https://github.com/garutilorenzo/wordpress-docker/network) 7 | [![GitHub stars](https://img.shields.io/github/stars/garutilorenzo/wordpress-docker)](https://github.com/garutilorenzo/wordpress-docker/stargazers) 8 | 9 | # Table of Contents 10 | 11 | * [Requirements](#requirements) 12 | * [Environment setup](#environment-setup) 13 | * [Use the environment](#use-the-environment) 14 | * [Import an existing WP site](#import-an-existing-wp-site) 15 | * [WP Cli](#wp-cli) 16 | * [Fix permission problem](#fix-permission-problem) 17 | * [Nginx](#nginx) 18 | * [SSL](#ssl) 19 | * [Certbot/Let's encrypt](#certbotlets-encrypt) 20 | * [Owned SSL certificates](#owned-ssl-certificates) 21 | * [PhpMyAdmin](#phpmyadmin) 22 | * [MySQL dump](#mysql-dump) 23 | 24 | ### Requirements 25 | 26 | To use this environment you need [Docker](https://docs.docker.com/get-docker/) an [Docker compose](https://docs.docker.com/compose/install/) installed. 27 | 28 | ### Environment setup 29 | 30 | You can find all the settings in the *.env* file in the root folder of this repository. The default settings are: 31 | 32 | | Label | Required | Default | Description | 33 | | ------- | -------- | ------- | ----------- | 34 | | `ENV` | `yes` | `PROD` | Valid values are: PROD or DEV. Changing this varialbe the environment will use a different WP image. In DEV environment is used the docker image with embadded Apache, in prod env is used the php-fpm docker image | 35 | | `WORDPRESS_IMAGE` | `yes` | `wordpress` | The [default](https://hub.docker.com/_/wordpress) docker image to use. | 36 | | `WORDPRESS_PROD_VERSION` | `yes` | `php7.4-fpm` | Production docker image version (php-fpm)| 37 | | `WORDPRESS_DEV_VERSION` | `yes` | `php7.4` | Development docker image version (embadded apache) | 38 | | `WORDPRESS_CLI_VERSION` | `yes` | `cli-php7.4` | WP client docker image version | 39 | | `WORDPRESS_DB_NAME` | `no` | `wordpress` | WP database name | 40 | | `WORDPRESS_TABLE_PREFIX` | `no` | `wp_` | WP mysql table prefix | 41 | | `WORDPRESS_DB_HOST` | `no` | `myslq` | MySQL container name | 42 | | `WORDPRESS_DB_USER` | `no` | `wordpress` | MySQL WP user | 43 | | `WORDPRESS_DB_PASSWORD` | `no` | `password` | MySQL WP user | 44 | | `MARIADB_VERSION` | `no` | `latest` | MariaDB container version | 45 | | `MYSQL_ROOT_PASSWORD` | `no` | `s3cretPassW0rd` | Development docker image version (embadded apache) | 46 | | `MYSQL_DATA_DIR` | `no` | `./wordpress-sql` | Local path for MySQL backup/restore | 47 | | `MYSQL_DUMP_DIR` | `no` | `./mysql-dumps` | Local where dump_mysql.sh store the MySQL dumps | 48 | | `NGINX_VERSION` | `no` | `latest` | Nginx container version | 49 | | `SERVER_NAME` | `yes` | `example.com` | Second level domain name (Example: example.com) | 50 | | `SERVER_ALT_NAME` | `yes` | `www.example.com` | Third level domain name (Example: www.example.com) | 51 | | `WP_CONTAINER_NAME` | `yes` | `wordpress` | WP container name (defined in docker-compose.yml) | 52 | | `SECURE_SUBNET` | `no` | `192.168.0.0/16` | Secure subnet to allow traffic to wp-admin, wp-login.php and xmlrpc.php | 53 | | `NGINX_CONF_DIR` | `no` | `./config/nginx/cfg/` | Nginx custom configuration path | 54 | | `NGINX_TEMPLATE_DIR` | `no` | `./config/nginx/tpl/` | Nginx template configuration path | 55 | | `WORDPRESS_UID` | `no` | `1000` | UID of the user running docker | 56 | | `WORDPRESS_GID` | `no` | `1000` | GID of the user running docker | 57 | | `WORDPRESS_USER` | `no` | `app` | Username used inside the WP docer container | 58 | | `WORDPRESS_GROUP` | `no` | `app` | Group assigned to WORDPRESS_USER | 59 | | `CUSTOM_WORDPRESS_IMAGE` | `no` | `my-wordpress` | WP custom docker image name | 60 | 61 | ### Use the environment 62 | 63 | #### Development 64 | 65 | If you would like to use this environment for local test or if you are developing a new plugin or theme you have to use the develompment version. To use this version create a symlink from docker-compose-dev.yml to docker-compose.yml 66 | 67 | ``` 68 | ln -s docker-compose-dev.yml docker-compose.yml 69 | ``` 70 | 71 | and change in the .env file the ENV value to DEV: 72 | 73 | ``` 74 | ENV=DEV 75 | ``` 76 | 77 | you can now start the environment with: 78 | 79 | ``` 80 | docker compose up -d 81 | ``` 82 | 83 | you can check the logs with: 84 | 85 | ``` 86 | docker compose logs -f 87 | ``` 88 | 89 | Now you have: 90 | 91 | * wordpress listening on port 80 (with embadded Apache). Access your wordpress on http://localhost 92 | * PhpMyAdmin listening on port 8080. Access PMA on http://localhost:8080 (see PhpMyAdmin section) 93 | * MySQL running but is not listening on any interface 94 | * Wordpress CLI container available (see WP Cli section) 95 | 96 | If you are developing a new theme or plugin is possible that you're facing a permission problem, if you check the files permission under wordpress-src you see that the files are owned by www-data: 97 | 98 | ``` 99 | drwxr-xr-x 5 www-data www-data 4096 Oct 12 15:34 wordpress-src 100 | ``` 101 | 102 | To fix this issue see the "Fix permission problem" section 103 | 104 | #### Production 105 | 106 | If you are ready to spin up a production environment simply create a symlink from docker-compose-prod.yml to docker-compose.yml: 107 | 108 | ``` 109 | ln -s docker-compose-prod.yml docker-compose.yml 110 | ``` 111 | 112 | and check in the .env file that the ENV variable is set to PROD: 113 | 114 | ``` 115 | ENV=PROD 116 | ``` 117 | 118 | On production environment you have to configure also nginx. To do so, check the environment variables attached to the nginx container. 119 | 120 | The environment variables are: 121 | 122 | * SERVER_NAME: Second level domain name (Example: example.com) 123 | * SERVER_ALT_NAME: Third level domain name (Example: www.example.com) 124 | * WP_CONTAINER_NAME: WP container name (defined in docker-compose.yml) 125 | * SECURE_SUBNET: Secure subnet to allow traffic to wp-admin, wp-login.php and xmlrpc.php (Default 192.168.0.0/16) 126 | 127 | you can now start the environment with: 128 | 129 | ``` 130 | docker compose up -d 131 | ``` 132 | 133 | you can check the logs with: 134 | 135 | ``` 136 | docker compose logs -f 137 | ``` 138 | 139 | Now you have: 140 | 141 | * nginx listening on ports 80 and 443 (optional). (see nignx section) 142 | * wordpress running with php-fpm container 143 | * PhpMyAdmin running, traffic to PhpMyAdmin is filtered by nginx (see PhpMyAdmin section) 144 | * MySQL running but is not listening on any interface 145 | * Wordpress CLI container available (see WP Cli section) 146 | 147 | ### Import an existing WP site 148 | 149 | If you have a running WP site and you want to use this environment you have to extract your existing sources in *wordpress-src* directory and the MySQL dump in *wordpress-sql* directory. 150 | 151 | **NOTE** before spin up the environment, check wordpress-src directory permission. If you have build a [custom image](#fix-permission-problem) remember to: 152 | 153 | ``` 154 | chown -R uid:gid wordpress-src/ 155 | ``` 156 | 157 | if you use the standard wordpress image all files and directory must be owned by user and group (www-data). Your system might be have a different uid and git for the www-data user and group (or you might don't have this user and group), so to fix the permission problem use the uid and gid directly: 158 | 159 | ``` 160 | chown -R 33:33 wordpress-src/ 161 | ``` 162 | 163 | **MySQL NOTE** dump can be in plain text or gzipped. The extension must be *.sql or *.gz 164 | 165 | **MySQL NOTE2** dump will be restored only on the first startup. If you want to restore a new dump you have to: 166 | 167 | * stop mysql container (docker-compose stop mysql) 168 | * remove the mysql volume (docker volume rm wordpress-docker_mysql). **Tip** you can find the volume name with: *docker volume ls.* 169 | * place the new dump in wordpress-sql 170 | * start the container (docker-compose up -d) 171 | 172 | ### WP Cli 173 | 174 | Check the Wordpress Client referenche [here](https://developer.wordpress.org/cli/commands/) 175 | 176 | To use the wordpress CLI use for example: 177 | 178 | ``` 179 | docker-compose run --rm wordpress-cli wp core install --url=http://localhost --title=test --admin_user=admin --admin_email=test@example.com 180 | Creating wordpress-docker_wordpress-cli_run ... done 181 | Admin password: &kWu5@BldBHixvvaim 182 | Warning: Unable to create directory wp-content/uploads/2021/10. Is its parent directory writable by the server? 183 | Success: WordPress installed successfully. 184 | ``` 185 | 186 | ### Fix permission problem 187 | 188 | To fix the permission problem the solution is to build a custom image. This image will then run all the processes inside the container with a user with a user with the same uid and gid of your local computer's user. 189 | 190 | First we need to check our uid and gid (use the *id* command): 191 | 192 | ``` 193 | id 194 | 195 | uid=1000(your-local-user) gid=1000(your-local-group) groups=1000(your-local-group),4(adm),24(cdrom),27(sudo) 196 | ``` 197 | 198 | then in the .env file adjust the variables: 199 | 200 | * WORDPRESS_UID 201 | * WORDPRESS_GID 202 | 203 | with your uid and gid. Now we can build our custom image: 204 | 205 | ``` 206 | bash build.sh 207 | ``` 208 | 209 | this will produce two new images, one for wordpress (my-wordpress:php7.4) and one for the wordpress cli (my-wordpress:cli-php7.4). A sample output will be: 210 | 211 | ``` 212 | Step 4/10 : ARG WORDPRESS_UID 213 | ---> Using cache 214 | ---> 7eb312bf432b 215 | Step 5/10 : ARG WORDPRESS_GID 216 | ---> Using cache 217 | ---> 917ace616147 218 | Step 6/10 : ARG WORDPRESS_USER 219 | ---> Using cache 220 | ---> aad8c3c33e3a 221 | Step 7/10 : ARG WORDPRESS_GROUP 222 | ---> Using cache 223 | ---> 14248a4f8db9 224 | Step 8/10 : COPY ./adduser.sh / 225 | ---> Using cache 226 | ---> 255a4a665ac6 227 | Step 9/10 : RUN /adduser.sh && rm -rf /adduser.sh 228 | ---> Using cache 229 | ---> 8e84c8cce8b2 230 | Step 10/10 : USER ${WORDPRESS_USER} 231 | ---> Using cache 232 | ---> d36fbaf33c9e 233 | Successfully built d36fbaf33c9e 234 | Successfully tagged my-wordpress:cli-php7.4 235 | ``` 236 | 237 | Now to use this new image you have to change the WORDPRESS_IMAGE in the .env file: 238 | 239 | ``` 240 | WORDPRESS_IMAGE=my-wordpress 241 | ``` 242 | 243 | Now stop the environment, fix wordpress-src directory permission and bring up the environment with the new image: 244 | 245 | ``` 246 | docker-compose down 247 | sudo chown -R your-local-user:your-local-group wordpress-src 248 | [sudo] password for your-local-user: 249 | 250 | docker-compose up -d 251 | ``` 252 | 253 | **NOTE** you can change the custom image name by editing the .env file and change the CUSTOM_WORDPRESS_IMAGE variable. 254 | 255 | ### Nginx 256 | 257 | By default Nginx will expose only the http port (port 80). The default configuration is config/nginx/tpl/nginx-http.conf.template. This template will be rendered on every nginx startup. For more information the nignx documentation is available [here](https://hub.docker.com/_/nginx) 258 | 259 | By default this template use many security enhancements, removing access to many WP paths and files. You can find the configurations under: config/nginx/cfg/ 260 | 261 | To disable this security enhancements edit the config/nginx/tpl/nginx-http.conf.template and comment or delete the lines: 262 | 263 | ``` 264 | # Security 265 | include /etc/nginx/custom.conf.d/nginx-custom-configs.conf; 266 | include /etc/nginx/custom.conf.d/nginx-wp-hardening.conf; 267 | ``` 268 | 269 | In the default template the following locations are protected: 270 | 271 | * /pma/ (PhpMyAdmin) 272 | * /xmlrpc.php 273 | * /wp-admin/ 274 | * wp-login.php 275 | 276 | The traffic to this location is filtered by the SECURE_SUBNET environment variable (Default 192.168.0.0/16). Only the client in this subnet will be able to access this locations. 277 | 278 | To disable this filter edit the config/nginx/tpl/nginx-http.conf.template file and comment or delete this lines: 279 | 280 | ``` 281 | allow ${SECURE_SUBNET}; 282 | allow 127.0.0.1; 283 | deny all; 284 | ``` 285 | 286 | ### SSL 287 | 288 | A configuration example is placed on config/nginx/tpl/nginx-https.conf.example to enable SSL rename this file with the .template extension. 289 | 290 | **Note** remember to delete or rename the nginx-http.conf.template 291 | 292 | #### Certbot/Let's encrypt 293 | 294 | Uncomment certbot service in docker-compose.yml 295 | 296 | If you have to create a new SSL certificate, modify init_letsencrypt.sh with your domain(s) name(s) and change the email variable. 297 | Require the new certificate with: 298 | 299 | ```console 300 | bash init_letsencrypt.sh 301 | ``` 302 | 303 | for nginx auto reload, uncomment the *command* on the nginx service. This is necessary for auto reload nginx when certot renew the ssl certificates. 304 | 305 | Now restart nginx and certbot: 306 | 307 | ```console 308 | docker-compose up -d 309 | ``` 310 | 311 | #### Owned SSL certificates 312 | 313 | If you have your own SSL certificate modifiy config/nginx/tpl/nginx-https.conf.example and adjust the nginx volumes in docker-compose.yml. 314 | 315 | **Note** remember to rename config/nginx/tpl/nginx-http.conf.example file with the .template extension. 316 | 317 | You can now start the services with: 318 | 319 | ```console 320 | docker-compose up -d 321 | ``` 322 | 323 | ### PhpMyAdmin 324 | 325 | The default username is root, and the password is the value of MYSQL_ROOT_PASSWORD in the .env file 326 | 327 | #### Development 328 | 329 | You can access phpMyAdmin at http://127.0.0.1:8080 330 | 331 | #### Production 332 | 333 | You can access phpMyAdmin at http://example.com/pma (access filtered by ip) 334 | 335 | 336 | ### MySQL dump 337 | 338 | To dump the current MySQL state you can use the dump.sh file. The dump will be saved in mysql-dumps directory (you can customize the dump directory in the .env file) 339 | 340 | ``` 341 | bash dump_mysql.sh 342 | ls -la mysql-dumps/ 343 | 344 | -rw-rw-r-- 1 lorenzo lorenzo 473 Oct 18 12:21 wordpress.20211018122109.gz 345 | -rw-rw-r-- 1 lorenzo lorenzo 299673 Oct 18 12:22 wordpress.20211018122247.gz 346 | ``` 347 | -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | unset WORDPRESS_UID 4 | unset WORDPRESS_GID 5 | unset WORDPRESS_USER 6 | unset WORDPRESS_GROUP 7 | unset WORDPRESS_VERSION 8 | 9 | env_str=$(cat .env | grep ENV) 10 | env_value=${env_str#*=} 11 | 12 | uid_str=$(cat .env | grep WORDPRESS_UID) 13 | uid_value=${uid_str#*=} 14 | 15 | gid_str=$(cat .env | grep WORDPRESS_GID) 16 | gid_value=${gid_str#*=} 17 | 18 | user_str=$(cat .env | grep WORDPRESS_USER) 19 | user_value=${user_str#*=} 20 | 21 | group_str=$(cat .env | grep WORDPRESS_GROUP) 22 | group_value=${group_str#*=} 23 | 24 | wordpress_version=$(cat .env | grep WORDPRESS_${env_value}_VERSION) 25 | wordpress_value=${wordpress_version#*=} 26 | 27 | echo $uid_value 28 | echo $gid_value 29 | echo $user_value 30 | echo $user_value 31 | echo $wordpress_value 32 | 33 | export WORDPRESS_VERSION=$wordpress_value 34 | export WORDPRESS_UID=$uid_value 35 | export WORDPRESS_GID=$gid_value 36 | export WORDPRESS_USER=$user_value 37 | export WORDPRESS_GROUP=$user_value 38 | 39 | docker-compose -f docker-compose-build.yml build -------------------------------------------------------------------------------- /config/nginx/cfg/nginx-custom-configs.conf: -------------------------------------------------------------------------------- 1 | # Directives to send expires headers and turn off 404 error logging. 2 | location ~* ^.+\.(curl|heic|swf|tiff|rss|atom|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ { 3 | log_not_found off; 4 | expires max; 5 | } 6 | 7 | # Web fonts send expires headers 8 | location ~* \.(?:eot|otf|ttf|woff|woff2)$ { 9 | expires max; 10 | add_header Cache-Control "public"; 11 | } 12 | 13 | # SVGs & MP4 WEBM send expires headers - this rule is set specific to ns site 14 | location ~* \.(?:svg|svgz|mp4|webm)$ { 15 | expires max; 16 | add_header Cache-Control "public"; 17 | } 18 | 19 | # Media: images, icons, video, audio send expires headers. 20 | location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|aac|m4a|mp3|ogg|ogv|webp)$ { 21 | expires 1M; 22 | add_header Cache-Control "public"; 23 | } 24 | 25 | # Cache css & js files 26 | location ~* \.(?:css(\.map)?|js(\.map)?)$ { 27 | add_header "Access-Control-Allow-Origin" "*"; 28 | log_not_found off; 29 | expires 30d; 30 | } 31 | 32 | # CSS and Javascript send expires headers. 33 | location ~* \.(?:css|js)$ { 34 | expires 1y; 35 | add_header Cache-Control "public"; 36 | } 37 | 38 | # HTML send expires headers. 39 | location ~* \.(html)$ { 40 | expires 7d; 41 | add_header Cache-Control "public"; 42 | } 43 | 44 | # Security settings for better privacy 45 | # Deny hidden files 46 | # Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac). 47 | location ~ /\. { 48 | deny all; 49 | } 50 | 51 | # Return 403 forbidden for readme.(txt|html) or license.(txt|html) or example.(txt|html) or other common git repository files 52 | location ~* "/(^$|readme|license|example|README|LEGALNOTICE|INSTALLATION|CHANGELOG)\.(txt|html|md)" { 53 | deny all; 54 | } 55 | 56 | # Deny backup extensions & log files and return 403 forbidden 57 | location ~* "\.(old|orig|original|php#|php~|php_bak|save|swo|aspx?|tpl|sh|bash|bak?|cfg|cgi|dll|exe|git|hg|ini|jsp|log|mdb|out|sql|svn|swp|tar|rdf)$" { 58 | deny all; 59 | } 60 | 61 | # common nginx configuration to block sql injection and other attacks 62 | location ~* "(eval\()" { 63 | deny all; 64 | } 65 | location ~* "(127\.0\.0\.1)" { 66 | deny all; 67 | } 68 | location ~* "([a-z0-9]{2000})" { 69 | deny all; 70 | } 71 | location ~* "(javascript\:)(.*)(\;)" { 72 | deny all; 73 | } 74 | 75 | location ~* "(base64_encode)(.*)(\()" { 76 | deny all; 77 | } 78 | location ~* "(GLOBALS|REQUEST)(=|\[|%)" { 79 | deny all; 80 | } 81 | location ~* "(<|%3C).*script.*(>|%3)" { 82 | deny all; 83 | } 84 | location ~ "(\\|\.\.\.|\.\./|~|`|<|>|\|)" { 85 | deny all; 86 | } 87 | location ~* "(boot\.ini|etc/passwd|self/environ)" { 88 | deny all; 89 | } 90 | location ~* "(thumbs?(_editor|open)?|tim(thumb)?)\.php" { 91 | deny all; 92 | } 93 | location ~* "(\'|\")(.*)(drop|insert|md5|select|union)" { 94 | deny all; 95 | } 96 | location ~* "(https?|ftp|php):/" { 97 | deny all; 98 | } 99 | location ~* "(=\\\'|=\\%27|/\\\'/?)\." { 100 | deny all; 101 | } 102 | location ~ "(\{0\}|\(/\(|\.\.\.|\+\+\+|\\\"\\\")" { 103 | deny all; 104 | } 105 | location ~ "(~|`|<|>|:|;|%|\\|\s|\{|\}|\[|\]|\|)" { 106 | deny all; 107 | } 108 | location ~* "/(=|\$&|_mm|(wp-)?config\.|cgi-|etc/passwd|muieblack)" { 109 | deny all; 110 | } 111 | 112 | location ~* "(&pws=0|_vti_|\(null\)|\{\$itemURL\}|echo(.*)kae|etc/passwd|eval\(|self/environ)" { 113 | deny all; 114 | } 115 | location ~* "/(^$|mobiquo|phpinfo|shell|sqlpatch|thumb|thumb_editor|thumbopen|timthumb|webshell|config|settings|configuration)\.php" { 116 | deny all; 117 | } -------------------------------------------------------------------------------- /config/nginx/cfg/nginx-wp-hardening.conf: -------------------------------------------------------------------------------- 1 | # Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac). 2 | location ~ /\. { 3 | deny all; 4 | } 5 | 6 | # Deny access to any files with a .php extension in the uploads directory 7 | location ~* /uploads/.*\.php$ { 8 | deny all; 9 | } 10 | 11 | # Deny access to any files with a .php extension in the uploads directory for multisite 12 | location ~* /files/.*\.php$ { 13 | deny all; 14 | } 15 | 16 | # Since version 2.5.7, Akismet introduced a new .htaccess file to block direct access to php files 17 | # Ref: http://wordpress.org/extend/plugins/akismet/changelog/ 18 | location ~* /akismet/.*\.php$ { 19 | allow 127.0.0.1; 20 | deny all; 21 | } 22 | 23 | # Restrict direct access to cached content 24 | location /wp-content/cache/ { 25 | deny all; 26 | } 27 | 28 | # hide any backup or SQL dump files 29 | location ~ ^.+\.(sql|bak|php~|php#|php.save|php.swp|php.swo)$ { 30 | deny all; 31 | } 32 | 33 | #Deny access to wp-content folders for suspicious files 34 | location ~* ^/(wp-content)/(.*?)\.(zip|gz|tar|bzip2|7z)\$ { 35 | deny all; 36 | } 37 | 38 | location ~ ^/wp-content/uploads/sucuri { 39 | deny all; 40 | } 41 | 42 | location ~ ^/wp-content/updraft { 43 | deny all; 44 | } 45 | 46 | #Disable execution of scripts other than PHP from your document root 47 | location ~* .(pl|cgi|py|sh|lua|asp)$ { 48 | return 444; 49 | } 50 | 51 | #Disable access to your configuration files and other files that you don’t want to users are able to see 52 | location ~* /(wp-config.php|readme.html|license.txt|nginx.conf) { 53 | deny all; 54 | } 55 | 56 | # Disable wp-config.txt 57 | location = /wp-config.txt { 58 | deny all; 59 | } 60 | 61 | # nginx block wpscann on plugins folder 62 | location ~* ^/wp-content/plugins/.+\.(txt|log|md)$ { 63 | deny all; 64 | error_page 403 =404 / ; 65 | } 66 | 67 | # Deny access to any files with a .php extension in the uploads directory 68 | # Works in sub-directory installs and also in multisite network 69 | # Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban) 70 | location ~* /(?:uploads|files)/.*\.php$ { 71 | deny all; 72 | } 73 | 74 | # Stop scann for the follow files on plugins folder 75 | location ~* ^/wp-content/plugins/.+\.(txt|log|md)$ { 76 | deny all; 77 | error_page 403 =404 / ; 78 | } 79 | 80 | # Stop scann for the follow files on themes folder 81 | location ~* ^/wp-content/themes/.+\.(txt|log|md)$ { 82 | deny all; 83 | error_page 403 =404 / ; 84 | } 85 | 86 | #This module will allow us to pattern match certain key files and inject random text in the files that 87 | # is non-destructive / non-invasive and will most importantly alter the md5sum calculated on such files. All transparent to WPScan. 88 | location ~* ^/(license.txt|wp-includes/(.*)/.+\.(js|css)|wp-admin/(.*)/.+\.(js|css))$ { 89 | sub_filter_types text/css text/javascript text/plain; 90 | sub_filter_once on; 91 | sub_filter ';' '; /* $msec */ '; 92 | } 93 | 94 | #Direct PHP File Access 95 | #If somehow, a hacker successfully sneaks in a PHP file onto your site, 96 | #they’ll be able to run this file by loading file which effectively becomes a backdoor to infiltrate your site. 97 | #We should disable direct access to any PHP files by adding the following rules: 98 | location ~* /(?:uploads|files|wp-content|wp-includes|akismet)/.*.php$ { 99 | deny all; 100 | } 101 | 102 | #Dotfiles 103 | #Similar to PHP file, a dotfile like .htaccess, .user.ini, and .git may contain sensitive information. 104 | #To be on the safer side, it’s better to disable direct access to these files. 105 | location ~ /\.(svn|git)/* { 106 | deny all; 107 | } 108 | 109 | location ~ /\.ht { 110 | deny all; 111 | } 112 | 113 | location ~ /\.user.ini { 114 | deny all; 115 | } 116 | 117 | #WordFence 118 | location ~ \.user\.ini$ { 119 | deny all; 120 | } 121 | 122 | 123 | # WordPress: deny wp-content, wp-includes php files 124 | location ~* ^/(?:wp-content|wp-includes)/.*\.php$ { 125 | deny all; 126 | } 127 | 128 | # WordPress: deny wp-content/uploads nasty stuff 129 | location ~* ^/wp-content/uploads/.*\.(?:s?html?|php|js|swf)$ { 130 | deny all; 131 | } 132 | -------------------------------------------------------------------------------- /config/nginx/tpl/nginx-http.conf.template: -------------------------------------------------------------------------------- 1 | server { 2 | listen 80; 3 | 4 | server_name ${SERVER_NAME} ${SERVER_ALT_NAME}; 5 | root /var/www/html; 6 | index index.html index.php; 7 | 8 | client_max_body_size 20M; 9 | 10 | # Security 11 | include /etc/nginx/custom.conf.d/nginx-custom-configs.conf; 12 | include /etc/nginx/custom.conf.d/nginx-wp-hardening.conf; 13 | 14 | # Prevent Clickjacking 15 | add_header X-Frame-Options "SAMEORIGIN"; 16 | add_header X-Content-Type-Options "nosniff"; 17 | 18 | charset utf-8; 19 | 20 | # Set the custom error pages 21 | error_page 404 /index.php; 22 | error_page 403 /index.php; 23 | 24 | # Logs 25 | error_log /dev/stderr; 26 | access_log /dev/stdout; 27 | 28 | location ^~ /pma/ { 29 | proxy_set_header X-Real-IP $remote_addr; 30 | proxy_set_header X-Forwarded-For $remote_addr; 31 | proxy_set_header Host $host; 32 | proxy_pass http://pma:80/; 33 | 34 | allow ${SECURE_SUBNET}; 35 | allow 127.0.0.1; 36 | deny all; 37 | } 38 | 39 | location ~* /xmlrpc.php$ { 40 | fastcgi_pass ${WP_CONTAINER_NAME}:9000; 41 | include fastcgi_params; 42 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 43 | 44 | allow ${SECURE_SUBNET}; 45 | allow 127.0.0.1; 46 | deny all; 47 | } 48 | 49 | # Remove direct access to the following folders & files 50 | location ~* ^/(?:\.|conf|data/(?:files|personal|logs|plugins|tmp|cache)|plugins/editor.zoho/agent/files) { 51 | deny all; 52 | } 53 | 54 | location ~* /data/public/.*.(ser|htaccess)$ { 55 | deny all; 56 | } 57 | 58 | # Stops the annoying error messages in the logs 59 | location ~* ^/(favicon.ico|robots.txt) { 60 | log_not_found off; 61 | } 62 | 63 | location = /favicon.ico { 64 | expires 1y; 65 | log_not_found off; 66 | access_log off; 67 | } 68 | 69 | location ~ ^/(wp-admin|wp-login.php) { 70 | fastcgi_split_path_info ^(.+\.php)(/.+)$; 71 | fastcgi_pass ${WP_CONTAINER_NAME}:9000; 72 | fastcgi_index index.php; 73 | include fastcgi_params; 74 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 75 | fastcgi_param SCRIPT_NAME $fastcgi_script_name; 76 | 77 | allow ${SECURE_SUBNET}; 78 | allow 127.0.0.1; 79 | deny all; 80 | } 81 | 82 | # Enables PHP 83 | location ~ \.php$ { 84 | fastcgi_split_path_info ^(.+\.php)(/.+)$; 85 | fastcgi_pass ${WP_CONTAINER_NAME}:9000; 86 | fastcgi_index index.php; 87 | include fastcgi_params; 88 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 89 | fastcgi_param SCRIPT_NAME $fastcgi_script_name; 90 | } 91 | 92 | # Enables Caching 93 | location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ { 94 | expires 7d; 95 | add_header Pragma public; 96 | add_header Cache-Control "public, must-revalidate, proxy-revalidate"; 97 | } 98 | 99 | # The rewrite magic 100 | location / { 101 | try_files $uri $uri/ /index.php?$args; 102 | } 103 | } -------------------------------------------------------------------------------- /config/nginx/tpl/nginx-https.conf.example: -------------------------------------------------------------------------------- 1 | server { 2 | listen 80; 3 | server_name ${SERVER_NAME} ${SERVER_ALT_NAME}; 4 | server_tokens off; 5 | 6 | location /.well-known/acme-challenge/ { 7 | root /var/www/certbot; 8 | } 9 | 10 | location / { 11 | return 301 https://$host$request_uri; 12 | } 13 | } 14 | 15 | server { 16 | listen 443 ssl; 17 | 18 | server_name ${SERVER_NAME} ${SERVER_ALT_NAME}; 19 | root /var/www/html; 20 | index index.html index.php; 21 | 22 | client_max_body_size 20M; 23 | 24 | # Security 25 | include /etc/nginx/custom.conf.d/nginx-custom-configs.conf; 26 | include /etc/nginx/custom.conf.d/nginx-wp-hardening.conf; 27 | 28 | # Prevent Clickjacking 29 | add_header X-Frame-Options "SAMEORIGIN"; 30 | add_header X-Content-Type-Options "nosniff"; 31 | 32 | charset utf-8; 33 | 34 | # SSL Settings 35 | ssl_certificate /etc/letsencrypt/live/${SERVER_NAME}/fullchain.pem; 36 | ssl_certificate_key /etc/letsencrypt/live/${SERVER_NAME}/privkey.pem; 37 | include /etc/letsencrypt/options-ssl-nginx.conf; 38 | ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; 39 | 40 | # Set the custom error pages 41 | error_page 404 /index.php; 42 | error_page 403 /index.php; 43 | 44 | # Logs 45 | error_log /dev/stderr; 46 | access_log /dev/stdout; 47 | 48 | location ^~ /pma/ { 49 | proxy_set_header X-Real-IP $remote_addr; 50 | proxy_set_header X-Forwarded-For $remote_addr; 51 | proxy_set_header Host $host; 52 | proxy_pass http://pma:80/; 53 | 54 | allow ${SECURE_SUBNET}; 55 | allow 127.0.0.1; 56 | deny all; 57 | } 58 | 59 | location ~* /xmlrpc.php$ { 60 | fastcgi_pass ${WP_CONTAINER_NAME}:9000; 61 | include fastcgi_params; 62 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 63 | 64 | allow ${SECURE_SUBNET}; 65 | allow 127.0.0.1; 66 | deny all; 67 | } 68 | 69 | # Remove direct access to the following folders & files 70 | location ~* ^/(?:\.|conf|data/(?:files|personal|logs|plugins|tmp|cache)|plugins/editor.zoho/agent/files) { 71 | deny all; 72 | } 73 | 74 | location ~* /data/public/.*.(ser|htaccess)$ { 75 | deny all; 76 | } 77 | 78 | # Stops the annoying error messages in the logs 79 | location ~* ^/(favicon.ico|robots.txt) { 80 | log_not_found off; 81 | } 82 | 83 | location = /favicon.ico { 84 | expires 1y; 85 | log_not_found off; 86 | access_log off; 87 | } 88 | 89 | location ~ ^/(wp-admin|wp-login.php) { 90 | fastcgi_split_path_info ^(.+\.php)(/.+)$; 91 | fastcgi_pass ${WP_CONTAINER_NAME}:9000; 92 | fastcgi_index index.php; 93 | include fastcgi_params; 94 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 95 | fastcgi_param SCRIPT_NAME $fastcgi_script_name; 96 | 97 | allow ${SECURE_SUBNET}; 98 | allow 127.0.0.1; 99 | deny all; 100 | } 101 | 102 | # Enables PHP 103 | location ~ \.php$ { 104 | fastcgi_split_path_info ^(.+\.php)(/.+)$; 105 | fastcgi_pass ${WP_CONTAINER_NAME}:9000; 106 | fastcgi_index index.php; 107 | include fastcgi_params; 108 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 109 | fastcgi_param SCRIPT_NAME $fastcgi_script_name; 110 | } 111 | 112 | # Enables Caching 113 | location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ { 114 | expires 7d; 115 | add_header Pragma public; 116 | add_header Cache-Control "public, must-revalidate, proxy-revalidate"; 117 | } 118 | 119 | # The rewrite magic 120 | location / { 121 | try_files $uri $uri/ /index.php?$args; 122 | } 123 | } -------------------------------------------------------------------------------- /config/php.conf.ini: -------------------------------------------------------------------------------- 1 | file_uploads = On 2 | upload_max_filesize = 20M 3 | post_max_size = 20M -------------------------------------------------------------------------------- /data/certbot/conf/.placeholder: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/garutilorenzo/wordpress-docker/226fa696a1d604abcdbaeb68b11e9e665d220e20/data/certbot/conf/.placeholder -------------------------------------------------------------------------------- /data/certbot/www/.placeholder: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/garutilorenzo/wordpress-docker/226fa696a1d604abcdbaeb68b11e9e665d220e20/data/certbot/www/.placeholder -------------------------------------------------------------------------------- /docker-compose-build.yml: -------------------------------------------------------------------------------- 1 | version: '3.8' 2 | services: 3 | 4 | wordpress: 5 | image: ${CUSTOM_WORDPRESS_IMAGE:-my-wordpress}:${WORDPRESS_VERSION:-latest} 6 | build: 7 | context: wordpress/ 8 | args: 9 | WORDPRESS_VERSION: ${WORDPRESS_VERSION} 10 | WORDPRESS_UID: ${WORDPRESS_UID} 11 | WORDPRESS_GID: ${WORDPRESS_GID} 12 | WORDPRESS_USER: ${WORDPRESS_USER} 13 | WORDPRESS_GROUP: ${WORDPRESS_GROUP} 14 | 15 | wordpress-cli: 16 | image: ${CUSTOM_WORDPRESS_IMAGE:-my-wordpress}:${WORDPRESS_CLI_VERSION:-latest} 17 | build: 18 | context: wordpress/ 19 | args: 20 | WORDPRESS_VERSION: ${WORDPRESS_CLI_VERSION} 21 | WORDPRESS_UID: ${WORDPRESS_UID} 22 | WORDPRESS_GID: ${WORDPRESS_GID} 23 | WORDPRESS_USER: ${WORDPRESS_USER} 24 | WORDPRESS_GROUP: ${WORDPRESS_GROUP} -------------------------------------------------------------------------------- /docker-compose-dev.yml: -------------------------------------------------------------------------------- 1 | version: '3.8' 2 | services: 3 | 4 | wordpress: 5 | image: ${WORDPRESS_IMAGE:-wordpress}:${WORDPRESS_DEV_VERSION:-latest} 6 | container_name: wordpress 7 | volumes: 8 | - type: bind 9 | source: ${WORDPRESS_DATA_DIR:-./wordpress-src} 10 | target: /var/www/html 11 | environment: 12 | WORDPRESS_DB_HOST: ${WORDPRESS_DB_HOST:-mysql} 13 | WORDPRESS_DB_NAME: ${WORDPRESS_DB_NAME:-wordpress} 14 | WORDPRESS_DB_USER: ${WORDPRESS_DB_USER:-wordpress} 15 | WORDPRESS_DB_PASSWORD: ${WORDPRESS_DB_PASSWORD:-W0rdpr3Ss.} 16 | WORDPRESS_TABLE_PREFIX: ${WORDPRESS_TABLE_PREFIX:-wp_} 17 | ports: 18 | - 80:80 19 | depends_on: 20 | - mysql 21 | logging: 22 | driver: "json-file" 23 | options: 24 | max-size: "1m" 25 | max-file: "5" 26 | restart: always 27 | 28 | mysql: 29 | image: mariadb:${MARIADB_VERSION:-latest} 30 | container_name: mysql 31 | volumes: 32 | - type: volume 33 | source: mysql 34 | target: /var/lib/mysql 35 | volume: 36 | nocopy: true 37 | - type: bind 38 | source: ${MYSQL_DATA_DIR:-./wordpress-sql} 39 | target: /docker-entrypoint-initdb.d 40 | read_only: true 41 | environment: 42 | MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-password} 43 | MYSQL_USER: ${WORDPRESS_DB_USER:-wordpress} 44 | MYSQL_PASSWORD: ${WORDPRESS_DB_PASSWORD:-W0rdpr3Ss.} 45 | MYSQL_DATABASE: ${WORDPRESS_DB_NAME:-wordpress} 46 | logging: 47 | driver: "json-file" 48 | options: 49 | max-size: "1m" 50 | max-file: "5" 51 | restart: always 52 | 53 | wordpress-cli: 54 | image: ${WORDPRESS_IMAGE:-wordpress}:${WORDPRESS_CLI_VERSION:-latest} 55 | volumes: 56 | - type: bind 57 | source: ./config/php.conf.ini 58 | target: /usr/local/etc/php/conf.d/conf.ini 59 | read_only: true 60 | - type: bind 61 | source: ${WORDPRESS_DATA_DIR:-./wordpress-src} 62 | target: /var/www/html 63 | environment: 64 | WORDPRESS_DB_HOST: ${WORDPRESS_DB_HOST:-mysql} 65 | WORDPRESS_DB_NAME: ${WORDPRESS_DB_NAME:-wordpress} 66 | WORDPRESS_DB_USER: ${WORDPRESS_DB_USER:-wordpress} 67 | WORDPRESS_DB_PASSWORD: ${WORDPRESS_DB_PASSWORD:-W0rdpr3Ss.} 68 | depends_on: 69 | - mysql 70 | - wordpress 71 | logging: 72 | driver: "json-file" 73 | options: 74 | max-size: "1m" 75 | max-file: "5" 76 | restart: "no" 77 | 78 | pma: 79 | image: phpmyadmin/phpmyadmin 80 | environment: 81 | PMA_HOST: ${WORDPRESS_DB_HOST:-mysql} 82 | PMA_PORT: 3306 83 | MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-password} 84 | ports: 85 | - 8080:80 86 | depends_on: 87 | - mysql 88 | logging: 89 | driver: "json-file" 90 | options: 91 | max-size: "1m" 92 | max-file: "5" 93 | restart: always 94 | 95 | volumes: 96 | mysql: -------------------------------------------------------------------------------- /docker-compose-prod.yml: -------------------------------------------------------------------------------- 1 | version: '3.8' 2 | services: 3 | 4 | wordpress: 5 | image: ${WORDPRESS_IMAGE:-wordpress}:${WORDPRESS_PROD_VERSION:-latest} 6 | container_name: wordpress 7 | volumes: 8 | - type: bind 9 | source: ${WORDPRESS_DATA_DIR:-./wordpress-src} 10 | target: /var/www/html 11 | environment: 12 | WORDPRESS_DB_HOST: ${WORDPRESS_DB_HOST:-mysql} 13 | WORDPRESS_DB_NAME: ${WORDPRESS_DB_NAME:-wordpress} 14 | WORDPRESS_DB_USER: ${WORDPRESS_DB_USER:-wordpress} 15 | WORDPRESS_DB_PASSWORD: ${WORDPRESS_DB_PASSWORD:-W0rdpr3Ss.} 16 | depends_on: 17 | - mysql 18 | logging: 19 | driver: "json-file" 20 | options: 21 | max-size: "1m" 22 | max-file: "5" 23 | restart: always 24 | 25 | mysql: 26 | image: mariadb:${MARIADB_VERSION:-latest} 27 | container_name: mysql 28 | volumes: 29 | - type: volume 30 | source: mysql 31 | target: /var/lib/mysql 32 | volume: 33 | nocopy: true 34 | - type: bind 35 | source: ${MYSQL_DATA_DIR:-./wordpress-sql} 36 | target: /docker-entrypoint-initdb.d 37 | read_only: true 38 | environment: 39 | MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-password} 40 | MYSQL_USER: ${WORDPRESS_DB_USER:-wordpress} 41 | MYSQL_PASSWORD: ${WORDPRESS_DB_PASSWORD:-W0rdpr3Ss.} 42 | MYSQL_DATABASE: ${WORDPRESS_DB_NAME:-wordpress} 43 | logging: 44 | driver: "json-file" 45 | options: 46 | max-size: "1m" 47 | max-file: "5" 48 | restart: always 49 | 50 | wordpress-cli: 51 | image: ${WORDPRESS_IMAGE:-wordpress}:${WORDPRESS_CLI_VERSION:-latest} 52 | volumes: 53 | - type: bind 54 | source: ./config/php.conf.ini 55 | target: /usr/local/etc/php/conf.d/conf.ini 56 | read_only: true 57 | - type: bind 58 | source: ${WORDPRESS_DATA_DIR:-./wordpress-src} 59 | target: /var/www/html 60 | environment: 61 | WORDPRESS_DB_HOST: ${WORDPRESS_DB_HOST:-mysql} 62 | WORDPRESS_DB_NAME: ${WORDPRESS_DB_NAME:-wordpress} 63 | WORDPRESS_DB_USER: ${WORDPRESS_DB_USER:-wordpress} 64 | WORDPRESS_DB_PASSWORD: ${WORDPRESS_DB_PASSWORD:-W0rdpr3Ss.} 65 | WORDPRESS_TABLE_PREFIX: ${WORDPRESS_TABLE_PREFIX:-wp_} 66 | depends_on: 67 | - mysql 68 | - wordpress 69 | logging: 70 | driver: "json-file" 71 | options: 72 | max-size: "1m" 73 | max-file: "5" 74 | restart: "no" 75 | 76 | pma: 77 | image: phpmyadmin/phpmyadmin 78 | environment: 79 | PMA_HOST: ${WORDPRESS_DB_HOST:-mysql} 80 | PMA_PORT: 3306 81 | MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-password} 82 | PMA_ABSOLUTE_URI: http://example.com/pma 83 | depends_on: 84 | - mysql 85 | logging: 86 | driver: "json-file" 87 | options: 88 | max-size: "1m" 89 | max-file: "5" 90 | restart: always 91 | 92 | nginx: 93 | image: nginx:${NGINX_VERSION:-latest} 94 | container_name: nginx 95 | ports: 96 | - '80:80' 97 | - '443:443' 98 | volumes: 99 | - type: bind 100 | source: ${WORDPRESS_DATA_DIR:-./wordpress-src} 101 | target: /var/www/html 102 | - type: bind 103 | source: ${NGINX_CONF_DIR:-./config/nginx/cfg/} 104 | target: /etc/nginx/custom.conf.d 105 | - type: bind 106 | source: ${NGINX_TEMPLATE_DIR:-./config/nginx/tpl/} 107 | target: /etc/nginx/templates/ 108 | # - type: bind 109 | # source: ./data/certbot/conf 110 | # target: /etc/letsencrypt 111 | # - type: bind 112 | # source: ./data/certbot/www 113 | # target: /var/www/certbot 114 | environment: 115 | SERVER_NAME: ${SERVER_NAME:-example.com} 116 | SERVER_ALT_NAME: ${SERVER_ALT_NAME:-www.example.com} 117 | WP_CONTAINER_NAME: ${WP_CONTAINER_NAME:-wordpress} 118 | SECURE_SUBNET: ${SECURE_SUBNET:-192.168.0.0/16} 119 | depends_on: 120 | - wordpress 121 | # command: "/bin/sh -c 'while :; do sleep 6h & wait $${!}; nginx -s reload; done & nginx -g \"daemon off;\"'" #certobt 122 | logging: 123 | driver: "json-file" 124 | options: 125 | max-size: "1m" 126 | max-file: "5" 127 | restart: always 128 | 129 | # certbot: 130 | # image: certbot/certbot 131 | # restart: unless-stopped 132 | # volumes: 133 | # - type: bind 134 | # source: ./data/certbot/conf 135 | # target: /etc/letsencrypt 136 | # - type: bind 137 | # source: ./data/certbot/www 138 | # target: /var/www/certbot 139 | # entrypoint: "/bin/sh -c 'trap exit TERM; while :; do certbot renew; sleep 12h & wait $${!}; done;'" 140 | # logging: 141 | # driver: "json-file" 142 | # options: 143 | # max-size: "1m" 144 | # max-file: "5" 145 | 146 | volumes: 147 | mysql: -------------------------------------------------------------------------------- /dump_mysql.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | db_host_string=$(cat .env | grep WORDPRESS_DB_HOST) 4 | db_host=${db_host_string#*=} 5 | 6 | db_root_string=$(cat .env | grep MYSQL_ROOT_PASSWORD) 7 | root_pw=${db_root_string#*=} 8 | 9 | db_name_string=$(cat .env | grep WORDPRESS_DB_NAME) 10 | db_name=${db_name_string#*=} 11 | 12 | mysql_path_string=$(cat .env | grep MYSQL_DUMP_DIR) 13 | mysql_path=${mysql_path_string#*=} 14 | 15 | dump_name=${mysql_path}/${db_name}.`date +%Y%m%d%H%M%S`.gz 16 | docker-compose exec ${db_host} /usr/bin/mysqldump --single-transaction --no-tablespaces --skip-lock-tables -u root -p${root_pw} ${db_name} | gzip -9 > ${dump_name} 17 | -------------------------------------------------------------------------------- /init_letsencrypt.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if ! [ -x "$(command -v docker-compose)" ]; then 4 | echo 'Error: docker-compose is not installed.' >&2 5 | exit 1 6 | fi 7 | 8 | domains=(example.com www.example.com) 9 | rsa_key_size=4096 10 | data_path="./data/certbot" 11 | email="youremail@address" # Adding a valid address is strongly recommended 12 | staging=0 # Set to 1 if you're testing your setup to avoid hitting request limits 13 | 14 | if [ -d "$data_path" ]; then 15 | read -p "Existing data found for $domains. Continue and replace existing certificate? (y/N) " decision 16 | if [ "$decision" != "Y" ] && [ "$decision" != "y" ]; then 17 | exit 18 | fi 19 | fi 20 | 21 | 22 | if [ ! -e "$data_path/conf/options-ssl-nginx.conf" ] || [ ! -e "$data_path/conf/ssl-dhparams.pem" ]; then 23 | echo "### Downloading recommended TLS parameters ..." 24 | mkdir -p "$data_path/conf" 25 | curl -s https://raw.githubusercontent.com/certbot/certbot/master/certbot-nginx/certbot_nginx/_internal/tls_configs/options-ssl-nginx.conf > "$data_path/conf/options-ssl-nginx.conf" 26 | curl -s https://raw.githubusercontent.com/certbot/certbot/master/certbot/certbot/ssl-dhparams.pem > "$data_path/conf/ssl-dhparams.pem" 27 | echo 28 | fi 29 | 30 | echo "### Creating dummy certificate for $domains ..." 31 | path="/etc/letsencrypt/live/$domains" 32 | mkdir -p "$data_path/conf/live/$domains" 33 | docker-compose run --rm --entrypoint "\ 34 | openssl req -x509 -nodes -newkey rsa:$rsa_key_size -days 1\ 35 | -keyout '$path/privkey.pem' \ 36 | -out '$path/fullchain.pem' \ 37 | -subj '/CN=localhost'" certbot 38 | echo 39 | 40 | 41 | echo "### Starting nginx ..." 42 | docker-compose up --force-recreate -d nginx 43 | echo 44 | 45 | echo "### Deleting dummy certificate for $domains ..." 46 | docker-compose run --rm --entrypoint "\ 47 | rm -Rf /etc/letsencrypt/live/$domains && \ 48 | rm -Rf /etc/letsencrypt/archive/$domains && \ 49 | rm -Rf /etc/letsencrypt/renewal/$domains.conf" certbot 50 | echo 51 | 52 | 53 | echo "### Requesting Let's Encrypt certificate for $domains ..." 54 | #Join $domains to -d args 55 | domain_args="" 56 | for domain in "${domains[@]}"; do 57 | domain_args="$domain_args -d $domain" 58 | done 59 | 60 | # Select appropriate email arg 61 | case "$email" in 62 | "") email_arg="--register-unsafely-without-email" ;; 63 | *) email_arg="--email $email" ;; 64 | esac 65 | 66 | # Enable staging mode if needed 67 | if [ $staging != "0" ]; then staging_arg="--staging"; fi 68 | 69 | docker-compose run --rm --entrypoint "\ 70 | certbot certonly --logs-dir /tmp/ --webroot -w /var/www/certbot \ 71 | $staging_arg \ 72 | $email_arg \ 73 | $domain_args \ 74 | --rsa-key-size $rsa_key_size \ 75 | --agree-tos \ 76 | --force-renewal" certbot 77 | echo 78 | 79 | echo "### Reloading nginx ..." 80 | docker-compose exec nginx nginx -s reload -------------------------------------------------------------------------------- /mysql-dumps/.placeholder: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/garutilorenzo/wordpress-docker/226fa696a1d604abcdbaeb68b11e9e665d220e20/mysql-dumps/.placeholder -------------------------------------------------------------------------------- /push.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | docker_registry='' 4 | 5 | env_str=$(cat .env | grep ENV) 6 | env_value=${env_str#*=} 7 | 8 | wordpress_image_name=$(cat .env | grep CUSTOM_WORDPRESS_IMAGE) 9 | wordpress_image_name_value=${wordpress_image_name#*=} 10 | 11 | wordpress_image_version=$(cat .env | grep WORDPRESS_${env_value}_VERSION) 12 | wordpress_image_value=${wordpress_image_version#*=} 13 | 14 | if [ -z "$docker_registry" ]; then 15 | # Docker hub 16 | DOCKER_REGISTRY_PATH="${wordpress_image_name_value}:${wordpress_image_value}" 17 | else 18 | DOCKER_REGISTRY_PATH="${docker_registry}/${wordpress_image_name_value}:${wordpress_image_value}" 19 | fi 20 | 21 | echo $DOCKER_REGISTRY_PATH 22 | docker push $DOCKER_REGISTRY_PATH -------------------------------------------------------------------------------- /wordpress-sql/.placeholder: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/garutilorenzo/wordpress-docker/226fa696a1d604abcdbaeb68b11e9e665d220e20/wordpress-sql/.placeholder -------------------------------------------------------------------------------- /wordpress-src/.placeholder: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/garutilorenzo/wordpress-docker/226fa696a1d604abcdbaeb68b11e9e665d220e20/wordpress-src/.placeholder -------------------------------------------------------------------------------- /wordpress/Dockerfile: -------------------------------------------------------------------------------- 1 | ARG WORDPRESS_VERSION 2 | FROM wordpress:${WORDPRESS_VERSION} 3 | 4 | USER root 5 | 6 | ARG WORDPRESS_UID 7 | ARG WORDPRESS_GID 8 | ARG WORDPRESS_USER 9 | ARG WORDPRESS_GROUP 10 | 11 | COPY ./adduser.sh / 12 | RUN /adduser.sh && rm -rf /adduser.sh 13 | 14 | USER ${WORDPRESS_USER} -------------------------------------------------------------------------------- /wordpress/adduser.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | if [ /etc/alpine-release ]; then 3 | addgroup --gid ${WORDPRESS_GID} ${WORDPRESS_GROUP} && \ 4 | adduser \ 5 | --disabled-password \ 6 | --gecos "" \ 7 | --home /var/www/html \ 8 | --ingroup ${WORDPRESS_GROUP} \ 9 | --no-create-home \ 10 | --uid ${WORDPRESS_UID} \ 11 | ${WORDPRESS_USER} && \ 12 | addgroup ${WORDPRESS_USER} www-data 13 | else 14 | groupadd -g ${WORDPRESS_GID} ${WORDPRESS_GROUP} && useradd -u ${WORDPRESS_UID} -g ${WORDPRESS_GID} -m -d /var/www/html -s /bin/bash ${WORDPRESS_USER} && usermod -a -G www-data ${WORDPRESS_USER} 15 | fi --------------------------------------------------------------------------------