How can stop Homebrew installing Postgres as root? - ruby

I have a Postgres permissions problem, every time i brew install postgres it does so as root user resulting in permissions denial on initdb, createdb and or anything else i try.
I sudo chown the ownership of /usr/local/var/postgres and it seems to change and allow me manual entry into the directory from cmd line, which then only consists of a server.log file listing the error:
postgres cannot access the server configuration file "/usr/local/var/postgres/postgresql.conf": No such file or directory
I then go to initdb and it returns:
The files belonging to this database system will be owned by user "jamesbkemp".
This user must also own the server process.
The database cluster will be initialized with locale "en_GB.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".
Data page checksums are disabled.
initdb: directory "/usr/local/var/postgres" exists but is not empty
If you want to create a new database system, either remove or empty
the directory "/usr/local/var/postgres" or run initdb
with an argument other than "/usr/local/var/postgres"
I then go back to look at /usr/local/var/postgresand the owner has changed back to root. I really am at a loss after many hours on this as to what's going on. Any ideas folks?

Postgresql install as non root is a pain if not impossible, because it was not designed this way: it is a multi-user service.
The same thing here: apache2 as non-root - you would have to build the server yourself changing the configuration a lot.
Let me add that for an experienced datacenter operator this is a strange idea, like driving a race car in your appartment.

Related

How can I get the Laravel 7 Homestead database snapshots working?

