Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Seydina's avatar

Upgrade Laravel From 10 to 11 : composer self-update issue

I installed composer globally, my laravel app in var/www/html which is served via an apache virtual host. All works fine. Before following upgrading steps, I want to update composer first to the latest version (my current composer version is 2.6.3) with this command composer self-update which give me this error :

Filesystem exception:                                                                                       
  Composer update failed: "/usr/local/bin/composer" could not be written.                                     
  rename(/home/myUser/.cache/composer/composer-temp2814960.phar,/usr/local/bin/composer): Permission denied 

I read in some articles that this issue can be solved with this command sudo composer self-update but may cause some security risks so I am a bit confused about how to proceed.

Another thing I want to know is : should we install laravel in apache folder var/www/html and execute composer within it using sudo without any security risks?

My Tech Stack : 
APACHE : v2
UBUNTU : 22.04 LTS
PHP : 8.3
COMPOSER : 2.6.3
LARAVEL : v10.44.0
0 likes
4 replies
s4muel's avatar

i would run sudo composer self-update (with sudo), because it really needs to write to a /usr/local/bin folder. or remove it ( sudo rm-rf /usr/local/bin/cpmposer) completely and start from scratch https://getcomposer.org/doc/00-intro.md#globally (read about permissions and sudo and local executables in that short documentation section)

to the second question: i would not install composer packages (composer instsall) with sudo (root user). not because security risks, but probably some file permissions, because all of the vendor files but also some of the auto-generated files will be created by root and you (or apache/webserver) wont be able to change/update them or write to some folders created during by the composer installation). run under your local user for your local project and as some user that runs webserver (www-data or similar) on production

Seydina's avatar

@s4muel In the docs you posted, this part tell me this :

If you like to install it only for your user and avoid requiring root permissions, you can use ~/.local/bin instead which is available by default on some Linux distributions.

What it means in my opinion that to avoid using root permissions with composer, you should move composer.phar file in ~/.local/bin is it not? In that case (moving composer.phar file in ~/.local/bin and making it executable), where to place my Laravel app directory ? (in var/www/html always or not?)

s4muel's avatar
s4muel
Best Answer
Level 50

@Seydina yes you can. if your scenario is to develop locally and run your compose, for yourself, this could be the way. composer is simply an executable you want to run. if it exists in /usr/bin (or /usr/local/bin or whatever your distro uses), anyone on that computer can run the composer command. but it needs to be installed with root permissions (i dont see anything bad with this approach, just list the /usr/bin directory and there are multiple commands available owned by root)

but in any case you dont want that, you can alternatively put it in ~/.local/bin, which is the place to put executables just for your own account. the placement of laravel app directory is not important in this context. because you could run composer install from anywhere (if installed according to our previous messages/documentation, of course).

/var/www/html is probably most common, but again, this depends on your preference, whether you have multiple projects, web-server (if using) just must be configured to serve files from that directory. but this is another topic

Please or to participate in this conversation.