I'm running WAMP Server 3.0.4 (32bit) with MySQL 5.7.11, and Apache 2.4.18, PHP 5.6.19 on Windows 7 Home Premium 64bit.
When I try to create a new virtual host I get the following errors:
( ! ) Warning: fopen(C:\\Windows\\system32\\drivers\\etc\\hosts): failed to open stream: Permission denied in C:\wamp32\www\add_vhost.php on line 238
Call Stack
# Time Memory Function Location
1 0.0010 172656 {main}( ) ...\add_vhost.php:0
2 0.0210 280016 fopen ( ) ...\add_vhost.php:238
( ! ) Warning: fwrite() expects parameter 1 to be resource, boolean given in C:\wamp32\www\add_vhost.php on line 239
Call Stack
# Time Memory Function Location
1 0.0010 172656 {main}( ) ...\add_vhost.php:0
2 0.0650 280384 fwrite ( ) ...\add_vhost.php:239
( ! ) Warning: fclose() expects parameter 1 to be resource, boolean given in C:\wamp32\www\add_vhost.php on line 273
Call Stack
# Time Memory Function Location
1 0.0010 172656 {main}( ) ...\add_vhost.php:0
2 0.0690 280072 fclose ( ) ...\add_vhost.php:273
The PHP code at lines 238 and 239 in add_vhost.php is:
$fp1 = fopen($c_apacheVhostConfFile_escape, 'a+');
$fp2 = fopen($c_hostsFile_escape, 'a+');
The two files being accessed are:
c:/wamp32/bin/apache/apache2.4.18/conf/extra/httpd-vhosts.conf
C:\\Windows\\system32\\drivers\\etc\\hosts
The code at line 273 in add_vhost.php is
fclose($fp1);
The file is
c:/wamp32/bin/apache/apache2.4.18/conf/extra/httpd-vhosts.conf
The file c:/wamp32/bin/apache/apache2.4.18/conf/extra/httpd-vhosts.conf does contain an entry for the new virtual host:
<VirtualHost *:80>
ServerName vhostsadd
DocumentRoot c:/wamp32/www/vhostsadd
<Directory "c:/wamp32/www/vhostsadd/">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
The hosts file (which is at c:\windows\system32\drivers\etc\hosts) does NOT contain an entry for the new virtual host.
I can open and edit the hosts file to insert the needed lines, but when I try to save it, I am told "The process cannot access the file because it is being used another process."
I'm using Notepad to edit the hosts file. Even if I run it as the administrator, I cannot save the file.
I have to restart Windows in Safe Mode in order to be able to save the edited hosts file. Then, of course, I have to restart Windows in normal mode to continue working.
Question - I inserted an echo to show me the files being opened at lines 238 and 239 and the file name being used for the host files seems a bit strange:
It is
C:\\Windows\\system32\\drivers\\etc\\hosts
but I would have expected to see
C:/Windows/system32/drivers/etc/hosts
That is, with the other slash (which I call a forward slash - as I, and everyone else, have done since 1973 when I started working with computers) and with only one slash in each position.
Is this part of the problem - the file name being used for the hosts file?
To recap - I get the messages shown above when I add a virtual host. The c:/wamp32/bin/apache/apache2.4.18/conf/extra/httpd-vhosts.conf file has the necessary entry but the hosts file does not.
If I restart Windows in Safe Mode, edit the hosts file to add the needed lines, save the file, and restart Windows, the virtual host works properly.
Note - I was able to get a virtual host correctly created with this WAMP installation a few months ago but now I'm getting these errors.
So - what is wrong here and what should I do to fix it?
Simon
When I try to create a new virtual host I get the following errors:
( ! ) Warning: fopen(C:\\Windows\\system32\\drivers\\etc\\hosts): failed to open stream: Permission denied in C:\wamp32\www\add_vhost.php on line 238
Call Stack
# Time Memory Function Location
1 0.0010 172656 {main}( ) ...\add_vhost.php:0
2 0.0210 280016 fopen ( ) ...\add_vhost.php:238
( ! ) Warning: fwrite() expects parameter 1 to be resource, boolean given in C:\wamp32\www\add_vhost.php on line 239
Call Stack
# Time Memory Function Location
1 0.0010 172656 {main}( ) ...\add_vhost.php:0
2 0.0650 280384 fwrite ( ) ...\add_vhost.php:239
( ! ) Warning: fclose() expects parameter 1 to be resource, boolean given in C:\wamp32\www\add_vhost.php on line 273
Call Stack
# Time Memory Function Location
1 0.0010 172656 {main}( ) ...\add_vhost.php:0
2 0.0690 280072 fclose ( ) ...\add_vhost.php:273
The PHP code at lines 238 and 239 in add_vhost.php is:
$fp1 = fopen($c_apacheVhostConfFile_escape, 'a+');
$fp2 = fopen($c_hostsFile_escape, 'a+');
The two files being accessed are:
c:/wamp32/bin/apache/apache2.4.18/conf/extra/httpd-vhosts.conf
C:\\Windows\\system32\\drivers\\etc\\hosts
The code at line 273 in add_vhost.php is
fclose($fp1);
The file is
c:/wamp32/bin/apache/apache2.4.18/conf/extra/httpd-vhosts.conf
The file c:/wamp32/bin/apache/apache2.4.18/conf/extra/httpd-vhosts.conf does contain an entry for the new virtual host:
<VirtualHost *:80>
ServerName vhostsadd
DocumentRoot c:/wamp32/www/vhostsadd
<Directory "c:/wamp32/www/vhostsadd/">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
The hosts file (which is at c:\windows\system32\drivers\etc\hosts) does NOT contain an entry for the new virtual host.
I can open and edit the hosts file to insert the needed lines, but when I try to save it, I am told "The process cannot access the file because it is being used another process."
I'm using Notepad to edit the hosts file. Even if I run it as the administrator, I cannot save the file.
I have to restart Windows in Safe Mode in order to be able to save the edited hosts file. Then, of course, I have to restart Windows in normal mode to continue working.
Question - I inserted an echo to show me the files being opened at lines 238 and 239 and the file name being used for the host files seems a bit strange:
It is
C:\\Windows\\system32\\drivers\\etc\\hosts
but I would have expected to see
C:/Windows/system32/drivers/etc/hosts
That is, with the other slash (which I call a forward slash - as I, and everyone else, have done since 1973 when I started working with computers) and with only one slash in each position.
Is this part of the problem - the file name being used for the hosts file?
To recap - I get the messages shown above when I add a virtual host. The c:/wamp32/bin/apache/apache2.4.18/conf/extra/httpd-vhosts.conf file has the necessary entry but the hosts file does not.
If I restart Windows in Safe Mode, edit the hosts file to add the needed lines, save the file, and restart Windows, the virtual host works properly.
Note - I was able to get a virtual host correctly created with this WAMP installation a few months ago but now I'm getting these errors.
So - what is wrong here and what should I do to fix it?
Simon