Getting Access forbidden on new localhost project - php

I'm attempting to setup a new webproject based off of the Open Source Point of sale system. I have followed the install steps as I usually do, but when I goto my localhost/webproj I get the following error:
Access forbidden!
You don't have permission to access the requested directory. There is
either no index document or the directory is read-protected.
If you think this is a server error, please contact the webmaster.
Error 403
localhost Apache/2.4.16 (Win32) OpenSSL/1.0.1p PHP/5.6.11
I have checked readonly flags on all files/folders, no problem there.
but there is this line in the readme which I'm having trouble verifying and wondering if that could be the cause.
PHP needs to have php-gd, php-bcmath, php-intl, php-sockets
and php-mcrypt installed and enabled.
how do I check these php 'things' are installed and enabled?
EDIT: Using windows 10. logged in locally as an admin user. Single machine no domain.

CD into your localhost directory using terminal / cmd prompt and check for ownership permissions firstly.
cd localhost (my assumption, you may need to tweak this to where your localhost files are stored) then run ls -ll which will display your permissions and ownership information.
If you find the ownership is wrong run:
chown -R yourUserName:staff webproj/*
You can then run a chmod to be sure:
chmod -R 755 webproj/*
To run a test you could simply chmod the files to 777 to see if this allows entry.

Are you sure there is an index.php in that folder; or whatever is your default directory index? Default permissions are usually good, but there are times you may have to chmod 777 on local dev to make things work. You can check modules with phpinfo(). Create a file, say phpinfo.php, and add just a single line like so: <?php phpinfo(); ?>
Oh, and XAMPP is usually owned by root, at least on nix, so chowning htdocs to your own account will fail.

OK it looks like this was caused by the new application having its index.html in a sub folder. If I launched directly from this sub folder it works. This was done to heighten security in the web application.

Related

Getting error "CodeIgniter\Cache\Exceptions\CacheException Cache unable to write to ... " for a new Codeigniter 4 project

Almost always, when I am starting a Codeigniter 4 project, I am getting the following error:
"CodeIgniter\Cache\Exceptions\CacheException Cache unable to write to "/path/to/codeigniter-project/writable/cache/."
SYSTEMPATH/Cache/Handlers/FileHandler.php at line 61
which points at the below line:
throw CacheException::forUnableToWrite($this->path);
What is the best way to solve this?
After doing a research, I've concluded into two options
Option 1:
The very quick way to just solve the above issue is to go to the command tool (e.g. terminal) and change the permissions of the folder to be writable and also to change the owner of the folder to be the one that is used from your server application. For example, I am using Apache and the user for apache is www-data:
chmod -R 755 writable/
chown -R www-data:www-data writable/
or for macOS:
chmod -R 755 writable/
chown -R _www:_www writable/
Pros:
A quick copy-paste solution
Those commands - most of the times - works out of the box
Even if you don't have access to command tool, you can change the permissions and ownership of the folder through FTP (e.g. through FileZilla UI interface)
Cons:
You always need to add those commands into a new project
You may experience issues on development when you are trying to access the folder with your username
Option 2 (suggested for local development):
Add the www-data or _www (for macOS) to be at the same group role as your user.
for Linux and Apache:
sudo usermod -aG www-data your_username
or for macOS and Apache:
sudo dseditgroup -o edit -a your_username -t user _www
If you are still getting the error also make sure that you have the folder as writable with the following command:
chmod -R 755 writable/
I don't know why but it may also need to do a restart of the Apache.
Pros:
It works for new projects with no extra effort
You don't need to change the owner of the folder so you can have access to the folder for development
Once this change is available to the server or locally, you don't need to use sudo anymore if the chmod command is required
Cons:
Not that safe for production environments (especially if you don't know what you are doing) since you would prefer to have specific users with specific roles rather than have users to have access everywhere
It requires more effort and it is not that straight forward for beginners
It needs more permissions to the server (e.g. sudo access)
The OP has a good answer. Though sometimes you don't have access to the terminal or a secure shell (ssh), especially in a shared hosting environment to be able to run those commands.
I got a similar issue while working on a new project. I noticed that this normally happened because my application failed to write session files in the writable/session folder of my root project directory because of permission restrictions. I was using the CodeIgniter\Session\Handlers\FileHandler as my configured "session storage driver".
I managed to solve it by instructing the application to write these temporary files in the server's tmp directory.
This is by default in the /tmp directory.
Excerpt from php-src/php.ini-production
; Directory where the temporary files should be placed.
; Defaults to the system default (see sys_get_temp_dir)
;sys_temp_dir = "/tmp"
Solution
I opened my .env file residing at the root of my project directory and added the line below.
app.sessionSavePath = '/tmp/my_project_name/ci4_session'
If you don't have this .env file, create one starting with this default file content:
Notice the dot (.) in front of the filename.
CodeIgniter4 env file
Addendum
Similarly, in your case, the application fails to write cache files in the writable/cache folder of your root project directory because of permission restrictions. You most certainly are using file as your cache handler.
Solution
Open your .env file residing at the root of your project directory and add the line below.
cache.storePath = '/tmp/my_project_name/ci4_cache'
TIP(S)
These and more configurations can be found/modified in your .env file using the rules below:
The configuration class file name, in lower case. I.e cache.
Followed by a dot(.).
Then the public configuration class's property name. I.e storePath.
Steps 1,2,3 combined makes, cache.storePath, which becomes your .env file's key declaration. Then an equals sign =. And lastly, the .env file's value ('/tmp/my_project_name/ci4_cache') declaration. Finally coming up with, cache.storePath = '/tmp/my_project_name/ci4_cache'.
The configuration classes can be found in the app/Config folder of your root project directory. I.e:
app/Config/Cache.php
app/Config/App.php
This worked for me, U should try this
Firstly cd into where your file is Example
cd /opt/lampp/htdocs/
This is where my file is
Secondly Write this command below in your command prompt
sudo chmod -R 777 file-name
I just create a folder inside "writable" folder with name "cache" and my project properly running.

Can't scandir() in php referenced from root Centos 7 using apache

After reading lots of questions regarding php scandir() I haven't found one that answered my question. If this is a duplicate, please let me know where the answer is before marking me down.
Problem:
If I do
var_dump(scandir("/"));
Then I get the contents of the system root folder: bin, installs, nvme, var, etc, etc... 😊
If I do
var_dump(scandir("/nvme"));
Then I get false and an error that var/www/public_html/nvme doesn't exist.
So then if I do
var_dump(scandir("../../../../../../../"));
I can see the system root folder
but if I do
var_dump(scandir("../../../../../../../nvme"));
then I get a permission denied error.
I tested that I can scan each directory between the public_html and the root directory, but the moment I try to scan forward a directory then I run into errors. All the directories on the way back are owned by the same user as the nvme directory I'm trying to scan. Using file_get_contents throws the same error.
In SElinux I gave apache permission to read and write to the nvme folder. I'm running on Centos 7 with SElinux enabled.
Why can't I can a up from root on a different directory path?
EDIT:
My specific error was that I hadn't completed setting the SElinux context.
Previously I had run
semanage fcontext -a -t httpd_sys_content_t "/nvme(/.*)
but after that I still needed to run
restorecon -v "/nvme"
so that the new context was actually implemented. Now var_dump(scandir("/./nvme")); and var_dump(scandir("../../../../../../../nvme")); both work.

Error in phpMyAdmin after updating to v4.8.0: The $cfg['TempDir'] (./tmp/) is not accessible

phpMyAdmin worked fine with v4.7.9. Now after updating to v4.8.0 today (replacing the old phpmyadmin folder against the new one) I'm getting this message in phpMyAdmin:
The $cfg['TempDir'] (./tmp/) is not accessible. phpMyAdmin is not able
to cache templates and will be slow because of this.
I added the folder ./tmp/ like like this: /usr/share/tmp
phpMyAdmin is on: /usr/share/phpmyadmin
This didn't change anything.
Who know this error? What can I do?
Solution was to create a folder called tmp like this: /usr/share/phpmyadmin/tmp.
Also make sure that the user (or group) running the webserver (e.g. Apache) has write access to the newly created tmp folder. Consequently, change the ownership to that user or add write access for all users. The latter one might not be really advisable.
simple fix is to create tmp dir in your phpmyadmin dir and set permission to 777
mkdir tmp && chmod 777 tmp
then
update your config.inc.php file add that line
$cfg['TempDir'] = 'tmp';
I had this same problem on Ubuntu 18.04 when I replaced the phpMyAdmin version from the package repository (v4.6.6) with the latest version (4.8.0). I don't know if you are running on Ubuntu, but maybe my response will be helpful to you (or others) who encounter something similar.
I put the new version in the standard location, /usr/share/phpmyadmin/, but Ubuntu's package installation of PMA puts some configuration settings in other places (see /etc/phpmyadmin/ and /var/lib/phpmyadmin/). I found this setting in /etc/phpmyadmin/apache.conf:
php_admin_value upload_tmp_dir /var/lib/phpmyadmin/tmp
and sure enough that directory had been created and had the proper permissions. Wanting to stay as close as possible to the package installation settings, I made this change in /usr/share/phpmyadmin/libraries/vendor_config.php and pointed directly to that folder:
//define('TEMP_DIR', './tmp/');
define('TEMP_DIR', '/var/lib/phpmyadmin/tmp/');
This setting is picked up by /usr/share/phpmyadmin/libraries/config.default.php (which you are not supposed to edit) to set $cfg['TempDir'].
In my case I added
$cfg['TempDir'] = '/usr/share/phpmyadmin/temp';
to the
config.inc.php
File within the phpmyadmin folder
Hope it will help someone
Create a temp directory owned by and restricted to the webserver user. Do not place it inside of the phpMyAdmin webroot. (In this example, the webserver runs as apache):
mkdir -p /var/tmp/phpMyAdmin
chown apache:apache /var/tmp/phpMyAdmin
chmod 700 /var/tmp/phpMyAdmin
Next, set TempDir inside of phpMyAdmin's config.inc.php:
$cfg['TempDir'] = '/var/tmp/phpMyAdmin';
Any answer suggesting that you create /usr/share/phpmyadmin/tmp is advocating bad security practice. This is generally true for temp directories, and explicitly stated in the official phpMyAdmin documentation:
For security reasons, all directories should be outside the tree
published by webserver.
For me phpmyadmin dir was found inside /opt/lampp/
open teminal inside /opt/lampp/phpmyadmin/
give root privileges to the terminal by typing sudo su command.
now in same terminal use (mkdir -p /tmp/) hit enter
now, chmod 777 /tmp
Inside phpmyadmin directory there is a file config.inc.php. Open it using same terminal .
add this line $cfg['TempDir'] = /tmp; and Save.
Now you are good to go , just reload the tab and the error will be gone.
Create a tmp folder in the base directory of the phpMyAdmin install (e.g. /usr/share/phpmyadmin/tmp), and make sure that it is writable by the user that PHP is running under.
From the phpMyAdmin documentation:
$cfg['TempDir']
Type: string
Default value: './tmp/'
The name of the directory where temporary files can be stored.
It is used for several purposes, currently:
The templates cache which speeds up page loading.
ESRI Shapefiles import, see 6.30 Import: How can I import ESRI Shapefiles?.
To work around limitations of open_basedir for uploaded files, see 1.11 I get an ‘open_basedir restriction’ while uploading a file from the import tab..
This directory should have as strict permissions as possible as the only user required to access this directory is the one who runs the webserver. If you have root privileges, simply make this user owner of this directory and make it accessible only by it:
chown www-data:www-data tmp
chmod 700 tmp
If you cannot change owner of the directory, you can achieve a similar setup using ACL:
chmod 700 tmp
setfacl -m "g:www-data:rwx" tmp
setfacl -d -m "g:www-data:rwx" tmp
If neither of above works for you, you can still make the directory chmod 777, but it might impose risk of other users on system reading and writing data in this directory.
well,in my case this error has occured when i was using ubuntu 18.04.
All you need is to go to the installation directory (in ubuntu - opt/lampp/phpmyadmin)
and create a folder tmp with all the suitable read/write permissions.
Follow these steps in case of ubuntu-
1.go to the PMA installation directory by typing following commands in cmd-
cd opt/lampp/phpmyadmin
2.Then type the following command-
sudo mkdir tmp && chmod 777 tmp
and then you are done..!!
I hope it helps..
1) create the tmp folder
mkdir /usr/share/phpmyadmin/tmp
2) findout your php user
<?php echo `whoami`; ?>
3) Change ownership of the tmp folder to the php user found in step 2
sudo chown -R step2phpuser:step2phpuser /usr/share/phpmyadmin/tmp
4) Signout of phpmyadmin and sign back in
I had the same error message. I'm using Ubuntu16.04 with lampp. You should go to 'phpmyadmin' directory, in my case '/opt/lampp/phpmyadmin/', create a new 'tmp' folder. Open a terminal window and:
cd YOUR_PATH_TO_PHPMYADMIN
sudo mkdir tmp
Now you have to change the group of the 'tmp' folder to give access to php user. In order to find it, you can create a php file inside your localhost directory, in my case 'htdocs'
sudo touch user.php
sudo nano user.php
Inside nano editor, type:
<?php echo `whoami`; ?>
Then press CTRL + O and CTRL + X to save and exit.
Open the browser and type in your address bar
localhost/user.php
It shows your php user.
After that, go to the terminal and navigate to your recently created 'tmp' directory inside phpmyadmin directory and type:
sudo chgrp YOUR_PHP_USER tmp -R
And change the permission to the 'tmp' directory:
sudo chmod 775 tmp -R
I recommend never give 777 permission to any file.
I hope it helps!
For Arch and Manjaro users:
Create a folder tmp at /etc/webapps/phpmyadmin/ - mkdir /etc/webapps/phpmyadmin/tmp
Set permission to 777 - chmod 777 /etc/webapps/phpmyadmin/tmp
Add this line to the config file at /etc/webapps/phpmyadmin/config.inc.php - $cfg['TempDir'] = '/tmp';
Cheers :)
I had the same problem but none of the answers above could solve.
In my case my php security settings was so strict protecting php to access directories out of scope defined in open_basedir located at my /etc/php.d/99-security.ini(which I added perviously from a security toturial and the settings also could be located at /etc/php.ini file in your case):
;; Limit PHP Access To File System
; Limits the PHP process from accessing files outside
; of specifically designated directories such as /var/www/html/
open_basedir="/home/:/etc/phpMyAdmin/:/var/lib/phpMyAdmin/"
change to:
open_basedir="/home/:/etc/phpMyAdmin/:/var/lib/phpMyAdmin/:'/usr/share/phpmyadmin/tmp/" ;<== changing to this solved the prblem
you just need to add your own directory in error mesage ('/usr/share/phpmyadmin/tmp/') and the end of open_basedir option. Don't forget placing separator : before adding it.
If the folder already exists for example from a previous installation:
chmod -R 777 PATH_TO_FOLDER
Therefore permission on subdirectories are also modified (recursively).
In my case [MacOs El Capitán/portuguese], the message was:
The $cfg['TempDir'] (./temp/) is not accessible
My solution, in xamppfiles/phpmyadmin/config.inc.php:
$cfg['TempDir'] = './temp/'; to $cfg['TempDir'] = '../temp/';
That is, I just added a point to the path... work's fine.
I just changed my vendor_config.php file to define('TEMP_DIR', '/tmp/'); instead of define('TEMP_DIR', './tmp/');
This seems to work.
I had a similiar problem, with the "temp" directory. The solution was to change the owner and group of the "twig" directory (inside "temp") to "apache" (both owner and group)
Create the tmp folder in the root of phpmyadmin files
In addition to that, you also need to provide all permissions to that folder. That's what I did in Windows.
My Answer goes to centos 7 Sentora users,
tmp folder has to be created under phpMyadmin of Sentora as shown below
cd /etc/sentora/panel/etc/apps/phpmyadmin/
sudo mkdir tmp
After creating the folder make sure you give Apache access permissions to the tmp folder
chown -R apache /etc/sentora/panel/etc/apps/phpmyadmin/tmp/
simply go to the phpmyadmin folder and put this code
$cfg['TempDir'] = './tmp/';
and then check tmp folder is exists or not into phpmyadmin if not exists then create tmp folder and give read and right permission to it.
For me, the error message was as follows:
The $cfg['TempDir'] (/var/lib/phpmyadmin/tmp/) is not accessible. phpMyAdmin is not able to cache templates and will be slow because of this
Then I navigate and checked the location. there was the tmp folder but was owned by www-data by default. After that, I make it writable by the user the PHP is running under. Problem solved.

move_uploaded file:failed to open stream: Permission denied in /srv/http/upload.php

I am trying to run a server on ArchLinux, I have apache and PHP running normally, but i can't upload a file with PHP. I have seen many questions of this sort on Stackoverflow and I seem to have used all the suggestions I found, but I still get a
failed to open stream: Permission denied in /srv/http/upload.php
error.
To be precise
Warning: move_uploaded_file(): Unable to move '/tmp/phpZvJK1l' to '/home/administrator/SCRIPTS/tr/solution.cpp' in /srv/http/upload.php on line 20
I set the permissions for /tmp/, /home/administrator/SCRIPTS/tr and /srv/http to 777 (I know thats not right, but I am working locally right now and I want to get it working somehow).
Also I set all the owner of these directories to http (that is the user running PHP), but the thing still doesnt work.
Some PHP configurations do not allow file access outside the users docroot directory, so you may not have access to /tmp from within PHP. Try uploading your file(s) to a temp directory within your /home/administrator directory - preferably to a directory that isn't accessible to web browsers (a sibling directory to your docroot).
give permission to the /tmp dir :
sudo chmod 777 /tmp
As an Arch user I have the same issue when I work on web projects.
I'll recommend you to see this part of the Arch Wiki
User directories are available by default through http://localhost/~yourusername/ and show the contents of ~/public_html (this can be changed in /etc/httpd/conf/extra/httpd-userdir.conf).
So do to so you have to create the ~/public_html directory then
You must make sure that your home directory permissions are set properly so that Apache can get there. Your home directory and ~/public_html must be executable for others ("rest of the world"):
$ chmod o+x ~
$ chmod o+x ~/public_html
$ chmod -R o+r ~/public_html
After that you don't need to put your file under /srv/http/ you can now use ~/public_html as development directory.

DOMPDF 0.5.1 - Fonts not working on live Server

I've got DOMPDF 0.5.1 running in a Drupal implementation on my localhost (xampp, windows 7) which generates my Pdf's just fine.
But when i commit this to the live server things go wrong. I get the error: "The font "Futura" contains a bad /BBox"
And all text is displayed as dots.
Any idea what might be going on?
The user who starts your webserver i.e. httpd or apache must have read/write access to the font folder as well, that might cause the problem.
Give your webserver write permission on the path specified in DOMPDF_FONT_DIR (lib/fonts by default). Under *nix, ideally you can make the webserver group the owner of this directory and give the directory group write permissions. For example, on Debian systems, Apache runs as the www-data user:
$ chgrp www-data lib/fonts
$ chmod g+w lib/fonts
If your user is not a member of the www-data group or you do not have root privileges, you can make the directory world writable and set the sticky bit:
$ chmod 1777 lib/fonts
http://code.google.com/p/dompdf/wiki/Installation

Categories