From Local to Live, which files to edit - Laravel - laravel

strangely I have never programmed locally, I am a beginner but unfortunately I have always created my little scripts directly live. I am using Laravel with Xampp, but now I would like to put my script online.
My question is, what files do I need to edit to make it effective online? At the moment I edit the .env file locally to connect to the database, but is it the same even if I put it online?
Thanks

Here you can find some basic information: https://laravel.com/docs/7.x/installation and https://laravel.com/docs/7.x/deployment
In general, to have a site in production (Laravel or not) it is better to manage your code with git (through Github, Gilab, etc.)
to have a clean version management (the alternative is to use Ftp trought Cpanel, ...).
If you are a beginner, you can go to https://forge.laravel.com/ which is a portal that greatly facilitates the production of a Laravel project.
Otherwise, a generic hosting is better that has the possibility to connect via ssh, in order to easily execute the commands
(composer install, php artisan, ...).
You can do many optimizations in production (I leave out the ones on the .env file you know):
When you do maintenance on the site it is always best to disable it first(status 503):
php artisan down
Upload the latest version of the code from the git repository:
git pull
Clean the item cache on the server:
php artisan cache:clear
Clean the route cache and recreate it (to do if there is no static code in web.php, but only references to code in the controller):
php artisan route:clear
php artisan route:cache
Clean and optimize the config file (reduces the number of files to be read from ten to one):
php artisan config:clear
php artisan config:cache
Clean up expired passwords and reset tokens (clean up tokens when a user requests a password reset):
php artisan auth:clear-resets
Recreate the framework classes or update the application:
composer dump-autoload or composer install
Activate the site:
php artisan up

Related

Laravel - What steps should one take to make a Laravel app ready for production mode

The scenario is I have developed a Laravel app in my localhost. Everything works fine. Now I need to make it go online. I am just trying to figure out what steps (configuration , security etc.) should I take before I make it go online.
I am listing a few steps:
1) Change in .env file to make the environment point to production mode using APP_ENV=production.
2) Avoide showing errors directly in pages as that would expose the innards of the app. Enable error logging instead.
3) Use caching for faster user experience
4) building a nice 404, not found page
What else should I undertake to turn the app from development mode into production mode ?
Apply changes to .env file:
APP_ENV=production
APP_DEBUG=false
Make sure that you are optimizing Composer's class autoloader map (docs):
composer dump-autoload --optimize
or along install: composer install --optimize-autoloader --no-dev
or during update: composer update --optimize-autoloader
Optimizing Configuration Loading:
php artisan config:cache
Optimizing Route Loading
php artisan route:cache
Compile all of the application's Blade templates:
php artisan view:cache
Cache the framework bootstrap files:
php artisan optimize
(Optional) Compiling assets (docs):
npm run production
(Optional) Generate the encryption keys Laravel Passport needs (docs):
php artisan passport:keys
(Optional) Start Laravel task scheduler by adding the following Cron entry (docs):
* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1
(Optional) Install, config and start the Supervisor (docs):
(Optional) Create a symbolic link from public/storage to storage/app/public (docs):
php artisan storage:link
Laravel deployment docs: https://laravel.com/docs/master/deployment
Digital Ocean's tutorial: How to Install and Configure Laravel
There are some steps you can check
Install LEMP or LAMP stack.
You can check/add PHP and Dependencies for Laravel
Test Your Site’s Functionality
Optimize Image Size
Google Analytics & SEO addition
Check w3 validation
Page speed optimization
configuration
set app_debug to false
make sure you are setting proper folder permissions
Security
use ssl certificate -> you can do configuration with nginx or apache for the same
redirect all requests to https after setting up ssl
set very strong database password
if your app has api's then use api throttling

How to use Laravel custom package, called laravel-users?

I made a new Laravel 5.8 project and run the
php artisan make:auth
and finished DataBase setup/connection. Now I followed the instructions from "https://github.com/jeremykenedy/laravel-users". After publishing it (4 in instructions), I run "php artisan serve" but it still shows the standard Laravel Welcome with login/register option from Auth. What more files do I need to edit/copy to get the "laravel-users" running/showing?
You've already run the make:auth command. The standard views are already in place (check resources/views/auth).
Either manually copy the correct views and assets from the Laravel-Users package, or discard all the auth scaffolding and run the make:auth command again with the package already installed.

