I am learning how to use the Symfony framework to do PHP web applications. When you install a new project, it warns me because it cannot create cache repository because is not writable. But when I start a new project with sudo keyword, the terminal complain about running the composer as a root/user.
So I don't know if I start a new project using sudo keyword or not? What is the correct?
You actually can use sudo when using composer in spite of the warning. The resulting project will work just fine.
I ran into this after installing a linux subsystem under Windows 10. For some reason my $HOME/.composer directory ended up being owned by root. I guess it was a byproduct of the composer install process. I didn't bother to figure out why for awhile. Just used sudo.
But it would be better to go ahead and just fix the directory using basic linux commands:
cd $HOME
sudo find .composer -exec chown myusername {} \;
sudo find .composer -exec chgrp myusername {} \;
And that should take care of the problem.
Related
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'm trying to run composer global require "laravel/installer" on my Ubuntu machine (Trenta OS Distro) and for some reason I can't get it to install.
file_put_contents(./composer.json): failed to open stream: Permission denied
I get the error above on every attempt. I've been unable to find any help on google so I'm guessing this isn't a very common problem. I tried whereis command on that file and it gives me a location
/usr/local/bin/composer
I tried running chmod -R 777 on that file but it did nothing. I don't know what else to do.
Composer was installed on my machine with the following command
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
I thought composer.json only comes with projects, but I shouldn't need an existing project in order to simply set up the Laravel Installer right?
I had the same problem and after reading this answer I solved it updating the .composer folder permissions:
sudo chown -R $USER:$USER /home/$USER/.composer
Where $USER is your machine's username.
Update: As #Lucas Bustamante pointed, you don't need to change $USER for your username, its an environment variable already.
As Ian Warner commented out, is not a good idea to run composer as sudo user, because it can lead to security issues.
usr/local/bin/composer composer global require "laravel/installer"
usr/local/bin/composer composer create-project --prefer-dist laravel/laravel myblog
I think this may solve your problem as it did for me.
I made a bash file for the whole process of global installation of Laravel.
download it from here, open a terminal in the bash file directory and run the command below:
bash Laravel_Global_Installer.sh
This bash file manages installations of:
Latest version of PHP and its extensions
Latest version of Composer (Global)
Latest version of Laravel (Global)
This will help you install Composer Globally and without sudo. Therefore you will be able to install Laravel Globally.
first run whereis composer then
navigate to the that directory and run
sudo chown -R $USER:$USER / composer
use sudo before the command,
for e.g.: sudo composer global require "laravel/installer"
I followed the documentation on https://getcomposer.org/doc/00-intro.md#globally to install composer globally on arch linux. When I do composer self-update, I get this message:
[ErrorException]
rename(/home/hannes/.composer/cache/composer-temp.phar,/usr/local/bin/composer): Permission denied
The permissions in /usr/local/bin/ (I changed them to 777, but it did not help):
-rwxrwxrwx 1 hannes users 1104202 30. Mai 18:07 composer
In my home directory I did this:
sudo chmod -R 777 .composer/
In /etc/php/php.ini, the open_basedir looks so:
open_basedir = /srv/http/:/home/:/tmp/:/usr/share/pear/:/usr/share/webapps/:/usr/local/bin/
I also tried sudo composer self-update but it did not work as well and is possibly not the right way. (?). What else could I try to make this work?
On Ubuntu server >= 16.04
FIRST
sudo rm /usr/local/bin/composer
AND
cd ~/.cache/composer
chmod 755 composer-temp.phar
sudo mv composer-temp.phar /usr/local/bin/composer
this might be the case if you have downloaded composer.phar directly ,
but not by running php composer-setup.php
make composer.phar executable with following command before moving it to /usr/local/bin/composer or after moving
sudo chmod 755 composer.phar
composer-setup.php will make this change for us by default
You should check the permissions of the directory /usr/local/bin/, not just the file within. The process has to write both, the file and into the directory which both must be granted.
Apart from that, a general hint: do not always set everything to 777. There is no reason for that and it makes your system vulnerable.
According to the line you posted in the last comment the directory is currently writeable only for the root user himself. That would explain the error you get. You should not make your own user account the owner, Linux systems are multi user environments. Instead think about one of these approaches:
add the account that is meant to execute the composer to the group root (a user account can belong to several groups) and make the directory group writeable
change the groups ownership of the directory to a group that account is a member of and make the directory group writeable
use the sudo utility to install and update the composer utility
The last option is the typically chosen and preferred one. It leaves permissions as they are (conservative) and only uses raised privileges for system maintenance jobs like installation and upgrade.
Use sudo command for any command which writes to root files of folder. It worked for me.
use sudo "your command"
Even after moving the file via sudo mv composer.phar /usr/local/bin/composer I was getting a permission error when trying to run the composer command. sudo chmod 755 /usr/local/bin/composer fixed things for me.
You could temporarily add the rights to your working user, then update composer w/o errors and then get back the rights.
sudo chmod 777 /usr/bin/
composer self-update
sudo chmod 755 /usr/bin/
Now, there is a package for composer in arch linux which works for me:
sudo pacman -S composer
This did the job for me on Centos 7
chown -R apache:apache path/to/composer
chmod 755 path/to/composer
make sure composer already at /usr/local/bin and then do following things
chmod 755 composer
if permission denied, add sudo
For those who are using shared server here are the steps.
Let's first download composer file.
cd ~
curl -sS https://getcomposer.org/installer | php
Now we can access composer by:
~/composer.phar
Assuming you have /public_html in root directory, here are the steps to use latest composer.
cd public_html
~/composer.phar update
In future, if you want to update composer:
~/composer.phar self-update
Hope this is helpful.
My solution on macOs was the following:
First delete the directory yo created. Somehing like '/usr/local/bin/composer' using this command: rmdir /usr/local/bin/composer.
Now try to install composer again using Homebrew :
Step 1: brew install composer.
Step 2: brew link composer.
Now you can run composer in terminal.
For composer 2
sudo composer self-update --2
For composer 1
sudo composer self-update --1
if permission denied you should use the command with sudo like:
sudo composer self-update
This is going to be easy one I guess. On my OS X - Yosemite I have copied composer.phar to my /usr/bin directory. I have been using it for a while but today I needed to run "composer update". It didnt work of course so I ran "sudo composer update". Then I got the message "command composer not found". Chmm
I copied composer to /usr/local/bin according to the documentation and now "sudo composer" works like charm. BUT when I run "composer" without sudo, it still uses the old one in "/usr/bin" directory. So I deleted it.
Now composer works only with sudo command. I get "Could not open input file: /usr/bin/composer.phar" otherwise. What should I do to point command "composer" to the new location in /usr/local/bin?
Another alternative to get a nice composer command instead of composer.phar:
$ curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin
$ ln -s /usr/local/bin/composer.phar /usr/local/bin/composer
Edit:
/etc/bashrc
Add this to that file:
alias composer="php /usr/local/bin/composer"
run:
source /etc/bashrc
Composer should now run without sudo.
Okay, I encountered issues of having to run composer commands with sudo as well, but in order to get it working without throwing this kind of error (in Ubuntu 15.10):
[ErrorException]
copy(/home/randomuser/.composer/cache/files/barryvdh/laravel-cors/056068736ff8f002514178e1416c7665732eaddc.zip): failed to open stream: Permission denied
What simply solved the issue for me is:
Navigating to my home directory $ cd
Changing the ownership of .composer with: sudo chown -R $USER:$USER .composer/
Then composer install works smoothly.
PS: this might be different for other situation.
Hope this helps :)
i will answer you how i solve it in my Ubuntu 16.10 and you can compare yours
my composer folder set in
/home/abdallah/.composer/
i only give this file the 777 permission so can be reached by any user group
sudo chmod -R 777 /home/abdallah/.composer/
and that is it
i hope this helpful for you
Judging from other answers it seems the solution can vary depending on your system. This is how I fixed the problem on Mac 10.12.
My composer executable in /usr/local/bin/composer had a different group than ~/.composer/ config and cache files.
/usr/local/bin/composer myusr admin
~/.composer/ myusr staff
The primary group for myusr is staff so I changed the group for /usr/local/bin/composer to staff.
/usr/local/bin myusr$ chgrp staff composer
Cache files that had been created when running composer as sudo in the past were still causing problems so I deleted those. Composer cache files are located here: ~/.composer/cache/
If updating hangs during composer update for a project check/empty cache files in the .composer directory for the project.
This is kind of a n00b question, but I'm a much better developer than a sys admin.
Im setting up an Amazon Linux instance on EC2 and can't seem to get php 5.5 with mcrypt installed. yum seems to throw php 5.3 at me each time i try to do a group install or just as a dependency of mcrypt.
Any suggestions? This is for a Laravel 4.1 application.
Thanks!
If you are using amazon linux, you will need to install the php packages that start with php55.
Older packages are kept for compatability.
Since start configuring an EC2 instance can be tricky and indeed there is not much available support or documentation at the date I'm writting this answer, I'll post the steps I followed that worked for me. So I hope it will be useful to someone else:
Start an EC2 instance as described on the AWS documentation. Do not use elastic beanstalk for deploying your php app.
Start you PuTTY session, it is well described on the AWS documentation.
When PuTTY session is on, install in the following order: apache server (v 2.4), php55, php55-mcrypt, php55-pdo and mysql55
sudo yum install httpd24
sudo yum install php55
sudo yum install php55-mcrypt
sudo yum install php55-pdo
sudo yum install mysql55
Check your server properly working sudo service httpd start. If succesfully installed, you'll see 'OK' and you should be able to see a sample page in the public DNS.
Add a group in order to allow "ec2-user" modifying and writing files inside var/www/html
sudo groupadd www
sudo usermod -a -G www ec2-user
Exit PuTTY and reenter again (so changes will be applied) exit
Reconnect and check membership
groups
Modify permissions on writing and editing files
sudo chown -R root:www /var/www
sudo chmod 2775 /var/www
find /var/www -type d -exec sudo chmod 2775 {} +
find /var/www -type f -exec sudo chmod 0664 {} +
Test your server
echo "<?php phpinfo(); ?>" > /var/www/html/phpinfo.php
sudo service httpd restart
visit http://publicdomain/phpinfo.php. If properly working (it should) it will display the php info page.
All these steps worked well for me after hours dealing with php versions that are not compatible with laravel 4.1>=