Where can I find WP_CONTENT_DIR in Wordpress structure? - php

I am using Query Monitor plugin, but it didn't create db.php symlink in path/to/wordpress/wp-content/db.php, even if I changed permission of the wp-content folder. My changing permission is restricted to one folder or file each time.
I can't do Linux nor Windows command-line queries. There is only one db.php inside query-monitor folder.
This is a quote from Query Monitor plugin:
When Query Monitor is unable to symlink its db.php file into place
Occasionally PHP won't have the correct permissions to put this
symlink in place. Query Monitor will still work fine in this
situation, but you won't see extended information that makes Query
Monitor much more useful.
You can manually create the symlink by running the following command
on the command line:
Linux / OS X:
ln -s
/path/to/wordpress/wp-content/plugins/query-monitor/wp-content/db.php
/path/to/wordpress/wp-content/db.php
Windows (requires administrator privileges):
mklink C:\path\to\wordpress\wp-content\db.php
C:\path\to\wordpress\wp-content\plugins\query-monitor\wp-content\db.php
> Alternatively, you can relax the file permissions on the
WP_CONTENT_DIR directory and then de-activate and re-activate the
plugin and it'll attempt to create the symlink again.
Changing query-monitor or wp-content folder to 777 and de-activate + re-activate plugin has no effect. I don't think I can change permissions in phpMyAdmin, but no idea if I can or not on a table, and no idea how to find and change permissions on that table neither.
Is WP_CONTENT_DIR a php file or line in a file or a table or something else and where is it?
In case it's a line in a php file, how can I change permissions on a php line ?

After many tries, I found out. One thing important: needs a path that begins with /home and can't be done offline else you'll get a conflict because it points to your computer.
No need to download nothing.
Cpanel may have Cron Jobs, which allows one linux bash shell command line as seen in this article (they don't host me). SSH client can also do this but it's more complicated.
Go to Advanced then Cron Jobs then set Once per minute:
ln -s /home/YOUR_HOST_USER_OR_ID/public_html/YOUR_BLOG_FOLDER/wp-content/plugins/query-monitor/wp-content/db.php /home/YOUR_HOST_USER_OR_ID/public_html/YOUR_BLOG_FOLDER/wp-content/db.php
Refresh till file is created, then delete Cron Job immediately after, to avoid repetition x2 on the 2nd minute.
So like that you avoid both errors:
Extended query information such as the component and affected rows is not available. Query Monitor was unable to symlink its db.php file into place. See this wiki page for more information.
Extended query information such as the component and affected rows is not available. A conflicting db.php file is present. See this wiki page for more information.

Related

How can I delete the hidden .svn folder on my local working copy using php on a remote server? Unlink() permission denied

My SVN repository contains multiple projects. Each project contains the same structure that looks like trunk -> doc -> log.txt. This log file contains the changes made between revisions.
Currently I created a php script that executes when a server build is run. This php script checks out log.txt file on the server's local directory. C://..../..../doc/log.txt.
It writes into this file and then commits the changes. The problem occurs when someone runs the server build with another project. It tried to check out the log.txt file of that project into the same directory and I get an svn error. I no longer need the checked out files in the local directory once the changes have been committed. The only option I could think of is to delete the doc folder (only in my local directory not the repo) before checking out the new one so that the previous log.txt is no longer there.
I found a recursive algorithmthat deletes all files with unlink() and directories with rmdir. The algorithm works well. Unfortunately, the hidden .svn files do not unlink() with permission denied errors. Using fileperms() on all files and parent directories gives back 16895 which translates to 40777 in octal, so I believe they have full permissions. But I believe permissions for users do not have modify/write. Is there a proper way to delete the hidden .svn folder on my server's working copy? Alternatively if anyone can think of a better method to do this. So if AprojA/doc/log.txt is already in the local directory and I check out BprojB/doc/log.txt. Is there a way to checkout and overwrite the existing log.txt with the log file from another project? --force parameter doesn't seem to do much for me.
I also had a vague idea of maybe checking out the top level svn repo with -depth=empty. and then svn update just the log txt files of each project. So instead of checkingout -> committing changes -> deleting. I can just have all log.txt files available. But the problem is they all have the same folder and file name of (doc/log.txt). Still relatively new to all this so I'd appreciate feedback of any kind.
u can use wild cards to delete the log files with the extension. so all files of the same extension will be deleted under the selected folder.

Clearing cache manifest via CLI

I've automated the deploying of my site and I have a script that runs framework/sake /dev/build "flush=1" This works however it clears the cache directory of the user who runs it, which is different from the apache user (which I can't run it from).
I've read a few bug reports and people talking about it on the SS forum however either there is no answer or it doesn't work for example
define('MANIFEST_FILE', TEMP_FOLDER . "/manifest-main");
I thought about just deleting the cache directory however it's a randomised string so not easy to script.
Whats the best way to clear the cache via command line?
To get this to work you need to first move the cache from the default directory to within the web directory by creating a folder silverstripe-cache at the web root. Also make sure the path is read/write (SS default config blocks this being readable by the public)
Then you can script:
sudo -u apache /path/to/web/root/framework/sake dev/build "flush=1"