I've enjoyed Homestead for years and today noticed a very appealing feature that I've never used before.
https://laravel.com/docs/7.x/homestead#database-snapshots says:
Homestead supports freezing the state of MySQL and MariaDB databases
and branching between them using Logical MySQL Manager. For example,
imagine working on a site with a multi-gigabyte database. You can
import the database and take a snapshot. After doing some work and
creating some test content locally, you may quickly restore back to
the original state.
...
A common workflow looks like the following:
Import a database into the default master lmm branch.
Save a snapshot
of the unchanged database using sudo lmm branch prod-YYYY-MM-DD.
Modify the database.
Run sudo lmm merge prod-YYYY-MM-DD to undo all
changes.
Run sudo lmm delete <branch> to delete unneeded branches.
This tool sounds really useful, but I'm having trouble following those instructions. Here is what I've tried and the results:
sudo lmm status
Active snapshot:
Database snapshots:
master
2.70% used by MySQL databases.
sudo lmm branch beforeImports
df: '': No such file or directory
Logical volume name "" is invalid.
Run `lvcreate --help' for more information.
mount: /homestead-vg/beforeImports: special device /dev/homestead-vg/mysql-beforeImports does not exist.
mount: /homestead-vg/beforeImports: special device /dev/homestead-vg/mysql-beforeImports does not exist.
mount: /homestead-vg/prod-YYYY-MM-DD: special device /dev/homestead-vg/mysql-prod-YYYY-MM-DD does not exist.
mount: /homestead-vg/beforeImports: special device /dev/homestead-vg/mysql-beforeImports does not exist.
sudo lmm checkout master
is the currently active database.
Setting /homestead-vg/master as the active database.
rm: cannot remove '/var/lib/mysql': Is a directory
ln: failed to create symbolic link '/var/lib/mysql/master': File exists
I'm using: Windows 10, Vagrant 2.2.7, Virtualbox 6.1.2, Homestead v10.2.0.
What am I doing wrong?
P.S. I looked at https://github.com/Lullabot/lmm/blob/ubuntu-18.04/functions.sh#L5 (which I think is what Homestead is using), and then I ran sudo echo `readlink /var/lib/mysql`, and it printed a blank line. But sudo ls -lah /var/lib/mysql shows lots of files. I clearly don't know what I'm doing and would appreciate any help.
P.P.S. I also see https://github.com/laravel/homestead/issues/1112 but do not understand.
There was a bug that prevented LMM from working with MySQL 8: https://github.com/laravel/homestead/issues/1383

How to allow creation of database triggers

When trying to install CiviCrm in Drupal 7 I get "Could not create a database trigger".
Using a standard ddev config.yml for drupal7.
A couple of solutions are suggested at https://civicrm.stackexchange.com/questions/2770/database-trigger-error-message but I am struggling to implement them within ddev.
RE Grant - When I try ddev exec mysql GRANT..... I get failed to execute command. When I ssh into a mysql shell to try to grant privileges I get access denied for user.
RE log_bin_trust_function_creators = 1. Where would I insert that?
Update 2019-01-25: I went to check this out after you created the issue and what I suggested was inadequate. As explained there, you need to do a little custom config. Create a .ddev/mysql/trigger.cnf with these contents:
[mysqld]
log_bin_trust_function_creators=on
And the next release of ddev (mid-February) will make this the default (PR). So please report your results there. I was able to install CiviCRM with this mysql config.
Original response: True but not adequate for triggers:
The db container root user has full privileges, so you can use mysql -uroot -proot ... to do what you need to do. You can do that inside the db container ddev ssh -s db or inside the web container ddev ssh or from the host using the info in ddev describe (but using root/root). (You can also use the root user to grant additional privileges to the db user, of course.)
If you know what privileges are required, we should add them to the db user, so please make an issue requesting what you need, because we'd like this to be easier for you.

EC2 AMI instance is resetting folder permission everyday

I have a log folder /var/www/app/logs/ in an EC2 AMI instance. My PHP aplication is writing logs there, however every day I must logon and do chmod in order to avoid the error message that the folder is not writable:
$ sudo chmod 7777 -R /var/www/app/logs/
For some reason the instance this permissions are reset every morning automatically by some unknown process. Is there a way to make this change permanently?
My guess is that you have some log rotation rules set up for this directory, which might be responsible for the permission change.
And, don't set the permissions to 777, definitely. Either change the owner of the directory to your application user, or add your application user to a group which has write permission to the directory.
Not sure whether is the best solution, but solves my problem. Edit the /etc/httpd/conf/httpd.conf file and change:
User apache
By:
User ec2-user
Then restart the webserver.

ftpd can't change root directory when connecting as a non-root user

I have an embedded system running linux and I have busybox installed for running different services. One of the services is ftpd, which I start like this from the etc/init.d/rcS file:
tcpsvd 0.0.0.0 21 ftpd -w -v /mnt/flash&
I have two users in the system, root and a regular user. Root user can easily connect to the FTP server, but when I try to login with the regular user's credentials, I get this error:
ftpd[678]: can't change root directory to '/mnt/flash': Operation not permitted
Now, I thought that it must be a directory permission problem, and I started with changing permissions on the /mnt/flash directory first, but after this didn't work, I ended up having all my files in file-system including / to be owned by this regular user and have drwxrwxrwt permissions (just to find the cause of the problem). But I still get this error.
I have also tried to start ftpd with different root folders, including /.
I also couldn't find any config files for the ftpd in my file-system, maybe I need to create one manually? If so, which one and how to tell ftpd to allow user logins?
I'd really appreciate any help. Thanks.
Well, after trying some random things, I discovered that user login works fine if there is no directory changing involved at all:
tcpsvd 0.0.0.0 21 ftpd -w -v &
I suspect that chroot is called otherwise and the user does not have a right to do that.

shell logged in as root yii file permissions - pain

Based on a recommendation on stack overflow, i am giving yii framework a spin.
It appears that I am only able to gain shell access to my web server if I log in as root.
I am running through the tutorial, and am having a number of problems typical command to create a web app-
/usr/local/bin/php /home/testuser/public_html/yii/framework/yiic webapp /home/testuser/public_html/demo
Do I have to type /usr/local/bin/php EVERY TIME???
Do I have to type /home/testuser/public_html/yii/framework/yiic in full every time???
Do I have to yype /home/testuser/public_html/demo in full?
As I am logged in as ROOT, I have to chown every file / folder created by root to make the file viewable by testuser!!!
I create a new controller using yii. controller message helloWorld, yii does some funky stuff, but I can't do ANYTHING with the files without chown EVERYTHING!!!
I'm not too confident with SSH, and I know it's all a learning curve, but... having to change file permissions EVERY time, and having to type full directories every time is just a pain.
I know that there are some shortcuts that I will probably learn with time, but if anybody could give me some pointers to make my life about 1M times easier (considering my main objectives at present are to learn yii framework) linux/terminal/shell commands are currently secondary to my requirements.
Here's what I'd do, in this order:
1 - When you login as root issue the command su - testuser. This changes your effective user id and groupid to that of testuser, meaning, you now are operating as that user account. Your current directory should now be the testuser's home directory. To get back to root user just type exit.
2 - Try running php -v without the fullpath. If it prints out a version number then you don't have to use the fullpath to run php. If you get an error then you can add /usr/local/bin to your PATH environment variable in your .profile file which is present in testuser's home directory. If the .profile doesn't exist then you can create it.
3 - Add /home/testuser/public_html/yii/framework to your PATH in testuser's .profile.
After doing all that then the next time you login as root you would be able to do the following:
su - testuser
cd public_html
php yiic webapp demo
And you wont have to worry about permissions since you are creating directories/files as testuser, not root.
See also: StackOverflow question about modifying your PATH

Resources