SOLVED: My machine didn't have MySQL installed and was having a hard time installing it and I still do.
I recently downloaded a Laravel project from cPanel and I wish to work on it. But when I try to run the project I get "500 server error".
After searching on Google, I tried the following steps
composer update --no-scripts
php artisan key:generate
php artisan migrate
This does not seem to be doing anything. How do I run the project on my local machine that I downloaded from the cPanel?
You may want to see what that error is in the log file:
Log file location:
/storage/logs/laravel.log`
The laravel.log file mentioned above may have a date with it on the name.
The 500 error is because the stack trace is turned off in the .env file with APP_DEBUG=falsewhich may be by design since it's on a live server.
Download the files in "public_html" folder and project folder(in my case it is "LMS" folder - refer screenshot).
Export the database from phpmyadmin in cPanel which is used in Laravel project
Go inside the Project folder(in my case LMS folder) and delete all the content inside the "public" folder. Then you will have an empty public folder inside your project folder(LMS folder)
Now copy and paste all the content inside "public_html" folder that is downloaded from cPanel into the previously emptied "public" folder inside the project folder(LMS)
Import the exported database to locally created database
Change following lines in index.php file which is inside the local "public" folder
These two lines
require __DIR__.'/../LMS/vendor/autoload.php';
$app = require_once __DIR__.'/../LMS/bootstrap/app.php';
into these two
require __DIR__.'/../vendor/autoload.php';
$app = require_once __DIR__.'/../bootstrap/app.php';
Notice that we have removed the "LMS" in the paths
Go to the .env file in the project root and change these settings that matches to your local environment
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=lms_trends_new
DB_USERNAME=root
DB_PASSWORD=root
//Only for MAMP users
DB_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock
Run following commands
$ php artisan config:cache
$ composer dump-autoload
Finally run your project with following command
php artisan serve
First , Download the database from cpanel which is used in laravel project .
Then follow any one step below .
Upload the database in your localhost mysql .
then Change your env files as per your local system .
Install composer using following command .
composer install
Then update the compsoser From your composer.json file .
Composer update
composer dump-autoload
Now run php artisan serve
If you find any difficult in the first step , follow the second one.
Install new laravel project using following command .
`composer global require laravel/installer`
Create new project Laravel
`laravel new projectname`
Then just copy paste the directories app/ , Resources, /Public , /config .
Do not touch anything inside config/config.php
Just change the database name and username, password in .env file ..
Then run
php artisan serve
If you still cant able to do it , comment here
Related
Before Laravel, I have been using the MVC Web Framework and success to host in cPanel server.
Now, I decide to upgrade my Framework. So I find Laravel because it also included MVC patterns and easy to learn for me. Seeing some tutorials, I decided to host a simple project of Laravel on a subdomain of my main domain sites.
What I did:
On server:
I create a subdomain and set the document root to /public_html/subdomain.maindomain.com/public.
Inside the public_html folder, I created a folder and renamed as just like to subdomain name.
On My Computer
composer global require laravel/installer
laravel new website
php artisan serve
Now, I get the Laravel homepage on browser link http://127.0.0.1:8000.
Then, I added bootstrap.
composer require laravel/ui
php artisan ui bootstrap --auth
npm install && npm run dev
Then, I see the login and register link on the Laravel homepage.
Now, seeing https://laravel.com/docs/8.x/deployment documentation of Laravel:
composer install --optimize-autoloader --no-dev
php artisan config:cache
php artisan route:cache
php artisan view:cache
Now, I uploaded the zip file (all files inside the website folder) and extracted it to server document root /public_html/subdomain_name/. In the subdomain_name folder, I have all the files that were in my website folder on my computer.
I don't change anything on the index.php file of the public folder, remain on default condition.
require __DIR__.'/../vendor/autoload.php;
$app = require_once __DIR__.'/../bootstrap/app.php';
Then, I check my URL but I faced This page isn’t working, subdomain.domain.com is currently unable to handle this request. HTTP ERROR 500
First of all upload the laravel to your domain root folder and not public_html and extract, then move the content of the public folder of your laravel to /public_html/subdomain.maindomain.com/public then edit the content of the index.php require __DIR__.'/../vendor/autoload.php'; equire_once __DIR__.'/../bootstrap/app.php'; to this require __DIR__.'/../../../laravelpackagename/vendor/autoload.php' and $app = require_once __DIR__.'/../../../laravelpackagename/bootstrap/app.php';
Not tested but I believe this should work
How did I solve this error:
I re-create the Laravel new project just like the above command and put that file to my server path to /public_html/laravel/. Therefore, I didn't change anything on the index.php file on the public folder, remain to the default condition. By doing this still error remains same (HTTP ERROR 500).
Then, I look at the error_log file at /public_html/laravel/public/, and see an error Parse error: syntax error, unexpected '?', expecting variable (T_VARIABLE) in public_html\laravel\vendor\ramsey\uuid\src\functions.php line on 34.
In cPanel MultiPHP Managers, I select my sites and set the PHP Version to the same version it has before [PHP 7.3 (ea-php73)]. Then, BOOM!! It worked. I see the homepage of my laravel project in the URL.
In brief, selecting the same PHP Version in cPanel MultiPHP Managers, help me to solve this error.
I have deployed laravel project to shared hosting but it returns HTTP error 500.
I will shortly describe to you all steps I have done and if there is mistake pls help :)
So here we go...
-I have run composer install --optimize-autoloader --no-dev
-I have run PHP artisan config:cache then PHP artisan config:clear
-After that I have run npm run prod and exported refreshed database with seeded admin acc
-In cPanel I have created database (from .env) and a username and his password (and added all that to .env)
Also, I have connected that admin acc and database successfully :)
-Then I have imported refreshed database in DB that I have just made on cPanel
-All files from the public folder I have uploaded to public_html
-And all folders and files (except public) I have created a new folder in the root and uploaded the rest of the project there
-After that, I went back to public_html/index.php and changed the path of 2 lines:
1. require DIR
2. $app = require_once
So instead of
require __DIR__.'/../vendor/autoload.php
I have put
require __DIR__.'/../folder_name_where_rest_of_app_is/vendor/autoload.php
And, same is done for $app line ...
Saved latest changes and then I have tried to refresh the site and it just throws HTTP Error 500
PS: Also I have added these lines
APP_ENV=production
APP_DEBUG=false
And on APP_URL is the copied URL from the browser...
If anywhere you can see any mistakes please tell me :)
try this
php artisan optimize:clear
composer dump-autoload
There are many possibilities.
To debug, limit access with something like HTTP basic auth or IP access control and turn on APP_DEBUG.
Check the log files in storage/logs/ and the web server logs.
Make sure the environment has an encryption key set. If not run:
php artisan key:generate
I have seen this answer in many posts but they have not helped me at all. I followed the regular steps to create the laravel project like this:
I cloned from my repository.
I ran composer update.
I added 777 permissions to storage and bootstrap folders.
I have a .env file.
I verfied the .htacces and it's ok.
It is working in locahost, but when I try to replicate it in Hostinger it does not work, it displays the 500 server error. So I wonder what is the problem?
I checked the logs by the way and they were empty. I put the laravel project debugger to true too.
the website url is xellin.com
The debug:
The logs folder:
Thanks.
I think this is a good opportunity to point out how PHP / Laravel / Underlying Server interacts one to each other.
First:
The HTTP server inspects Document Root and .htaccess to get instructions.
If the file is .php (like Laravel), then it CALLS to the php handler.
The php handler could be a FPM version or a Fast CGI version.
-> If an error ocurrs parsing the .htaccess or with the initial interaction between Http Server and PHP... Laravel never runs for real. All ends in a PHP error log
To find out what's wrong, you need to inspect what PHP / Http Server said about the error in their respective logs.
In short words: at this point is not a Laravel error, but a server/php one.
Second:
If Apache/PHP runs well, then PHP executes the Laravel Applicacion Lifecycle... if Laravel encounters a problem, then you will see the usual output error of Laravel Error Handler.
I think this is a must to know to work with web apps in general, because many times developers miss to catch if the problem was with Laravel, or with PHP / Server itself.
As a side note, that's why it is important to know how to choose propper hosting service for Laravel.
Thanks for reading.
You can try to clear cache
Like as
php artisan optimize
Or
You can manually delete cache files which is located in bootstrap folder and inside bootstrap folder you can see cache folder inside cache folder delete all files except git ignore file your issue fix
If you show again this error on live serve then tou can update your composer and then run
php artisan optimize
at first, if you give any of your folders 777 permissions, you are allowing ANYONE to read, write and execute any file in that directory.... what this means is you have given ANYONE (any hacker or malicious person in the entire world) permission to upload ANY file, virus or any other file, and THEN execute that file...so please be careful because IF YOU ARE SETTING YOUR FOLDER PERMISSIONS TO 777 YOU HAVE OPENED YOUR SERVER TO ANYONE THAT CAN FIND THAT DIRECTORY. please read the full explanation from here
the second here is the detailed steps I used to deploy my projects to the server:
run npm run production then update your github repo.
clone the project from GITHUB to server - clone to an outside folder (not public_html folder)
run cd <cloned folder name>
run composer install
run npm install
copy and configure .env file to cloned folder( be sure name is .env not env).
copy all content of cloned_project_folder_name/public to public_html folder
in index.php inside public_html folder edit as below
$app = require_once __DIR__.'/../cloned_project_folder_name/bootstrap/app.php';
require __DIR__.'/../cloned_project_folder_name/vendor/autoload.php';
set your .htaccess properly.
change permission to 755 to index.php and all file in public_html folder
run composer install --optimize-autoloader --no-dev
run php artisan config:cache
run php artisan route:cache
I think I state it all, hope that will help
I am trying to make a middleware using artisan php artisan make:middleware AuthorizedUserOnly but I get ErrorException like below.
file_get_contents(/mysite.com/www/local/composer.json) Failed to open stream no such file or directory.
This is my document root.
-local
-Laravel application folders
-artisan
-index.php
-composer.json
.htaccess
I changed my directory structure to work with shared hosting. And It was working fine.
KEY NOTES
Other artisan commands work. Like I tried php artisan route:list & php artisan config:cache & php artisan tinker.
This directory structure works fine.But as the error says that it is trying to find composer.json in local directory while it is on document root.
php artisan make:model command spits the same Exception
What could be the possible issue and solution ?
Solution : I moved my composer.json file to local directory and it worked fine. So new directory structure is
-local
-Laravel Application Folders
-composer.json
-artisan
-index.php
.htaccess
HOW ?
I am not sure about this yet. But this is the possible reason. php artisan make command create some files. So to included these created files into system execute composer dump-autoload. So to run composer it looks for in the same directory where artisan lives which is local directory in my case.
IMPORTANT
I changed laravel default directory structure to successfully run my applicaiton on SHARED HOSTING which laravel DOESNOT RECOMMEND.
We should follow the recommendations made by laravel to avoid any similiar issue. Specially never to mess with default directory structure at least.
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.