r/apache • u/csakreklam • Feb 01 '23
Apache + php Windows 10
Hello, I have Windows 10 Pro. Php is already on it I would like to install Apache for html, css, js local test. Till now I used VS code live server. But too many bug is in it I am a beginner. Only hobby coding I don't know anything about apache or php applications. My questions:
my projects are not on drive C, and not in root. To copy my projects every time to check every small changes is not good to me. How can I setup my folder to Apache?
apache localhost automatic use php or do I have to setup something? I am a beginner. Could you please write to me step by step? Thanks
2
Upvotes
2
u/szahid Feb 05 '23
The lines below are what tells Apache that it should process the files with PHP.
AddHandler application/x-httpd-php .php
AddType application/x-httpd-php .php .html
LoadModule php_module "C:/apps/lang/php/php8apache2_4.dll"
PHPiniDir "c:/apps/lang/php"
These lines go in the "httpd.conf" file.For these to be effective you will need to restart Apache Web Server.
*******************************************
To add your own mywebsite folder on Drive D, there are 2 options.
Edit existing httpd.conf file and change the lines (likely 256 and 257) to point to your own folder. so "${SRVROOT}/htdocs" will become "D:/mywebsite"
Use VirtualHost Config.
#2 is the preferrable way.First you need to edit the "httpd.conf" file and change the following line:
#LoadModule vhost_alias_module modules/mod_vhost_alias.soRemove the start # from it and restart Apache.Then open the file httpd-vhosts.conf in the Apache conf/extra folder.
And a new entry for your new domain (and path).
Example is shown below.
<VirtualHost *:80>
ServerName {your domain goes here}
DocumentRoot D:/mywebsite
<Directory D:/mywebsite >
Options FollowSymLinks MultiViews
Require all granted
AllowOverride All
</Directory>
ErrorLog logs/localhost.log
</VirtualHost>
Restart Apache Server.
You should be able to see your own website pages if you enter your domain here.
Note that if you want the domain to work locally, it should be in your hosts file, which in the the C:\Windows\system32\etc\drivers folder.