Joomla Database Access Error - php

I used to have a working Joomla 3 site, but when upgrading Ubuntu from 12.10 to 13.10, I lost the OS. I've copied everything from /var/www and /var/lib/mysql and have the contents available.
I've placed the contents of /var/www onto my new system's Apache2 DocumentRoot, and can access the files. I've gone through and checked the configurations, but am stuck at the point of restoring my old MySQL database using the /var/lib/mysql files.
I've wrecked one system simply by 'scp /old_server/mysql root#roboserver.local:/var/lib' in which the mysql server failed every attempt to access. So instead I created a new database with the same name and copied everything 'var/lib/mysql/robo/.' over to that new server's database in that same location.
I need to know how to bring back an old Joomla database exactly as I had it. The current error I am getting is:
Error displaying the error page: Application Instantiation Error: Can't find file: './robo/robo_session.frm' (errno: 13) SQL=DELETE FROM `robo_session` WHERE `time` < '1399079287'
I'm 15yrs old, just started using SSH a month ago, so if you could give a step-by-step fix I'd appreciate it! I have complete physical and root access to every machine.

I've found the solution and am documenting it for anyone else with this specific problem.
When Joomla returned the error from the MySQL Database, it attempted to find the file by reading it. Running 'chown -R mysql:mysql /var/lib/mysql' set all the permissions back to normal, allowing the database to be read.
In my attempts to repair the databases, I neglected to check ownership of the files. (As I was logged in through SSH as root, yes, shame on me.)

Related

Can't write to a remote server location with PHP but I can browse and write to it in File Explorer?

Sorry if this a repeat of a question that has been asked before but I have not been able to find my exact situation. We are trying to migrate our website server from a Windows 10 VM (yes I know) to a Windows Server 2019 VM. We have some PHP on our site that writes files to some of our other servers on the same domain and have been able to do so without issue using file_put_contents like so:
file_put_contents("\\\\server\\folder\\folder\\folder\\".$filename, $file);
Now all of a sudden, to run the same code on our new server I get a Warning on this line, "Failed to open stream: Permission denied". I have permission to access this folder, I can browse to \server\folder\folder\folder and create a file there. I even tried mapping this server to a letter drive on my new web server, and still same error. I can put the file on the local C drive just fine but that's it.
Running fileperms on the folder path gives Warning: fileperms(): stat failed. Running is_writable on the folder path returns false, I just can't see how. Running it on the old Windows 10 web "server" returns true. I've read some things about needing to enable certain settings on the server you're trying to access, but I just can't think of what would allow one VM to access it and not another. Both VM's are logged in with the same user with admin rights. I can bring up the same folder in file explorer and write to it, just not via PHP. What obvious thing am I missing?
Thanks!
After weeks of banging our heads against the wall we finally figured this out. On our old web server, when right-clicking the website from the Sites file tree in IIS, under Manage Website -> Advanced Settings, the Physical Path Credentials field was set to the credentials needed to access these folders. On the new server it was blank. I'm not sure how this got missed but in any case, after entering the correct credentials here everything immediately worked.

Xampp install WordPress stuck on step2 installer