XAMPP SQLite DB using PHP, Can't get to insert [duplicate]

I have a SQLite database that I am using for a website. The problem is that when I try to INSERT INTO it, I get a PDOException
SQLSTATE[HY000]: General error: 8 attempt to write a readonly database
I SSH'd into the server and checked permissions, and the database has the permissions
-rw-rw-r--
I'm not that familiar with *nix permissions, but I'm pretty sure this means
Not a directory
Owner has read/write permissions (that's me, according to ls -l)
Group has read/write permissions
Everyone else only has read permissions
I also looked everywhere I knew to using the sqlite3 program, and found nothing relevant.
Because I didn't know with what permissions PDO is trying to open the database, I did
chmod o+w supplies.db
Now, I get another PDOException:
SQLSTATE[HY000]: General error: 14 unable to open database file
But it ONLY occurs when I try to execute an INSERT query after the database is open.
Any ideas on what is going on?
The problem, as it turns out, is that the PDO SQLite driver requires that if you are going to do a write operation (INSERT,UPDATE,DELETE,DROP, etc), then the folder the database resides in must have write permissions, as well as the actual database file.
I found this information in a comment at the very bottom of the PDO SQLite driver manual page.
This can happen when the owner of the SQLite file itself is not the same as the user running the script. Similar errors can occur if the entire directory path (meaning each directory along the way) can't be written to.
Who owns the SQLite file? You?
Who is the script running as? Apache or Nobody?
For me the issue was SELinux enforcement rather than permissions. The "read only database" error went away once I disabled enforcement, following the suggestion made by Steve V. in a comment on the accepted answer.
echo 0 >/selinux/enforce
Upon running this command, everything worked as intended (CentOS 6.3).
The specific issue I had encountered was during setup of Graphite. I had triple-checked that the apache user owned and could write to both my graphite.db and its parent directory. But until I "fixed" SELinux, all I got was a stack trace to the effect of: DatabaseError: attempt to write a readonly database
This can be caused by SELinux. If you don't want to disable SELinux completely, you need to set the db directory fcontext to httpd_sys_rw_content_t.
semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/railsapp/db(/.*)?"
restorecon -v /var/www/railsapp/db
I got this error when I tried to write to a database on an Android system.
Apparently sqlite3 not only needs write permissions to the database file and the containing directory (as #austin-hyde already said in his answer) but also the environment variable TMPDIR has to point to a (possibly writable) directory.
On my Android system I set it to TMPDIR="/data/local/tmp" and now my script runs as expected :)
Edit:
If you can't set environment variables you can use one of the other methods listed here: https://www.sqlite.org/tempfiles.html#temporary_file_storage_locations
like PRAGMA temp_store_directory = 'directory-name';
In summary, I've fixed the problem by putting the database file (* .db) in a subfolder.
The subfolder and the database file within it must be a member of the
www-data group.
In the www-data group, you must have the right to write to the
subfolder and the database file.
####### Additional Notes For Similar Problem #####
I gave write permissions to my sqlite database file to other users and groups but it still didn't work.
File is in my web root directory for my .NET Core WebApi.
It looked like this:
-rw-rw-rw- 1 root root 24576 Jan 28 16:03 librestore.db
Even if I ran the service as root, I kept getting the error :
Error: SQLite Error 8: 'attempt to write a readonly database'.
I also did a chown to www-data on the librestore.db and I still received the same error.
Finally I moved up above my webroot directory and gave others write access to that directory (LibreStore - the root of my WebApi) also and then it worked.
I'm not sure why I had to give the directory write access if the specific file already had write access, but this is the only thing that worked.
But once I made that change www-data user could access the .db file and inserts succeeded.
I got the same error from IIS under windows 7. To fix this error i had to add full control permissions to IUSR account for sqlite database file. You don't need to change permissions if you use sqlite under webmatrix instead of IIS.
I used:
echo exec('whoami');
to find out who is running the script (say username), and then gave the user permissions to the entire application directory, like:
sudo chown -R :username /var/www/html/myapp
(For followers looking for an answer to a similar question)
I'm building a C# .Net Core 6.0 WPF app. I put the Sqlite.db3 on the c:\ drive for convenience while developing. To write to the database I must open Visual Studio 2019 as Administrator.
#Charles in a comment pointed out the solution to this (or at least, a botch solution). This is merely me spelling it out more clearly. Put file_put_contents('./nameofyourdb.sqlite', null); (or .db, whichever you fancy) in a .php file in the root directory of your app (or wherever you want the db to be created), then load that page which renders the php code. Now you have an sqlite db created by whichever user runs your php code, meaning your php code can write to it. Just don't forget to use sudo when interacting with this db in the console.
A good clean solution to this is to allow the file of your main user account to be written to by (in my case) the http user but this worked for me and its simple.
None of these solutions worked for me and I suppose I had a very rare case that can still happen. Had a power shortage so even with 777 permissions on folder and db file, without SELinux, I would get this error.
Turns out there was a jellyfin.pid file (not sure if it's named after the service or user as they have the same name) locking it after the power shortage. Deleted it, restarted the service and everything worked.
I got this in my browser when I changed from using http://localhost to http://145.900.50.20 (where 145.900.50.20 is my local IP address) and then changed back to localhost -- it was necessary to stay with the IP address once I had changed to that once

Permission denied mkdir for cron and browser

We have an PHP XML parsing script that uploads photos to a folder structure like /content/images/2012/05/31/%object_id%/. This parser runs primarily as a DirectAdmin cronjob. We run into many problems getting the folder permissions right to enable the uploading in that directory for both the cronjob as running the parser via the browser.
According to print_r(posix_getpwuid(fileowner($directory))); the owner of the directory is is the same as get_current_user(). Nevertheless I receive: Warning: mkdir() [function.mkdir]: Permission denied when running the script via the browser. It works fine when running it as a cron job.
All folders have chmod 0777 and new folders are created as such;
mkdir($path,0777,true);
Naturally we have the same permission problems with uploading and/or deleting the files themselves.
Is there any way to enable all the file actions running both as a cron job and through the browser?
We are running Linux with PHP Version 5.2.17.
Couple of thinks to note: get_current_user gets the owner of the .php file (i.e. the script) but NOT the name of the user that is running the php script. Invariably these are different as the file will be uploaded by you (a regular user) and php/apache will run as a different user (often called "apache" or "www".) You need the latter of these two. suggested snippet from the php manual to get this is:
$processUser = posix_getpwuid(posix_geteuid());
print $processUser['name'];
(http://php.net/manual/en/function.get-current-user.php - see comments)
To solve you current problem, though, my strong suggestion is to run the cron as the same user that the php/apache is running as (check man page on crontab) - the user should be the one in that snippet above, CHOWN the files and directories to that same user (they will currently be root) and to a group that is shared between you and the FTP client. Then make sure the user and group have read+write permissions so you can also edit from ftp. Make sure you change permissions on both directores (775) and files (644) as your script creates them.
Also note that if you mkdir(), then the directory above must also have write permissions for the user (and this might actually be your initial problem, and why only root/cron can write there).

rename() PHP function cannot find directory even though it is there?

I have just created a new folder on my server, and all the right permissions are set, I am sure of it.
The folder is there, but my PHP cant find the actual folder anyways?
Any ideas why?
The only thing I can think of is that my folder has special characters in its name.
I create it with this command:
sudo mkdir "Textiler & Sybehör"
I have lots of other directories with these kind of characters and they work fine.
Just this one seems to not work...
I am stuck!
PHP says cannot find directory...
UPDATE:
In command line tool, I tried moving the dir like this:
mv "Textiler & Sybehör" images/"Textiler & Sybehör"
I get this error:
cannot stat `Textiler & Sybeh\366r': No such file or directory
It is like if the letter "ö" isn't interpreted correctly.
When you make a directory with sudo that means it is created as the super or root user. If your web server is using suexec and running PHP as a normal user, PHP will not be able to access folders and/or files owned by other users.
Check to see if suexec is being used by or on your hosting provider or server.
The other thing is to determine if your folder really needs to be owned by the root user. If not, use the following command to change the owner: sudo chown <regular_user>:<regular_user> where <regular_user> is the account that PHP is running as.
Although it might be because of the characters in the name. What about folder structure? Do you have an .htaccess file with a rewrite base set? Code snippet would be great.
Also may as well check ownership permissions (chown) and then chmod the folder so it's writable.

Categories