-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Laravel App 2FAuth: initial commit of English text
Showing
1 changed file
with
211 additions
and
0 deletions.
There are no files selected for viewing
211 changes: 211 additions & 0 deletions
211
community-tutorials/how-to-install-laravel-app-2fauth-on-webhosting/01-en.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,211 @@ | ||
--- | ||
title: Install the Laravel PHP App 2FAuth on a Webhosting via CCP | ||
description: Learn how to deploy the Laravel PHP App 2FAuth on a Webhosting | ||
level: [beginner, intermediate, advanced] | ||
updated_at: 2023-11-23 | ||
slug: how-to-install-laravel-app-f2auth-on-webhosting | ||
author_name: Markus Hoffrogge | ||
author_url: https://github.com/mohffrog | ||
author_image: https://avatars.githubusercontent.com/u/45703410?v=4 | ||
author_bio: | ||
tags: [2FAuth, 2fa, laravel, php, deployment, webhosting, plesk, ccp] | ||
netcup_product_url: https://www.netcup.de/bestellen/produkt.php?produkt=2042 | ||
language: en | ||
available_languages: [en] | ||
--- | ||
|
||
# Introduction | ||
This tutorial is motivated by two main targets: | ||
|
||
1. How to install a Laravel PHP application on a Netcup Webhosting | ||
2. How to install the 2FAuth PHP application on a Netcup Webhosting | ||
|
||
The 2FAuth application is a pretty useful Open Source application with great benefits: | ||
- Providing you with time based generated one time passwords being used for common 2-factor (2FA) authentication. | ||
- This application makes use of the common standard TOTP, HOTP or STEAM algorithms to generate your personal 2FA one time passwords. | ||
- It supports scanning or uploading of QR codes typically being provided by an application requiring 2FA. | ||
- It is an Open Source application - so you do not rely anymore on Microsoft, Google or any other 3rd party provider to host your secret primary key for generating those passwords. | ||
- In addition you can use it as an alternative or as a fallback solution to an app on your mobile device to get the 2FA password at the time of logging into an application. | ||
|
||
Please have a look to [2FAuth Docs](https://docs.2fauth.app/) or [2FAuth on GitHub](https://github.com/Bubka/2FAuth) for additional information. | ||
|
||
As the 2FAuth application is a PHP application based upon the Laravel PHP framework, this tutorial can also be taken as an example how to deploy a Laravel PHP application to a Plesk managed Webhosting. | ||
|
||
The reading time of this tutorial is about five minutes; running through an actual setup on your Webhosting will take approximately 30-45 minutes. | ||
|
||
> **Info** | ||
> | ||
> The entire installation can completely be done via the Webhosting Customer Control Panel (CCP). | ||
> There is no need for a `ssh` shell nor `ftp` access nor any other commandline execution. | ||
# Requirements | ||
The Webhosting must provide: | ||
|
||
* PHP >= 8.1 | ||
* PHP Composer project installation | ||
* It should support Let's encrypt certificates for encryptive security reasons | ||
* A common PHP supported database instance like e.g. MySQL instance must be created to which 2FAuth can connect | ||
|
||
Since 2FAuth is a very small footprint application, a PHP heap memory of >=64MB is sufficient. | ||
|
||
# Overview on the installation steps | ||
|
||
* Create and configure a dedicated subdomain for a Laravel PHP application | ||
* Install a Let's Encrypt certificate for the subdomain | ||
* Download, upload and unpack the release of the 2FAuth application | ||
* Configure PHP for this subdomian to comply with a Laravel PHP application | ||
* Run PHP Composer to install any application dependency | ||
* Configure the Laravel application environment | ||
* Run the applications Laravel PHP artisan installation commands | ||
* Enjoy the 2FAuth apllication showing up with the Login page | ||
|
||
# Step 1 - Create a dedicated subdomain to host the F2Auth app | ||
|
||
1. Add a new subdomain to your Webhosting - e.g. f2auth.mydomain.de<br>!!! Configure the document root to f2auth.mydomain.de/**public**<br>Click **OK** | ||
![img_01](images/01_2FAuth_Plesk_AddSubDomainFor2FAuthLaravelApp.png) | ||
|
||
> **Info** | ||
> | ||
> The document root of a subdomain hosting a Laravel PHP application MUST be set to <subdomain>/public. | ||
> Otherwise you will break the security concept of a Laravel application, since the root directory of the Laravel app does not contain any .htaccess config file to restrict direct access to the application content from outside! | ||
# Step 2 - Install a Let's Encrypt certificate for the subdomain | ||
|
||
1. Click **SSL/TLS Certificates** on the CCP subdomain panel<br> | ||
![img_02](images/02_2FAuth_Plesk_SelectSSL_TLS_CertificatesFromSubDomainDashboard.png) | ||
2. Click **Install** in the certificates installation dialog<br> | ||
![img_03](images/03_2FAuth_Plesk_AddSSLLetsEncryptCertificateToSubDomain.png) | ||
3. Select the installation options as follows and click **Get it free**:<br> | ||
![img_04](images/04_2FAuth_Plesk_ConfigureLetsEncryptCertificateOptions.png ) | ||
4. Enable HSTS for security reasons<br> | ||
![img_05](images/05_2FAuth_Plesk_EnableHSTSFor2FAuthSubDomain.png) | ||
|
||
# Step 3 - Download, upload and unpack the release of the 2FAuth application | ||
|
||
1. Download F2Auth application as .zip file from [2FAuth Releases](https://github.com/Bubka/2FAuth/releases)<br> | ||
![img_06](images/06_2FAuth_Plesk_DownLoadLatest2FAuthAppReleaseZipFileFromGitHub.png) | ||
2. Drop this file to your subdomain home directory `<WebHostingHome>/f2auth.mydomain.de/` and extract it there into the same folder<br> | ||
![img_07](images/07_2FAuth_Plesk_Unpack2FAuthAppFromReleasedZipFile.png) | ||
3. Remove the initial subdomain root directory `public`<br> | ||
![img_08](images/08_2FAuth_Plesk_RemoveInitialSubDomainDocRootFolder.png) | ||
4. Select all files within the unpacked folder and move them one level up to the subdomain home directory<br> | ||
![img_09](images/09_2FAuth_Plesk_SelectAllFilesFromUnpackFolderToMoveToSubDomainHomeDir.png)<br> | ||
![img_10](images/10_2FAuth_Plesk_MoveAllFilesFromUnpackFolderToSubDomainHomeDir.png) | ||
5. Finally remove the now empty unpack folder<br> | ||
![img_11](images/11_2FAuth_Plesk_RemoveEmptyUnpackDir.png) | ||
|
||
# Step 4 - Configure PHP for this subdomian to comply with a Laravel PHP application | ||
|
||
1. Click **PHP** on the CCP subdomain panel<br> | ||
![img_12](images/12_2FAuth_Plesk_SelectPHPFromSubDomainDashboard.png) | ||
2. Select PHP version to `8.1` as a minimum - this is required by `F2Auth` at the time this tutorial has been written<br> | ||
![img_13](images/13_2FAuth_Plesk_ConfigurePHPVersion.png) | ||
3. Edit `open_basedir` and select the item starting with **`{WEBSPACEROOT}`**<br> | ||
![img_14](images/14_2FAuth_Plesk_ConfigurePHPOpenBaseDir.png) | ||
4. Edit `upload_tmp_dir` and select **`{DOCROOT}{/}tmp`**<br> | ||
![img_15](images/15_2FAuth_Plesk_ConfigurePHPUploadTMPDir.png) | ||
|
||
All other PHP config properties can be left to their default values. | ||
|
||
> **Info** | ||
> | ||
> PHP `open_basedir` must allow the application php scripts to access directories up to the subdomain docroot directory. | ||
> Otherwise the Laravel application will fail internally with http error status 500. | ||
# Step 5 - Run PHP Composer and install application dependencies | ||
|
||
Any Laravel PHP application provides a configuration for PHP Composer to simplify the entire installation and to ensure that all dependencies are installed in a consistent and version compliant way. | ||
|
||
1. Click **PHP Composer** on the CCP subdomain panel<br> | ||
![img_16](images/16_2FAuth_Plesk_SelectPHPComposer.png) | ||
2. Click **Scan** on the upcoming PHP Composer dialog<br> | ||
![img_17](images/17_2FAuth_Plesk_ScanForPHPComposerApp.png) | ||
3. Click **Install** after the composer has determined all dependencies<br> | ||
![img_18](images/18_2FAuth_Plesk_RunInstallFromPHPComposer.png) | ||
|
||
# Step 6 - Configure the Laravel application environment | ||
|
||
1. Navigate to the subdomains file list and double click file `.env.example` to open it with the online editor<br> | ||
![img_19](images/19_2FAuth_Plesk_SelectEnvExampleToSaveAs.png) | ||
2. Save this file as `.env` in the same directory<br> | ||
![img_20](images/20_2FAuth_Plesk_SaveEnvExampleAsDotEnv.png) | ||
3. Double click the `.env` file to open it with the online editor<br> | ||
![img_21](images/21_2FAuth_Plesk_DotEnvSelectFileToEdit.png) | ||
4. Edit the properties shown in the following screenshots accordingly:<br> | ||
- Edit `SITE_OWNER` and `APP_URL`<br> | ||
![img_22](images/22_2FAuth_Plesk_DotEnvEditAppProperties.png) | ||
- Edit all `DB_...` properties<br> | ||
![img_23](images/23_2FAuth_Plesk_DotEnvEditDatabaseProperties.png) | ||
- Optional: If you want the app to send an eMail in case of restting a user password, then edit all `MAIL_...` properties accordingly<br> | ||
![img_24](images/24_2FAuth_Plesk_DotEnvEditMailProperties.png) | ||
- Save the `.env` file<br> | ||
|
||
# Step 7 - Run the applications Laravel PHP artisan installation commands | ||
|
||
1. Click **Scheduled Tasks** on the CCP subdomain panel<br> | ||
![img_25](images/25_2FAuth_Plesk_SelectScheduledTasksToRunInstallCommands.png) | ||
2. Click **+ Add Task**<br> | ||
![img_26](images/26_2FAuth_Plesk_AddScheduledTaskToRunInstallCommand.png) | ||
3. In the task dialog:<br> | ||
- Check `Run a PHP script` | ||
- Select script file `<subdomain root dir>/artisan` | ||
- Edit `migrate:refresh` as script argument | ||
- Select PHP version `8.1` | ||
- Click **Run Now**<br> | ||
![img_27](images/27_2FAuth_Plesk_InitMigrateRefreshCommand.png) | ||
4. Run same task with script argument updated to `passport:install`<br> | ||
![img_28](images/28_2FAuth_Plesk_InitPassportInstallCommand.png) | ||
5. Run same task with script argument updated to `storage:link`<br> | ||
![img_29](images/29_2FAuth_Plesk_InitStorageLinkCommandOutput.png) | ||
6. Run same task with script argument updated to `key:generate`<br> | ||
![img_30](images/30_2FAuth_Plesk_InitKeyGenerateCommandOutput.png) | ||
7. Run same task with script argument updated to `config:cache`<br> | ||
![img_31](images/31_2FAuth_Plesk_InitConfigCacheCommandOutput.png) | ||
8. You should have gotten a notification output for any of the installer task command runs like this:<br> | ||
![img_32](images/32_2FAuth_Plesk_InstallationCommandOutputs.png) | ||
9. **!!! Preserve the APP key** from the `.env` file in a safe place. Without that key you will not be able to use the database, since anything persisted in the database will be encrypted with this key.<br> | ||
![img_33](images/33_2FAuth_Plesk_PreserveAppKey.png) | ||
|
||
# Step 8 - Enjoy the 2FAuth application showing up with the Login page | ||
|
||
> **Congratulations** | ||
> | ||
> You have completed the setup of your self hosted [2FAuth](https://docs.2fauth.app/) application! | ||
> Navigate to your subdomain URL and login to your `2FAuth` application. | ||
> **Info** | ||
> | ||
> The first user lgging into the application will become the F2Auth Admin - so make sure you are the first one! | ||
![img_34](images/34_2FAuth_Plesk_LoginUI.png) | ||
|
||
# Conclusion | ||
|
||
- A Netcup Webhosting can run the F2Auth Laravel application without any specific modification of the application | ||
- To run a Laravel PHP application on a Webhosting the following configuration must be set for the subdomain: | ||
- The docroot for the subdomian must be `<subdomain>/public` | ||
- PHP `open_basedir` must be configured to start with `{WEBSPACEROOT}` rather than `{DOCROOT}`<br> | ||
**Note** This setting implies the risk that the application scripts are getting access to your entire hosting files. So you have to make sure that you can trust the content and the implementation of the application! | ||
|
||
# License | ||
|
||
[MIT](https://github.com/netcup-community/community-tutorials/blob/main/LICENSE) | ||
|
||
Copyright (c) 2021 netcup | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicence, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
# Contributor's Certificate of Origin | ||
By making a contribution to this project, I certify that: | ||
|
||
1) The contribution was created in whole or in part by me and I have the right to submit it under the licence indicated in the file; or | ||
|
||
2) The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate licence and I have the right under that licence to submit that work with modifications, whether created in whole or in part by me, under the same licence (unless I am permitted to submit under a different licence), as indicated in the file; or | ||
|
||
3) The contribution was provided directly to me by some other person who certified (a), (b) or (c) and I have not modified it. | ||
|
||
4) I understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project or the licence(s) involved. |