configuration apache virtualhosts
Note By default, Apache configuration on Mac OS X serves files from /Library/WebServer/Documents for localhost
- Make you super user:
sudo su
- Make you super user:
nano /etc/apache2/httpd.conf
- Add this line:
Include /private/etc/apache2/vhosts/*.conf
- Add this line to include all files ending in .conf in the /private/etc/apache2/vhosts/ directory:
Include /private/etc/apache2/vhosts/*.conf
- Do:
mkdir /etc/apache2/vhosts
cd /etc/apache2/vhosts
- Create virtual host configuration file:
nano _default.conf
- Add (for exemple):
<VirtualHost *:80>
DocumentRoot "/Library/WebServer/Documents"
</VirtualHost>
- Create Vhost configuration file (with the that you want):
exemple.site.net.conf
- Add on it (replace by your username and your dir project):
<VirtualHost *:80>
DocumentRoot "/Users/(my_username)/Documents/workspace/(my_dir_project)/htdocs"
ServerName exemple.site.local
ErrorLog "/private/var/log/apache2/exemple.site.local-error_log"
CustomLog "/private/var/log/apache2/exemple.site.local-access_log" common
<Directory "/Users/(my_username)/Documents/workspace/(my_dir_project)/htdocs">
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
- Run
apachectl restart
apachectl configtest
- edit etc/hosts
nano /etc/hosts
- add:
127.0.0.1 exemple.site.local
- Clear local DNS cache
dscacheutil -flushcache
- After you will can access to: http://exemple.site.local for local development.
Below, the command to run from /etc/apache2 to change default dir "Library/WebServer/Documents" by "/Users/(your_username)/workspace/Sites" (be careful, it change in all .conf files) :
LC_CTYPE=C && LANG=C && find * -type f -exec sed -i "" "s#/Library/WebServer/Documents#/Users/(your_username)/workspace/Sites#g" {} +
Sometimes we should kill httpd to reload server:
sudo apachectl stop
OR
sudo /usr/sbin/apachectl stop
AND
sudo killall httpd
sudo apachectl start
sudo dscacheutil -flushcache
To fix Error 403:
- change Rights on folder of you (To make readable by Apache)
chmod a+rx /var/www/your_folder
chmod a+r /var/www/votre-dossier/your_folder
- add index.html file
cd /var/www/your_folder
nano index.html
Hello word
- add Options +Indexes on .htaccess
cd /var/www/your_folder
nano .htaccess
Options +Indexes