I used to use forge for deploying my laravel application to production. I recently deregisted forge and I wanted to deploy via ssh to ubuntu server on my own.
I did composer update and I pull changes to my server via ssh; but after these my application started to give error 500. I did every thing I searched may be useful such as commands below but nothing worked.
does any one know why am I facing is this error? in local environment every thing works properly and my laravel project worked properly before ssh and composer update.
these are the steps I have go through but nothing worked:
deleting vendor folder and reinstalling composer
changing permisions for bootstrap and also for the whole project :
sudo chgrp -R www-data storage bootstrap/cache
sudo chmod -R ug+rwx storage bootstrap/cache
run composer dump-autoload
php artisan config:cache
composer update and sudo composer update
I also tried these commands but none of them worked:
php artisan view:clear
php artisan config:cache
php artisan cache:clear
php artisan config:clear
I am using laravel 8
my .env file also exists and every thing are set there
when I turn on debug mode the error of the application page is like this:
Target class [hash] does not exist.
please helpme if any one has any experience on this problem.
From russia /ivorycoat
delete vendor
composer update
.env.example copy and create .env
php artisan cache:clear
php artisan config:clear
php artisan key:generate
php artisan serve
I have a laravel 7 application running on a server (Ubuntu 18.04 LTS, apache2 webserver). My problem is, that php artisan cache:clear does return "Failed to clear cache. Make sure you have the appropriate permissions."
I tried the following approaches without success:
chmod -R 775 storage
php artisan config:cache
manually deleting "bootstrap/cache/services.php" + "bootstrap/cache/packages.php" + "bootstrap/cache/config.php"
New created cache folders in "storage/framework/cache/data" are sometimes owned by user root, this seems to be the problem.
If I delete these folders manually it works till new root folders are created.
With ps -aux I saw that the laravel process was running from user root. I changed this with sudo -u myusername, but this didnt change the behaviour. I am starting the laravel application (php artisan serve) within the rc.local script on server restart.
The current user "myusername" is in the group www-data.
You have to run webserver from the user that is belongs to the same usergroup with your current user. By default rc.local call commands from root user, which is not what you need.
Edit your rc.local this way:
su user01 -c 'php /var/www/artisan serve'
Where user01 is your current user and /var/www/artisan is full path to your artisan file. Also maybe you should specify full path to your php bin file, like /usr/bin/php or else.
More details here
The problem should be that you don't have folders in storage path. You should have
storage/framework/sessions
storage/framework/views
storage/framework/cache
Try to create empty folders, it should be work.
I have a Laravel project that I copied from my Ubuntu server and now I am trying to run it my local machine (XAMPP on Mac) I have been struggling with this for a few days now and I feel like I am going insane.
When I paste my project in XAMPP htdocs folder I get this error:
View [welcome] not found
Which php artisan cache:clear makes that go away, then I get this error:
The bootstrap/cache directory must be present and writable
Then I do this, php artisan cache:clear which gives me a new error:
Class view does not exist
Then after that no matter what I do either in terminal or viewing the web browser, I always get the error
Class view does not exist
Then I have tried composer update still the same error.....what am I doing wrong?
This has been a nightmare.
Last time i checked Laravel doesnt run on XAMPP but rather on the PHP installed when installing XAMPP so the project can be saved anywhere on the computer.
Given this being the fact, you will need to just have an active PHP installation and then you copy only the relevant files of the project onto the new computer (such files that you will get when you push your project onto GitHub). It doesn`t come with cache issues then all you need to do afterwards is to
php artisan key:generate
then composer install or composer update to get the vendor packages from online
My money right now is on picking the relevant files and reinstall with them
According to my own installation when changing the computer this is the list you will have to copy
I just tried to reproduce your issue on my mac. So i have installed XAMPP with the PHP version 7.1.25 which is the equivalent version of my local PHP version
So I installed the XAMPP and started server.
Downloaded my laravel project folder from my ubuntu server and copied it to htdocs (XAMPP)
When i tried to run http://localhost/myproject/public it shows the exception like
There is no existing directory at "/Applications/XAMPP/xamppfiles/htdocs/myproject/storage/logs" and its not buildable: Permission denied
Then i gave full permission to the storage folder
chmod -R 777 storage
And changed ownership for the files inside myproject folder.
Here i just checked the ownership of the dashboard directory which is running perfectly and given the same user ownership of myproject directory.
chown -R root:admin .
Then following commands
composer install
php artisan cache:clear
php artisan view:clear
php artisan route:clear
After this my laravel code runs perfectly.
Class view does not exist
is probably a ownership issue of the directory
For me (when developing on xampp, what I do for all my projects) - I'd not recommend to put your stuff in the htdocs folder. Laravel expects to not be hosted on a subfodler e.g. (localhost/my-project). So you should set up a virtual host in order to make it work easily (e.g. my-project.test) which is a bit annoying.
Simple solution is using the php artisan serve command in order to simply setup a local server on port 8000.
Don't forget to start xampp for the mysql server.
Some typical tips were already mentioned:
delete vendor folder & run composer install (install composer if you haven't)
run composer dump-autoload
run php artisan key:generate
ofcourse don't forget the migration php artisan migrate
and clear your full cache php artisan cache:clear
Usually you do not need to set any file permissions afaik
chmod -R 777 storage/
If you have a different user for apache2 (usually www-data), also do:
chown -R www-data storage/
You could also check if it runs with the built-in server:
php artisan serve
You can create .htaccess file and add below data into .htaccess file
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
After create .htaccess file, set laravel root path in terminal and run below command in terminal
php artisan serve
Since your Apache is already serving then you have permission problems only. And since you're using Mac, the default user name and group in Apache conf is _www for Mac and not www-data that is for Ubuntu. You can see it in the httpd.conf file :
<IfModule unixd_module>
#
# If you wish httpd to run as a different user or group, you must run
# httpd as root initially and it will switch.
#
# User/Group: The name (or #number) of the user/group to run httpd as.
# It is usually good practice to create a dedicated user and group for
# running httpd, as with most system services.
#
User _www
Group _www
</IfModule>
Now, use terminal, get in your project directory let's say cd /var/www/laravel-project1 and make sure that the group _www (or the user too in some case of your App environment logic` has access (read and write) to :
All public directory and sub-directories containing assets if you have.
sudo chgrp -R _www public
sudo chmod -R 774 public
Storage directory and sub-directories specified here (storage/framework -> all, storage/logs -> all, storage/app -> public directory only), and bootstrap/cache directory and files
sudo chgrp -R _www storage/framework storage/logs storage/app/public bootstrap/cache
sudo chmod -R 774 storage/framework storage/logs storage/app/public bootstrap/cache
That should get rid of all of your permissions problem to access pages.
BUT now if on using the page, sessions and logs files that are created you get other problems, there might be a last problem of permission which is called UMask, which tell Apache or Web Server like Nginx what permission to assign to newly created directory or files for the user _www. By default Apache umask is 0002, which give 0775 for directory and 0664 for new file. If ever umask value was changed to 0022 like it's the default in Nginx, then the equivalent permissions 0755 or 0644 will not be sufficient for your Apache group _www to write in the directories that have group _www. So you can either change umask to 0002 or change owner to _www :
sudo chown -R _www public storage/framework storage/logs storage/app/public
So that depends on your configs.
I ran into the same problem as you, but not moving from ubuntu to mac, it was from windows to linux, I was in a total mess, but only git rescued me, it might give you a bit of pain, but it is going to save you in the future.
Here is the steps you need to do.
Create empty repository on the mac using this command git init --bare.
Clone the repository to the ubuntu using git clone.
Copy your laravel code to the clone you made in step 2.
Push the files from the ubuntu to the MAC.
Test the project.
The directory you will create in the mac, it can be inside the htdocs of the xammp.
I know it might be painful task to do, but it is quite worth it.
Sources for more information:
git-scm
Getting Git on Server
If you need more help, I'll be more than happy to discuss it with you.
Note: The following works for Laravel 5.x but also 4.2, not tested with other versions
Why not using Git?
(If you are not familiar with it, have a look at the official website, there are also tons of tutorials on the web)
Usually, copy-pasting entire projects is not a good idea, because of some file/directory permissions and other not-so-good stuff.
That's what I did to move my project from Windows to my Ubuntu Server:
Put your project on a git repository (GitHub, GitLab, or whatever), the .gitignore files provided with the Laravel apps are, in most cases, good enough
On your new machine, clone your repository
Do a
composer dump-autoload
composer install
To migrate your db, do
php artisan migrate
and if you have seeding, do this
php artisan db:seed
Then, if you have problem with file/folder permissions, do not EVER do a chmod -R 777 path/, if you have to do this to solve your problem, you are doing something wrong.
This command grants all privileges to anyone to all the files and folders in the path folder.
In your case, you have to do the following:
First, find which username is apache using to run the server (usually it's www-data)
ps aux | egrep '(apache|httpd)'
Then, change the project directory owner to apache's user (example for www-data apache user)
sudo chown -R www-data:www-data /var/htdocs/your-project/
Set folders permissions
sudo find /var/htdocs/your-project/ -type d -exec chmod 755 {} \;
Set files permissions
sudo find /var/htdocs/your-project/ -type f -exec chmod 644 {} \;
To fix the bootstrap/cache and storage/ permission problem, do
sudo chown -R www-data:www-data /var/htdocs/your-project/
Laravel 5.x
sudo chmod -R ug+rwx /var/htdocs/your-project/storage /var/htdocs/your-project/bootstrap/cache
Laravel 4.2
sudo chmod -R ug+rwx /var/htdocs/your-project/storage /var/htdocs/your-project/app/bootstrap/cache
Then, you should be good.
Doing that way, you can easily move your project from a machine to another without struggling with permission fixes or anything.
More info and source for files and folders permissions command-line instructions, see Laravel 5 Files Folders Permission and Ownership Setup
Go to your project folder add run these commands from terminal
sudo chmod -R 777 your_projrct/storage
sudo chmod -R 777 your_projrct/bootstrap/cache
sudo chown -R :www-data your_project
sudo chmod -R g+s your_project
then php artisan key:generate and composer install
when user/group www-data are unkown; most Linux distributions use apache:
chown -R apache:apache dirname
while on OSX, this would be user/group _www:
chown -R _www:_www dirname
adding the current user to group _www might make life easier, in general.
To isolate your issues:
Get your code into a repository(bitbucket or github)
Clone the repository into your local environment
Run composer install
Run php artisan serve. This way you rule out xampp as an issue.
In your browser go to localhost:8000
If you already have your entire codebase on your local box(including the vendor folder) then skip steps 1 and 2. Step 3 wouldn't hurt, but you can probably skip that too.
Once you get everything working, switch to xampp.
First of all:
composer update
composer dumpautoload
php artisan cache:clear
And then just configure a virtual host
1. Create a local domain for your app
Edit hosts file and redirect all requests from your domain to 127.0.0.1:
127.0.0.1 lara.vel
2. Configure a Virtual Host
Edit \xampp\apache\conf\extra\httpd-vhosts.conf:
<VirtualHost lara.vel:80>
DocumentRoot "C:\xampp\htdocs\laravel\public"
ServerAdmin laravel.dev
<Directory "C:\xampp\htdocs\laravel">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Done! Open up your domain in your browser, You'll see your project there!
The other way is simple, Just run artisan serve.
Please vote up if you found this answer useful.
I think if you copied the project from Ubuntu so it is a permissions problem.
first get users on your Mac machine by typing this in terminal
users
then copy the user you just got for example (username) and use it in this command
sudo chown -R username project-directory
then check for yourproject-directory/bootstrap/cache if it not exists, go create it. else run this command:
sudo chmod -R guo+w project-directory/bootstrap/cache
then
sudo chmod -R guo+w project-directory/storage
then clear composer autoload and cache and config using artisan command
composer dump-autoload
php artisan cache:clear
php artisan view:clear
php artisan route:clear
now try to run the project if the problem still exists,
you need to check config/app.php if it contains Illuminate\View\ViewServiceProvider::class
the view service provider.
if it is not there, so add it
I have a webhook for my application that currently does this:
cd /var/www/html; git pull origin master; /usr/local/bin/composer dump-autoload; php artisan migrate
I've been able to get all the commands above to work except the composer dump-autoload command.
When I log into the server as ec2-user and run sudo -u apache /usr/local/bin/composer dump-autoload, the command runs. But if I hit the endpoint that runs this command through a PHP script using shell_exec, this does not work.
Is there a way for me to get apache user to run this command on its own?
This should be doable by modifying your sudoers file.
visudo
Add the line:
ec2-user ALL=(apache) NOPASSWD: /path/to/script.sh
Don't forget to check if the apache user does have writing privileges under Laravel directory. composer will try to write in 'vendors' directory.
Regards.
I deployed a laravel project to amazon web server. I used my git repository to deploy it. I updated composer in the server via sync.sh file. Now I need to migrate using artisan command.
Here is my sync.sh file
#!/bin/bash
sudo chmod -R a+w /var/www/****serverName***/public_html/*projectName*
sudo php /usr/bin/composer --working-dir=/var/www/*serverName*/public_html/*projectName*/ update
you can add the following line to your sync.sh file.
sudo php /var/www/****serverName***/public_html/projectName/artisan migrate