I generate one laravel project . Now i need to move the project to the production server. In the local system, I use php artisan serve to run the project and run http://127.0.0.1:8000/ .
while moving to the production server, I changed the .env file
APP_ENV=production
APP_DEBUG=false
APP_LOG_LEVEL=debug
APP_URL=http://myserverip
My config/app.php
'env' => env('APP_ENV', 'production'),
'debug' => env('APP_DEBUG', false),
'url' => env('APP_URL', 'http://my ip'),
I run the project (ip/projectfolder) in live it displays dirctory files listing in the browser.
Is there is any thing extra I need to configure ?
Related
In my Laravel-8, I deleted .env when I'm about to deploy to production.
In the .env, I have:
APP_KEY=base64:JMKPPddG+sPK/ufZKNGwGTStKbMLO2Vnv/4i2fA3j1c=
and config/app:
'key' => env('APP_KEY'),
Everything was working fine until when I deleted .env
When I run the application, I got this error:
production.ERROR: No application encryption key has been specified in Laravel
I don't want to use .env
How do I get this resolved?
Thanks
first run this command to cache configurations:
php artisan config:cache
then u can remove .env
note: calling env() helper from your code will always return null because .env values can be accessed only from config files.
blocking access to .env file in the server is a better solution though.
I've been trying to setup mailing in Laravel 7 with AWS SES and have setup all my credentials properly and set my drivers to SES.
I get the following error when attempting to send an email verification with the default built in functionality.
Connection could not be established with host smtp.mailtrap.io :stream_socket_client(): unable to connect to tcp://smtp.mailtrap.io:2465 (Operation timed out)
.env
MAIL_DRIVER=ses
MAIL_FROM_ADDRESS=no-reply#taxsion.com
MAIL_FROM_NAME="${APP_NAME}"
AWS_ACCESS_KEY_ID=HIDDEN
AWS_SECRET_ACCESS_KEY=HIDDEN
AWS_DEFAULT_REGION=us-east-1
I have ensured that the AWS key and secret have full access to SES, in my config/services.php I am setting it to use these credentials.
'ses' => [
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
]
I have searched through numerous "solutions" and have tried creating a separate user for SES only with no luck.
Any help would be great, thanks!
Laravel 7 has introduced Multiple Mail Drivers which has changed how the mail config works.
If you look at your config/mail.php you'll notice that you have a MAIL_MAILER value instead of MAIL_DRIVER. You should be able to simply change the MAIL_DRIVER to MAIL_MAILER in your .env file:
MAIL_MAILER=ses
You may also need to clear the config cache after you've made the change:
php artisan config:clear
The issue was that my .env was not being loaded due to caching.
Simply running php artisan config:clear cleared the cached config and updated it with my new parameters.
My .env contains the following:
MAIL_MAILER=ses
MAIL_FROM_ADDRESS=no-reply#domain.com
MAIL_FROM_NAME="${APP_NAME}"
When trying to retrieve the APP_URL from the Laravel config it returns the wrong URL for development only.
My env file has the following:
APP_URL=http://127.0.0.1:9000
However when I call env('APP_URL') it returns me:
'http://localhost'
Which will not work with my current docker set-up it has to be 127.0.0.1:9000
In my config/app.php file I have the following:
'url' => env('APP_URL')
I have tried php artisan config:cache and php artisan config:clear but I still get the same result of http://localhost
Any ideas on where it could be getting http://localhost from other than the .env or config/app.php?
Thought it would be worth noting using config('app.url') also returns http://localhost
I found out there is an undocumented feature when loading .env files. If you have a .env.dev file in your project folder it will load this config over everything else if your application is in dev mode. It's documented that .env.testing is used in testing which makes sense but it also does it for dev with .env.dev
The application I was working on had a .env.dev and it was this file that had the http://localhost string inside of it.
Just in case anyone is having this issue in production, these are the steps that worked for me:
Make sure that the .env file is specifying that the app is in production. APP_ENV=production
Run php artisan optimize:clear
"localhost" is probably the default value. You error indicates that the .env file is not read at all. Make sure you're not editing .example.env, check if other env variables are accessible, check for typos, check file permissions on .env and if it's located in the root folder of the project.
Today I tried uploading my first website,but i'm getting an error.On the local server it works fine but when I uploaded it to the live server,i'm getting an error that is saying "Whoops, looks like something went wrong".To be more specific it's showing twice on the same page.Check the image bellow.
Steps followed while uploading project to live server:
Zipped the file
Created a new folder at the root directory.
Unzipped the file in the new folder.
Moved all the files from public folder to /public_html/
Edited the locations on the index.php file.
Note: Other than index.php I haven't altered any other file.
I followed a lesson on youtube and with these steps, his project worked but mine is throwing an error.
I have also noticed that after unzipping the folder in the cpanel the .env file is missing.Could this be the issue?
Make the .env file is there .
Then don't forget to generate the application key
php artisan key:generate
There are some times that the .env file isn't being read by the server. You may try to edit the .env file and supply the necessary credentials according to your server such as the following:
APP_URL= *
APP_KEY= *
DB_CONNECTION=mysql
DB_HOST= *
DB_PORT=3306
DB_DATABASE= *
DB_USERNAME= *
DB_PASSWORD= *
The lines with the asterisks are the ones you typically need to fill up. The APP_KEY can be set by using the php artisan key:generate command in your local workspace, then copy the value to your live server.
If the .env can't be read and it still shows an error, try to edit the config/app.php file and change 'key' => env('APP_KEY'), into 'key' => yourgeneratedkey,. Try to also change the values in your config/database.php file into the same one as your .env file
Follow the installation guide https://laravel.com/docs/5.6
Check the server requirements(check if all the required extensions are installed).
Check if all the files are there.
Check Configurations
check config.php file
check directory permissions.
generate application key (php artisan key:generate)
Check if .env exists or not
thanks to all of you who replied.I found the solution.It turns out the cause for the error was a simple spelling mistake in my .env file.
This is caused by missing ".env" file, copy the content of ".env.example" file and create a new ".env" file in the same directory as your "example.env" file.
then run: php artisan key:generate
When I use 'php artisan migrate' I get the following error message:
[Illuminate\Database\QueryException]
SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = homestead and table_name = migrations)
[PDOException]
SQLSTATE[HY000] [2002] Connection refused
I've installed Laravel on a mac with XAMPP and have the following settings:
database.php
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
.env
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
I've tried several solutions I could find online, but none have worked so far.
This is really anoying, but changing DB_HOST=127.0.0.1 to DB_HOST=localhost solves the problem. Give it a try (obviously your file permission must be the right one)
The solution for me was different than anywhere else I found online.
I was unknowingly using the VM (virtual machine) version of XAMPP on Mac, which functions differently than the normal version. VM XAMPP interface looks like this.
If you are using the VM XAMPP, uninstall it and install the correct XAMPP version here.
Once I installed the new version php artisan migrate worked.
If someone is experiencing this when using Docker, I had a multi-stage build with first container running the dependency installation and the second one just being the runtime. What I didn't realise is that the installation with Laravel scripts generate a cached config (bootstrap/cache/config.php) which is used instead of the config/database.php file.
Adding the following to the Dockerfile as the last step did the trick:
RUN php artisan config:clear
First create your database. Read more about it here: http://www.complete-concrete-concise.com/web-tools/creating-a-mysql-database-using-xampp
Let's say your new database is named: my_db.
Use this in your .env:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=my_db
DB_USERNAME=root
DB_PASSWORD=""
I was using a Vagrant machine to run the whole thing, but I was mistakenly running command on my own machine.Thought this might help someone.
Hi you don't have DB_SOCKET= /path/to/socket in env.file while you have unix_socket => env('DB_SOCKET', '') in database.php file.
You could get the /path/to/socket by $ mysql_config --socket
if you are using MAMP then in your .env file :
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=root
DB_PASSWORD=root
I had a similar problem. Only it was using "ddev". It turned out that mysql responds to a completely different IP instead of 127.0.0.1 or locahost.
console: ddev ssh // If using ddev.
Login to mysql: mysql -y USERNAME -p
Runs this "SELECT SUBSTRING_INDEX(USER(), '#', -1) AS ip, ##hostname as hostname, ##port as port, DATABASE() as current_database;" It displays a table with data. The IP may not be the one to connect to. Must take is hostname.
ping "hostname" from the previous table. And then try to put the obtained IP in the .env file. Or "hostname". It also fits.
Now connection works.
This is coming late but it might help someone. I had the same error, it turned out it was a typo in my .env file. Instead of DB_HOST, it was B_HOST. In your case it might be some other env key. Just look closer and you will discover the you have a malformed env file.