Windows 10 and PHP a file_get_contents() responds with permission denied - php

Error:
Warning: file_get_contents(C:\Users\ET\projects\results.php): failed to open stream: Permission denied in C:\Users\ET\projects\results.php on line 16
line 16: $fileContents = file_get_contents("Files/$file","r");
XAMPP with PHP 7.3
IntelliJ PHPStorm 2019.2.3
Windows 10 Home
This fails in both the IntelliJ IDE's terminal, in CMD and in CMD opened as admin.
How is this fixed in windows where there is no chmod?

Copy your project files to (it is xampp documents folder: c:/xampp/htdocs for (php,html,css,js)):
c:/xampp/htdocs/proj1
c:/xampp/htdocs/proj2
Then set virtualhost: C:\xampp\apache\conf\extra\httpd-vhosts.conf
<VirtualHost *:80>
DocumentRoot "c:/xampp/htdocs/proj1"
ServerName proj1.xx
ServerAlias www.proj1.xx
<Directory "c:/xampp/htdocs/proj1">
DirectoryIndex index.php
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "c:/xampp/htdocs/proj2"
ServerName proj2.xx
ServerAlias www.proj2.xx
<Directory "c:/xampp/htdocs/proj2">
DirectoryIndex index.php
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Create in windows hosts file: C:\Windows\System32\drivers\etc
127.0.0.1 localhost proj1.xx proj2.xx
Restart xampp apache2, browser and then run in browser:
http://proj1.xx
Or
http://proj2.xx
You can change c:/xampp/htdocs/proj1 to your project path C:\Users\ET\projects ofcourse in xampp virtualhosts file.
P.S. You don't know the basics ... read and learn.

Related

How can I run my Laravel project without cmd command "php artisan serve"?

<VirtualHost *:80>
ServerAdmin webmaster#hujjaj.dev
DocumentRoot "C:\xampp\htdocs\hujjaj_app_new\public"
ServerName hujjaj.dev
ErrorLog "logs/hujjaj.dev-error.log"
CustomLog "logs/hujjaj.dev-access.log" common
I am doing so in my virtual host file and update 127.0.0.1 hujjaj.dev then i restart XAMPP and after that I navigate to localhost/hujjaj.dev but showing 404|Not Found.
Please try the following
<VirtualHost 127.0.0.2:80>
DocumentRoot “D:\laravel-gkb\public”
DirectoryIndex index.php
ServerName laravel-gkb.test
<Directory “D:\laravel-gkb\public”>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order Deny,Allow
Allow from all
Require all granted
</Directory>
</VirtualHost>
Then add the save domain in your hosts file
127.0.0.2 hujjaj.dev
Refer this for more details : link
Yes, There is another way to run laravel project, with following command..
php -S 127.0.0.1:8001 server.php
This will run your application at 127.0.0.1:8001 mentioned address.
Note: laravel default entry point is server.php thats why we mentioned it. other wise it will be index.php

Virtual host redirecting to the xampp folder, but only getting This site can’t be reached

I know I'm probably missing something simple, but I've exhausted all resources trying to get this working.
I'm running my Apache on Port:5000 and trying to direct to lsapp.dev instead of http://localhost:5000/lsapp/public/ with:
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/lsapp/public"
ServerName lsapp.dev
</VirtualHost>
I have tried VirtualHost *:5000 but still can't get it work?
you can use this on command line in your project root
php artisan serve --port=your_port_number
or do this:
edit httpd-vhosts.conf that is located in C:\xampp\apache\conf\extra\httpd-vhosts.conf and add following lines at the end of the file:
# VirtualHost for LSAPP.DEV
<VirtualHost lsapp.dev:80>
DocumentRoot "C:\xampp\htdocs\lsapp\public"
ServerAdmin lsapp.dev
<Directory "C:\xampp\htdocs\lsapp">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
our apache is listening to lsapp.dev connections, but we have to configure our hosts file that allows to redirect lsapp.dev to the localhost that is located in C:\Windows\System32\drivers\etc
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
127.0.0.1 lsapp.dev
Set your Virtual host file like this.
<VirtualHost *:80>
DocumentRoot "D:\laravel Task\laravel\blog" //here set your project storage path
ServerName localhost.test.com // set your url for your project
<Directory "D:\laravel Task\laravel\blog"> // again set your project storage path
AllowOverride All
Order allow,deny
Allow from all
Require all granted
set your hosts file like this
127.0.0.1 localhost.test.com
Now you can Run your project
localhost.test.com
//OR//
If you dont want to use virtual host, then you can run your project like this
goto your project folder=>
command line in your project root=>php artisan serve
your project will run in
http://127.0.0.1:8000/

Configuration of virtual host

