Laravel Cloud Hosting Questions
Change your Laravel .ENV file configuration through the control panel
The Laravel .env file is a configuration file that contains environmental variables for your Laravel application. These variables are used to store sensitive data such as database credentials, API keys, and other important configuration settings that your application needs to run properly.
The .env file is located in the root directory of your Laravel project and is loaded automatically by Laravel when the application boots up. This file contains a list of key-value pairs, where the keys are the names of the environmental variables, and the values are their corresponding values.
Using the ENV Configuration Tool
If you've deployed a Laravel-optimised Managed Cloud Server then you can quickly and easily add or change existing Laravel environment variables using the ENV Configuration tool within the 20i control panel.
To use the ENV Configuration tool:
- Head to your Hosting Packages and select Options > Manage on the package you need to manage
- Select ENV Configuration from the Laravel Tools section
If you've just deployed a new application then you'll see all the default environment variables pre-populated in the table view. If you want to adjust any variables, for example 'APP_DEBUG', then you can simply edit the right-hand side column with the option you want and the proceed to select Update ENV Configuration to save your changes.
If you want to edit the ENV file directly through File Manager, then there's a quick link to take you directly to the file at the top-right of the page, select View in File Manager to go directly to the source file which is usully found within your applications home directory.
You can also add new variables to your file by inputting the variable you want to add in the text field at the bottom-left of the table, then inputting the variable in the text field to the right. Then Update ENV Configuration will add the new variable to the table/file.
Using the 20i Laravel Command Executor
The 20i Laravel Command Executor is a feature available when you provision a Laravel-optimised Managed Cloud Server. The command executor allows you to run custom commands on your server directly from the 20i control panel without needing to connect via SSH.
Using the command executor, you can perform a wide range of server management tasks, such as installing software, configuring services, running database migrations, and more. The command executor also provides access to tools such as PHP.
The Command Executor currently supports the following types of command: PHP, Artisan, ENV, NPM and Node commands.
Here are some examples of what you can run using the 20i Laravel Command Executor.
1. Install packages: You can use the command executor to install packages or libraries on your server. For example, to install the curl package, you can run:
sudo apt-get install curl
2. Run database migrations: If you're using a PHP framework like Laravel, you can run database migrations using the command executor. For example, to run Laravel's database migrations, you can run:
php artisan migrate
3. Update packages: You can use the command executor to update your server's packages and dependencies. For example, to update all installed packages, you can run:
sudo apt-get update && sudo apt-get upgrade
4. Backup your database: You can use the command executor to create backups of your database. For example, to create a backup of a MySQL database, you can run:
mysqldump -u [username] -p [database_name] > [backup_file].sql
These are just a few examples of the many commands you can run using the 20i Laravel Command Executor. You can run any command that you would typically run in a command line interface, as long as it's supported by your server's operating system.
Checking your Laravel error logs through the control panel
Like any software, Laravel applications may encounter errors during their operation. Laravel error logs are a record of these errors, which are generated by Laravel's built-in error handling system.
When an error occurs in a Laravel application, the error is logged to a file in the application's storage directory. By default, Laravel uses the Monolog library for logging, which allows for flexible logging configurations and can log to multiple destinations, including files, email, databases, and more.
Laravel error logs contain information about the type of error, the location in the code where the error occurred, and any other relevant details, such as the values of variables at the time of the error. This information can be invaluable for troubleshooting and resolving issues in a Laravel application.
Developers can view Laravel error logs by accessing the log files directly, or by using a tool like the Laravel Logs, which provides a web interface for viewing and searching log files.
There are many types of errors that can be logged in Laravel, depending on the nature of the application and the code that is running. Here are some examples of common errors that might appear in Laravel error logs:
- Syntax errors: these occur when there is an error in the syntax of the PHP code, such as a missing semicolon or a typo in a variable name
- Database errors: when there is an error with the database connection or a problem with the SQL queries being executed, such as a table that doesn't exist or a query that has invalid syntax
- Server errors: when there is an issue with the server environment, such as a misconfigured web server or insufficient server resources
- Application logic errors: when there is a problem with the logic of the application code, such as a function that is not returning the expected result or a conditional statement that is not behaving as expected
- Security errors: when there is a security vulnerability in the application, such as a cross-site scripting (XSS) or SQL injection attack, or when there is an attempt to access a resource that the user is not authorized to access
Laravel error logs can help developers identify and resolve these types of errors, improving the stability and security of their applications.
Getting started with a Laravel Managed Cloud Server
Laravel on 20iCloud, AWS or Google Cloud
With a 20i Managed Cloud Server you can deploy Laravel applications on an optimised cloud server stack complete with easy setup, production ready PHP and full environment control. Deploy unlimited Laravel apps across 20iCloud, AWS and GCP, and easily manage everything through the My20i control panel, no server admin required.
You get built in dev tools like Git Version Control, FTP/SFTP access, scheduled tasks, SSH and 20i's Laravel Command Executor, all on top of the industry's best hosting platform with expert customer support. Did we mention you get free backups and free SSL as standard?
To get started head to Managed Cloud Hosting and choose your server spec!
Here's a breakdown of some of the features you'll get with 20i:
Built-in performance | Built-in dev tools | Built-in security |
---|---|---|
✔️ Multi-platform Cloud Hosting | ✔️ Git Version Control | ✔️ Free SSL Certificates |
✔️ My20i Control Panel | ✔️ Unlimited FTP/SFTP Access | ✔️ Free Daily Backup & Restore |
✔️ Free CDN & Edge Caching | ✔️ SSH & SFTP Login Control | ✔️ PCI Compliant Hosting |
✔️ 100% Renewable Energy | ✔️ Redis Cache | ✔️ Two-Factor Authentication |
✔️ IPv6 and HTTP/2 Enabled | ✔️ ElasticSearch | ✔️ Advanced DDoS Protection |
✔️ 80+ One-Click Apps Inc. Laravel | ✔️ Cron Job Manager | ✔️ Error & Access logs |
Deploying Your Laravel Cloud Server
1. Head to 'Build your Cloud Server' and choose Laravel from the server optimisations.
2. Choose what cloud platform you want to use: 20iCloud, AWS or GCP and the size of server you need.
3. Select Deploy Cloud Server and your server will be built within just a few minutes.
Installing Laravel on your Cloud Server
1. Head to your cloud server list and select Options > Add Package.
2. Give your site/app a name and then select Options > Manage.
3. Laravel will install automatically and you'll be able to start work on your app straight away.
How To Host Your Live Laravel Application with 20iCloud
Contents
- Introduction
- Prerequisites
- Step 1 - Create an Empty Hosting Package
- Step 2 - Connect your GitHub Account
- Step 3 - Select and Clone your Repository
- Step 4 - Getting your Laravel Application Live
- Step 5 - SSL, DNS, Email & More
Introduction
Laravel is an open-source PHP framework that provides a set of tools and resources to build modern PHP applications, and not coincidentally it's also the most starred PHP framework on GitHub! Laravel has been crafted by a collaborative community to provide a seamless and elegant developer experience, and so, deserves a hosting experience to match!
20iCloud is a Managed Cloud Server environment that's been built from the ground up to host a wide range of applications, and can be provisioned with a technical profile designed specifically for hosting Laravel applications.
Laravel Technical Profile Details
Service | Details |
MariaDB | Faster query speeds and can handle a higher number of concurrent connections efficiently. |
NGINX | High-Performance Web Server for faster static file serving over Apache2. |
PHP-FPM | Pre-configured PHP-FPM to manage PHP processes. Its main advantage is that it can handle a high volume of queries, making it especially useful for sites with heavy traffic or complex web applications. |
Redis 6 | Caches data in-memory, Redis allows for rapid retrieval of frequently accessed data like product details and user sessions, significantly reducing database load. |
In this guide we'll walk you through the process of hosting your Laravel application with 20iCloud.
Prerequisites
- A GitHub repository with your Laravel application.
- A 20iCloud Server with the Laravel profile.
Step 1 - Create an Empty Hosting Package
Before you can clone your Laravel application from your GitHub account you need to create a hosting package. This will contain your applications files, databases and emails if necessary.
- Head to Managed Cloud Hosting.
- Select Hosting Packages and then Add Hosting Package.
- Select your Cloud Server and enter a Domain Name (this can be changed later).
- Now select Create Hosting Package.
Your hosting package will be provisioned on your 20iCloud Server ready for your Laravel application. You'll be able to manage DNS, apply the Free SSL, add email accounts and much more alongside the running of your application.
Step 2 - Connect your GitHub Account
You'll now be able to connect your GitHub account to enable you to select and clone the repository containing your Laravel application.
Head to Git Version Control icon.
Select Sign in with GitHub. You can also use Manual Setup if you'd like to enter the details of your Git repository manually.
3. Select Install & Authorize to allow the 20i Git Manager application to access your selected repositories.
20i Git Manager will then be install and initiated as a GitHub Application with the permissions and access specified during the install. You can manage the application settings from within GitHub Applications. You can also Sign Out of GitHub from the Git Version Control page in My20i.
Step 3 - Select and Clone your Repository
Now you've connected your GitHub Account you'll be able to see and manage your repositories from the dropdown menu. You can now go about choosing a repository that you want to clone from, to do this:
1. Find and select the repository that you want to clone from.
2. Once selected you'll see the Clone a Repository section pre-filled with the repository information needed, select Create at the bottom to clone the repository into the path selected.
3. Your application will be cloned onto your 20i hosting package on your Cloud Server.
Step 4 - Configure Laravel for Production
Now that your application has been cloned onto your 20i hosting package, it's time to configure and deploy your Laravel application. This involves several key steps to ensure your application is optimised for a production environment.
1. Create a .env
File and Set Environment Variables
Use the 20i Command Executor (or SSH) to create a .env file. This file is crucial as it holds all the environment-specific settings for your application, such as database credentials, cache settings, and more. Ensure you do not commit this file to your source control to avoid exposing sensitive information.
Example .env
content:
APP_NAME=Laravel
APP_ENV=production
APP_KEY=base64:...
APP_DEBUG=false
APP_URL=https://yourdomain.com
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=your_database
DB_USERNAME=your_username
DB_PASSWORD=your_password
CACHE_DRIVER=redis
QUEUE_CONNECTION=database
SESSION_DRIVER=file
SESSION_LIFETIME=120
To generate a .env
file using the command executor in the 20i Laravel tools, you can run the following command:
cp .env.example .env
You can then use the 20i Env Configuration to update the .env file to set appropriate values for your environment.
2. Install Dependencies
Once your environment variables are set, use the 20i Command Executor (or SSH into your server) and run the following command to install all required PHP dependencies:
composer install --no-dev --optimize-autoloader
This ensures that only production dependencies are installed, and the autoloader is optimized for faster performance.
3. Build Assets for Production
If your application uses frontend assets like JavaScript or CSS, you need to compile and minify them for production. This is usually done using tools like Laravel Mix:
npm ci
npm run production
These commands install the necessary Node.js dependencies and compile the assets.
4. Cache Configuration Files
To boost your application's performance, cache the configuration and route files:
php artisan config:cache
php artisan route:cache
php artisan view:cache
These commands compile your configuration, routes, and views into single files to reduce the number of file system accesses.
5. Run Database Migrations
Ensure your database is up to date with the latest schema by running the migrations:
php artisan migrate --force
The --force
flag is necessary to run migrations in a production environment.
6. Restart Services
Finally, restart the necessary services to apply the changes:
php artisan queue:restart
By following these steps, your Laravel application should be well-configured for a production environment on your 20iCloud server.
Step 5 - SSL, DNS, Email & More
20iCloud Servers are perfect for hosting your live Laravel applications and come with all the tools you need to make your live application.
1. Apply the Free SSL
Head to the SSL/TLS Certificates section and select Enable to install a free Wildcard Let's Encrypt SSL.
2. Ensure DNS is Correct
You can manage your DNS through the Manage DNS section. The A Records are already configured to serve traffic to your application, ensure your nameservers are pointing to 20i's nameservers.
3. Set Up Email Accounts
20iCloud Servers come with Unlimited 10GB Mailboxes. Head to Email Accounts and add any mailboxes that you need.