I'm installing WordPress through Xampp. I used to work with MAMP and it basically works the same way.
Normally I do everything manually as in copying the files and installing the database.
When loaded the famous "can't establish database connection" kicks in.
Now I thought this might have something to do with the fact that MAMP and Xampp have some minor differences. So I decided to use the WordPress installer.
After placing the files in XAMPP->xamppfiles->htdocs->customFolder I ran the installer.
Database is created in phpMyAdmin and I expect the installer to finish after adding the credentials. But nooooo. For some reason this sob keeps denying the wp-config.php to be created.
I quadruple checked every credential of the database. Have no idea on why step2 fails to install WordPress.
So I might think this is an port issue. I have also installed MAMP and it is running on port:8080. After setting xampp to port:8080 it gives me an error saying it can't bind to that port. Changed it to port:8666 but the same problem occurs.
Any thoughts or extra info?
---- UPDATE ---
So I created the wp-config.php manually and got these extra error messages.
All files in the htaccess folder have now file permission 777. This is merely for testing and would never happen in a live environment.
Warning: mysqli_real_connect(): (HY000/1045): Access denied for user 'root'#'localhost' (using password: YES) in /Applications/XAMPP/xamppfiles/htdocs/testing/wp-includes/wp-db.php on line 1531
There must be file permission issue, You must grand 777 rites to create wp-config file. chmod 775 wp-content/upload
Also note
All files should be owned by the actual user's account, not the user account used for the httpd process.
Group owneraship is irrelevant, unless there's specific group requirements for the web-server process permissions checking. This is not usually the case.
All directories should be 755 or 750.
All files should be 644 or 640. Exception: wp-config.php should be 440 or 400 to prevent other users on the server from reading it.
No directories should ever be given 777, even upload directories. Since the php process is running as the owner of the files, it gets the owners permissions and can write to even a 755 directory.
It sounds like a folder/file permissions issue rather than a port issue.
This question should help you solve the permissions on your xampp/xamppfiles/htdocs/customfolder
XAMPP permissions on Mac OS X?
When WordPress gives that error it's most often because it can't create the wp-config.php file due to insufficient write permissions.
I found the solution.
MAMP uses a user root and password root.
XAMPP in contrast to MAMP doesn't.
The user name is root but the password is empty.....
I faced this issue attempting to install within XAMPP and what solved it for me was to run XAMPP as administrator. This reflects other answers referring to permissions.
The other thing that can be an issue is XAMPP timing out on the install. One can modify their php.ini file within xampp to increase the max execution time. As they say "I hope this helps"
;;;;;;;;;;;;;;;;;;;
; Resource Limits ;
;;;;;;;;;;;;;;;;;;;
; Maximum execution time of each script, in seconds
; http://php.net/max-execution-time
; Note: This directive is hardcoded to 0 for the CLI SAPI
max_execution_time = 90
I had same issue using XAMPP 8.1.12 on WINDOWS 10;
Try installing an older version, in my case XAMPP 8.0.25 fixed the problem.

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

Why can't WordPress access the file system?

A client informed me that any time he tries to update a plugin, he gets an error:
To perform the requested action, WordPress needs to access your web server. Please enter your FTP credentials to proceed. If you do not remember your credentials, you should contact your web host.
I don't have FTPd setup on the server, but this seems like a basic permissions issue, right? I've never had to use FTP credentials to update any other WordPress installations.
Well, I did some reading and started messing with permissions and long story short, out of frustration, I eventually made everything writeable by everybody:
sudo chmod -R 777 src
But I'm still getting the same error. So it has to be some type of configuration issue, right?
I ran a few find . -exec grep commands to determine if there is a hard-coded document root (like in Joomla), but I came up empty handed.
Do I really have to install FTPd to be able to update WordPress from the admin interface?
Is there a config file somewhere that specifies the document root location?
Is there some other configuration option that I'm missing here?
Or maybe it's something in the database? The site was originally on a shared host but was moved to a DigitalOcean VPS a month or so ago.
I was able to force WordPress to use the filesystem instead of FTP by setting the FS_METHOD constant in wp-config.php:
define('FS_METHOD', 'direct');
More details can be found in the WordPress codex.
Try running chown -R apache:apache on the directory. I recall running in to an issue with ownership even when permissions were OK. You may have more success posting this on ServerFault as well.

How can I fix the Permission error when I call session_start()?