I was trying to create a virtual host on my localhost, I followed a tuto on the internet. Here're the steps :
1) I created my project on desktop (using laravel 5)
2) I opend the file "httpd-vhosts.conf" (C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-binaries\httpserver\apache2418x161221110224\conf\httpd-vhosts.conf ) to uncomment this line : "Include conf/extra/httpd-vhosts.conf"
3) I edited the file "httpd-vhosts.conf" I added the following lines :
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "C:\Users\Sony\Desktop\links"
ServerName links.localhost
</VirtualHost>
4) I edited the file "hosts" (C:\Windows\System32\drivers\etc\hosts)
and added this line "127.0.0.1 links.localhost"
5) Then I restarted easyphp and executed the following command on my command line : ipconfig /flushdns
--> Results :
The file "httpd-vhosts.conf" is empty
This line is commented again : "Include conf/extra/httpd-vhosts.conf"
When I try to access the vhost "http://links.localhost", is just like if i am accessing the localhost
This is what I have at the end of "httpd.conf"
# VIRTUAL HOSTS
## Virtualhost localweb
<VirtualHost 127.0.0.1>
DocumentRoot "C:/Program Files (x86)/EasyPHP-Devserver-16.1/eds-www"
ServerName 127.0.0.1
<Directory "C:/Program Files (x86)/EasyPHP-Devserver-16.1/eds-www">
Options FollowSymLinks Indexes
AllowOverride All
Order deny,allow
Allow from 127.0.0.1
Deny from all
Require all granted
</Directory>
</VirtualHost>
#Costumized vhost config file
Include conf/links-vhost.conf
First create a file (say) name it links.conf and add your Virtual host
<VirtualHost *:80>
DocumentRoot "C:\Users\Sony\Desktop\links"
ServerName links.localhost
</VirtualHost>
Now at the the end of your httpd.conf add : Include conf/links.conf.

Php website virtual host

I'm new to php, I did installed xampp-win32-1.8.2-2-VC9-installer on my window7 desktop pc. PHP page run from C:\xampp\htdocs but when i create virtual host and tried to access php file in d:\web\ it shows access forbidden.
my host file code
127.0.0.1 localhost1
my httpd-vhost file code
NameVirtualHost *
<VirtualHost *>
DocumentRoot "C:/xampp/htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost localhost1:80>
DocumentRoot "d:/web/test.php"
ServerName localhost1
<Directory "d:/web/test.php">
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
I don't know now where i have to change
It's a file permissions derived issue. Try changing NTFS permissions in "C:/xampp/htdocs" to allow read and execute permissions to the user that is running the web server, you should be able to see who that user is in the Apache configuration file, tipically "apache" which is the equivalent to IUSR in IIS.

Unable to start Zend2 skeleton app

I have a xampp serwer on windows XP:
Apache 2.4.3
PHP 5.4.7
and I try to start learning Zend2.
I downloaded skeleton app: https://github.com/zendframework/ZendSkeletonApplication
and run from cmd:
php composer.phar self-update
php composer.phar install
(not that I had to give a full link to php like C:\xxx\php.exe - I don't know why, I have php in my enviromental variables). It went ok - no errors.
I added this code to httpd-vhosts.conf :
<VirtualHost *:80>
ServerName zf2-tutorial.localhost
DocumentRoot /zf2-tutorial/public
SetEnv APPLICATION_ENV "development"
<Directory /zf2-tutorial/public>
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
I also added this line to C:\WINDOWS\system32\drivers\etc\hosts
127.0.0.1 zf2-tutorial.localhost localhost
When I run
http://zf2-tutorial.localhost
in the browser I get "Permission denied"
When I try
http://localhost/zf2-tutorial/public/
I get very long php error
Fatal error: Uncaught exception 'Zend\ServiceManager\Exception\InvalidArgumentException' with message 'Provided abstract factory must be the class name of an abstract factory or an instance of an AbstractFactoryInterface.' in C:\xampp\htdocs\zf2-tutorial\vendor\zendframework\zendframework\library\Zend\ServiceManager\ServiceManager.php:302 ...........
I figure sth is wrong with serwer since I get "Permission denied".
What I am doing wrong? Thx in advance.
BIg Thanx Everyone. My final config:
<VirtualHost *:80>
ServerName zf2-tutorial.localhost
DocumentRoot C:/xampp/htdocs/zf2-tutorial/public
SetEnv APPLICATION_ENV "development"
<Directory C:/xampp/htdocs/zf2-tutorial/public>
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
127.0.0.1 zf2-tutorial.localhost
Works fine on: http://zf2-tutorial.localhost/
Your hosts file is incorrect. Instead of:
127.0.0.1 zf2-tutorial.localhost localhost
Remove the last "localhost", so you get:
127.0.0.1 zf2-tutorial.localhost
Edit:
Another thing I just noticed is your DocumentRoot: this should be the fully qualified path to your document root: i.e. C:/www/zf-tutorial/public. Note that you should use forward slashes for directory separators. Use the same path in your Directory configuration to make sure that access is allowed to that directory.
It seems you are using Windows, so your vhost configuration should contains Windows alike path to your project. Are you sure that you have valid path to php\bin in your %PATH%?
> echo %PATH%
I am using XAMPP on Windows 7.
Here is my vhost configuration:
<VirtualHost *:80>
##ServerAdmin postmaster#dummy-host2.localhost
DocumentRoot "C:/xampp/projects/zf2-tutorial/public"
ServerName zf2.tutorial
##ServerAlias www.dummy-host2.localhost
SetEnv APPLICATION_ENV "development"
<Directory C:/xampp/projects/zf2-tutorial/public>
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
ErrorLog "logs/zf2.tutorial-error.log"
CustomLog "logs/zf2.tutorial-access.log" combined
</VirtualHost>
This one is essential (probably also in your case):
<Directory C:/xampp/projects/zf2-tutorial/public>
# ...
Require all granted
</Directory>

Categories