Laravel Serve command does not respect --env parameter

To be able to run Browser tests directly in my IDE (without using the artisan dusk command), I want to run php artisan serve --env=dusk.local. While it indeed starts the local PHP server, it uses the wrong database. It uses the database specified in .env not the one in .env.dusk.local.
I ran php artisan cache:clear thousands of times, but it doesn't change anything.
Running things like php artisan migrate --env=... works.
Is there a way to achieve my goal without needing to rename my .env.dusk.local file to .env before each test?
This is a bug in Laravel 5.8: https://github.com/laravel/framework/issues/27828
There is currently no solution (other than downgrading to Laravel 5.7).
It has been fixed in the latest release 5.8.7.

Laravel-Php artisan serve url (127.0.0.1:8000) vs localhost/laravelproject/public

I want to access my laravel project.I run php artisan serve and access the 127.0.0.1:8000 in browser.
But i learned that I can also check my project using the localhost/laravelproject/public url whithout running php artisan serve.
Question: What is the point of using php artisan serve?
No point in two different methods like you mentioned run laravel by "php artisan serve" and by "project url" followed by localhost. But advantage of "php artisan serve" is you can run you laravel project without putting in htdocs/www directory i.e servers root directory. You can put laravel project anywhere where you want and run through the artisan command.
I found some information you may find interesting:
https://www.quora.com/How-can-I-use-php-artisan-serve
But in simple words, php artisan serve is an easy way to create a php server and that is what laravel needs to run.
You could do the same with "php -S 8080 (which would start a php web server (single threaded) in the current directory on port 8080)"
Also if you have already a php server running with apache or nginx it would not be necessary any of the commands.
Hope you find this helpful.
The `Serve command is just a shortcut for the PHP Builtin Webserver, something PHP has out of the box, so the point of using it is to start testing your application as fast as you could, you just need to install PHP, Composer and your application is up (if you don't need anything else, of course). But if you already have Nginx installed, there is no point at all, just use it.
It's not wise to use the Builtin Webserver in production.

moving Laravel project between computers

I have been working on a laravel5 project on a computer , but now I want to continue on an other, but don't know how :(
I'm using wampserver and the project is in the "www" folder, this is the error I'm getting when trying to open the project: " Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request"
Your error message is very vague, so it is hard to pinpoint the cause. I assume you just copy pasted all of the project files
Try these steps:
Make sure you copy all of the project files including the hidden ones(.env).
Prepare your destination computer as in http://laravel.com/docs/
Check you have all the necessary PHP extensions available in php.ini as in above link requirements. Also, watch your PHP version!
Install composer https://getcomposer.org/doc/00-intro.md
When copied, go to your destination folder and run composer install.
Run php artisan key:generate from the command line.
Run php artisan cache:clear from command line
http://php.net/manual/en/install.windows.commandline.php
Make sure your webserver is serving pages from project/public folder.
If laravel is failing, check the log file to see the cause
your_project/storage/logs/laravel.log
Copy the project folder and navigate terminal/cmd
just run following commands.
Create database and place the same name at .env file in laravel project folder
1. composer install
2. php artisan key:generate
3. php artisan cache:clear
4. php artisan migrate
UPDATE: If you're getting
Whoops, looks like something went wrong
in app/config/app.php, set debugging as true with:
'debug' => env('APP_DEBUG', true)'
If you're getting the error
No supported encrypter found. The cipher and/or key length are invalid
for some people it worked to do cp .env.example .env before (2).
You would also have to create new storage link, because Laravel uses absolute path inside it.
php artisan storage:link
https://stackoverflow.com/a/32722141/3982831 Please follow this to resolve your problems. All people forget about permissions on folders.
After you have done as Ademord answer, you might need to use refresh to your WAMP, XAMP or any other development stack you are using. I had the same issue plus changes were not reflecting in the front end. For example new routes in the web.php were not updating.

Resources