when I uploaded the script to the server I got this error
Warning: Unknown: open(/tmp/sess_58f54ee6a828f04116c2ed97664497b2, O_RDWR) failed: Permission denied (13) in Unknown on line 0
Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/tmp) in Unknown on line 0
The error appeared when I call session_start(), although I set the permission of /tmp folder to 777.
Change session path where you can write data or contact server administrator about /tmp problem
http://php.net/manual/en/function.session-save-path.php
you will need to change your session.save_path php.ini directive
You can do that using session_save_path
If you have SSH access, here is how to correct the permission and ownership
sudo chown -R NAME_OF_USER /tmp
Replace NAME_OF_USER by the user under which runs php. You can find it by simply putting these lines in a php file:
$processUser = posix_getpwuid(posix_geteuid());
print $processUser['name'];
exit;
Check that you're not running into diskspace issues. If all the permissions are correct (and 777 ought to do it for you), then you might still get this error (for some versions of PHP and Apache) if there isn't enough space to write to the disk.
I had this problem in the following situation:
I filled some session vars with PHP
While the session was still active, I changed from PHP 5.4 to 5.3 on my host.
Reloading the page gave the error, described above.
Reset the PHP version to 5.4 again.
Used session_unset(); and session_destroy(); to clean the current session.
Changed the PHP version back to 5.3.
Now it works again.
Conclusion: For an irrelevant reason I had to change my PHP version, and while switching with sessions alive, the sessions get corrupted.
I realize that this is an old post, however I just ran into this problem, and found an easy solution.
For me, the issue was happening with one of my websites deployed locally. I hadn't tried accessing the websites using other browsers, but it was happening every time I tried to access this site via Chrome. I decided to go into the Chrome developer tools, under the application tab -- and clicking "Clear Storage". Voila -- everything is working like magic again.
Hope this helps someone else!
Additionally, you may want to use ini_set('session.save_path', '/dir/here'); assuming you have access to this function. The other ways suggested are valid.
I've just had exactly the same problem with one of my PHP scripts and I was like what did I break 'cos it worked perfectly the day before and I'm running it from my own local Puppy Linux machine so it's not even a host or anything.
The only thing I'd been doing before that was trying to get Java to work in the web browser, so some how I'd managed to get Java to work but broke PHP - oops!
Anyway I did remember that whilst trying to get Java to work I had deleted the contents of the /tmp folder to wipe anything out that may be causing a problem (it actually turned out with Java I was using the old plugin oij with the new Firefox)
To solve this problem I opened up Rox File Manager, went to the / folder and right clicked on the tmp folder -> Mount Point 'tmp' and clicked properties.
I noticed the permissions were set as Owner - Read, Write, Exec, but Group and World were only set at Read and Exec and not Write. I put a tick in Write for both Group and World and now PHP works fine again.
I don't know at what point the permissions for tmp must have changed but for PHP to use them it must be set to have Write permissions.
Add following line
ini_set('session.save_path', getcwd() . '/tmp');
before
session_start();
if you are using Apache web server, the quick fix is to go to your command line and type:
open /etc/apache2/
then from the window opened, open the file called httpd.conf and search for User or Group change these 2 lines to:
User _www
Group _www
This is because you want your server to have permission to your systems directories, especially you want to change the User or you can leave your Group to either staff or admin.
I had the same problem of permission, but on /var/lib/php/session/.
To fix it, I deleted the file and restarted php-fpm.
rm -rf /var/lib/php/session/sess_p930fh0ejjkeeiaes3l4395q96
sudo service php5.6-fpm restart
Now all works well.
For me the problem seems to be a WHM bug!
I have a bunch of add on domains and all work fine but with a subdomain it brings this error.
Strange thing but if I use the full URL with the main domain it works fine:
main-domain.com/my.subdomain.com
If I use the subdomain directly it brings "Permission denied (13)":
my.subdomain.com
The thing is all addon domains root is:
/home/xx/
But for my subdomain, don't know why, the root is: (I shouldn't have access to that dir)
/
So it´s really trying to reach: /tmp instead of /home/xx/tmp
Which also exists but don't have the right permissions
To clarify this are examples of the whole path:
/home/my-account/public_html
/home/my-account/tmp
/tmp
The workaround I used was:
session_save_path('/home/my-account/tmp');
session_start();
Using PHP 5.6 I had already used session_save_path() to point to a directory within the domain's structure. It worked fine until I upgraded to PHP 7.0, at which time I received the noted error. At PHP.net I found several comments that indicated assigning a direct path didn't always work, so I used their suggestion.
session_save_path(realpath(dirname($_SERVER['DOCUMENT_ROOT']) . '/../session'));
worked perfectly. Remember to change /../session to the relative location of your actual session directory.
If :
session.gc_probability > 0
session files are created by different user(s) (e.g. root and apache).
session files are all stored in the same place (e.g. /var/lib/php/session)
Then you'll see this error when e.g. the Apache PHP process attempts to run garbage collection on the session files.
Fixes :
Reconfigure PHP so gc_probability is 0, and have a cron job removing the old/stale file(s).
Have each different user save their session files in separate place(s) (session_save_path() etc).
I initially had this issue due to nginx owning the /tmp location and php-fpm was running under 'apache' user and group due to the www.conf. I swapped out the user/group in that file and then it worked ok. You may want to check <?php echo exec('whoami'); ?> to verify.
In my case the problem was SELINUX not allowing this.
A helpful command to get suggestions on how to fix this:
sealert -a /var/log/audit/audit.log
If you want to rule out SELINUX, try disabling it for a moment. If that fixes the issue then that is the problem.

Categories