Постоянно забываю как это делать решил задать вопрос здесь, чтобы после можно было его найти.
Как я делаю:
sudo gedit /etc/hosts
добавляю строчку в открывшемся файле
127.0.0.1 test.loc www.test.loc
сохраняем, далее:
sudo gedit /etc/apache2/conf.d/custom/vhosts
добавляем следующее
<VirtualHost *:80>ServerName test.locServerAlias test.locDocumentRoot "/home/www-data/www/test/www"ScriptAlias /cgi/ "/home/www-data/www/test/cgi-bin/"ErrorLog /home/www-data/www/test/error.logCustomLog /home/www-data/www/test/access.log common</VirtualHost>
создаю в "/home/www-data/www" "/home/www-data/www/test/www" c правами 777в результате ввода в браузере http://www.test.loc/ я должен попасть на страничку
/home/www-data/www/test/www/index.php
но видимо я что то упускаю, т.к. открывается другая страница.
вот что у меня БЫЛО в vhosts:
<VirtualHost *:80>ServerName test.locServerAlias test.locDocumentRoot "/home/www-data/www/test/www"ScriptAlias /cgi/ "/home/www-data/www/test/cgi-bin/"ErrorLog /home/www-data/www/test/error.logCustomLog /home/www-data/www/test/access.log common</VirtualHost>
и hosts:
127.0.0.1 localhost127.0.1.1 alexander-A17127.0.0.1 test.loc www.test.loc
всё что не работает перенаправляется на skaz-gorod.loc (в адресной строке адрес не меняется), что я делаю не так?
пользователя www-data добавил в группу пользователя которым являюсь (это не безопасно но мне не страшно :) )Доработал напильником:
вот что у меня СТАЛО в vhosts:
<VirtualHost 127.0.0.5>ServerName test.locServerAlias test.locDocumentRoot "/home/www-data/www/test/www"ScriptAlias /cgi/ "/home/www-data/www/test/cgi-bin/"ErrorLog /home/www-data/www/test/error.logCustomLog /home/www-data/www/test/access.log common</VirtualHost>
и hosts:
127.0.0.1 localhost127.0.1.1 alexander-A17127.0.0.5 test.loc www.test.loc
после сайт открывался с ошибкой:
Internal Server ErrorThe server encountered an internal error or misconfiguration and was
unable to complete your request.
Please contact the server administrator, [no address given] and
inform them of the time the erroroccurred, and anything you might havedone that may have caused the error.
More information about this error may be available in the server error
log.
Apache/2.2.22 (Ubuntu) Server at 127.0.0.5 Port 80
а в логах писал:
[alert] [client 127.0.0.1] /home/www-data/www/test/www/.htaccess:
Invalid command 'RewriteEngine',perhaps misspelled or defined by amodule not included in the serverconfiguration
Ошибка говорит, что не включен модуль Апача rewrite
Решается просто:
sudo a2enmod rewrite
sudo /etc/init.d/apache2 restart
УРА ЗАРАБОТАЛО!