I've newly started to use Laradock to build my Laravel projects but I have a problem in editing the files such as Controllers, Models, etc which are made by the php artisan command in the Laradock workspace. The reason is the user in the workspace is a root and on the other side, I'm trying to edit the file in my editor by a common user. So every time I have to run the command chmod -R 777 /newCreatedFile.php to change the permission. So is there any solution to handle this problem?
By the way my OS is ubuntu 18.04
In the Laradock Getting Started guide, it explains how to get Laradock running as a specified user:
Note: You can add --user=laradock to have files created as your host’s user. Example:
docker-compose exec --user=laradock workspace bash
I believe this should solve your issue, as you will no longer have the Docker user running these commands. Try it out!
Note: The core issue may just be that whatever user Laradock is running as is not creating files with group permissions that allows the host machine's user write capabilities, hence why the --user flag can be used. It may not actually be running as the root user itself.
Related
I am having a hard time trying to figure out the issue.
I am creating a Model using this Artisan command,
Artisan::call('make:model',['name' =>'Models\\'.$module.'\\'.$model_name]);
For whatever reasons,
1.there is a lock icon in the file
2.owner of the file is www-data
3.the permission for the file is 644 but when I create the Model from CLI the permission of the file is 757.
It all depends who runs the code, in this case web-server runs the code, thus Apache or NGINX is the owner of newly created file (same goes for uploads).
You can change this using
umask
change user/group of web-server
Best option is to use artisan as its meant to be used, from command line.
We moved a Laravel 5.6 Installation from a Windows to a UNIX Webserver. I manage my laravel over the CLI via Putty and develope from my Windows Machine using a Network Path.
I have a strange Problem and just cant find any solution for this, since im also new to Unix/Linux.
When i run a php artisan create command, it works all just fine. Laravel creates the Migration. But i cant edit the Files on my Windows Machine since i got no Permission.
On older Files that was previously generated on my Windows machine, the Right Window on Windows looks like this:
Anyone Read
www-data (Unix User\www-data) Read/Write
www-data (Unix Group\www-data) Read/Write
The rights on the freshly generated Artisan File looks like these. I already added my Unix User to the www-data group.
Anyone read
pm (Unix User\pm) read/write
www-data (Unix Group\www-data) read
I dont know, why the www-data Group dont have read/write Permissions on freshly generated Artisan Files.
I guess you need to change the umask of the user under which artisan is run.
So, go to the root home directory of that user (I guess /home/pm) edit the file ".bashrc" (or create it doesn't exist) and add this line:
umask 2
which is like "when this user create a new file or directory, make it readable and writable for him or users in his group, but only readable for other users"
More info about umask here: https://www.cyberciti.biz/tips/understanding-linux-unix-umask-value-usage.html
I have just installed Laravel Homestead on my computer running Windows 10 and now I'm trying to create my first project with Composer.
I have cd:ed into the right folder called Code after doing vagrant ssh.
composer create-project laravel/laravel Project1 --prefer-dist
returns an error.
[ErrorException] mkdir(): Permission denied
Must be some kind of error with Composer permissions. How can I fix it?
In Windows 10 if you face some access problems you need to run the consoles and GIT BASH with Administrator rights only
In the "Homestead.yaml" file you can configure 777 permission via the following configuration.
"dmode=777" means all directory gets 777 permission and "fmode=777" means all file gets 777 permission on "code" folder.
folders:
- map: C:/Users/NEW/code
to: /home/vagrant/code
options:
mount_options: ["dmode=777","fmode=777"]
Ensure that the directory you are using is in the xampp folder. The error happens because you do not have write permission on your project folder. Check to ensure you are creating the project on the xampp folder because, regardless of you being the local admin, you may only have read permissions on some folders. You can right-click on the folder>properties>security tab on the users, click Add then add your username and assign them Full Control, click Apply. It may take some time to apply depending on the number of projects you have. After it finishes, you should be good.
PS: This is for Windows users and I sorted this out using the same process.
I solvet it temporarily with a solution that I'm not fully satisfied with, but at least it works.
sudo chmod 777 code-folder-name
Did this in the vagrant root folder.
I'm new to Laravel and I find this framework awesome.
Artisan is also great but a have a little problem using it.
Let's say that I create a new Controller with Artisan like this
php artisan make:controller Test
There will be a new file in app/Http/Controllers named Test and the permission on this file will be root:root
When I want to edit this file with my editor over ftp I can't because I'm not logged as root.
Is there any ways to tell Artisan to create files with www-data group for example (without doing an chown command) ?
Since you have root shell access, the following command will execute another one using the www-data user-
sudo -u www-data php artisan make:controller Test
Replace www-data with whatever the username your web server operates under, or the username you login to the FTP service with.
When you do this, the controller will be owned by www-data, which is what you want.
Note: do not ever run commands copy-pasted from the internet without knowing exactly what they do, especially in a root shell.
In this case, the -u parameter tells sudo to execute the command as a specific user, not as the root user.
From the manpage:
-u user, --user=user
Run the command as a user other than the default target user (usually root ). The user may be
either a user name or a numeric user ID (UID) prefixed with the ‘#’ character (e.g. #0 for UID
0). When running commands as a UID, many shells require that the ‘#’ be escaped with a backslash
(‘\’). Some security policies may restrict UIDs to those listed in the password database. The
sudoers policy allows UIDs that are not in the password database as long as the targetpw option
is not set. Other security policies may not support this.
I know this is a really old post but I'd also really advise anyone agains editing your Laravel files over FTP. I used to do this in my pre-Laravel days and it NEVER ended well.
Editing over FTP can have all kinds of problems- dropping connection mid-edit being the least of them. Security and live development errors being a much larger concern.
Develop on your local or dev environment, commit/push to git, then either pipeline to your server or handle your FTP uploads and cleanup after the fact. Pipelines are your best bet if your host will allow them. We use Atlassian BitBucket for ours but the set-up and deployment should be relatively similar for most hosts. Check with your host for documentation on their pipeline set-up:
https://www.atlassian.com/continuous-delivery/tutorials/bitbucket-pipelines
There's also some tutorials online for pipelining straight to FTP (if on a shared host, say):
https://www.savjee.be/2016/06/Deploying-website-to-ftp-or-amazon-s3-with-BitBucket-Pipelines/
It is because you ran a command from root user, try to run the command from the user which you using for edit the project via ftp.
Using Laravel Homestead to work with Laravel 4. After running vagrant up this morning, I was unable to access homestead.app:8000. I pinged it with no problem so I investigated my virtualbox and discovered that Nginx wasn't starting. I then attempted to view logs and I am denied permission from the /var/log/nginx directory which is owned by www-data adm.
My question then, what is the su or sudo password which would allow me to access that directory? The documentation is surprisingly void of any information as well as the Homestead.app Git repository. Thank you.
i had similar issue with laravel/homestead vagrant virtual machine and nginx not restarting. the error after running nginx -t was :
nginx: [crit] pread() "/etc/nginx/sites-enabled/sites-available" failed (21: Is a directory)
nginx: configuration file /etc/nginx/nginx.conf test failed
solution was to delete the symbolic link sites_available:
rm -Rf /etc/nginx/sites-enabled/sites-available
than it worked:
service nginx restart
elevate to root by typing sudo -s
A quick way to jump to a root account shell is to run the "sudo bash" command. That way, if you don't have to have to type "sudo" in front of each command. Since this VM is for development purposes I don't see it as a danger, but in real production Ubuntu runs with the root account locked down so you always go in and should stay in with user level privileges until you need to execute a higher level command. You "can" enable the root account and set a password, but jumping to it with sudo is the better method.
You can just look at the log using the root account password. So: sudo nano and then just enter your root user's password. A root is able to do anything on the system, so that always is a solution for this kind of problems.
If you forgot the root password, just search google to recover it.