質問

I have various websites in my /home/user/projects folder and I want to be able to test them on the browser with Apache2 (they have PHP files and connect to databases).

I don't want to copy them to var/www each time I change something. I just want to open an URL in the browser and Apache should do the rest. Would also be great to assign fake domains by editing the hosts file but I don't know how to achieve it. I tried this solution but I can't access the files.

UPDATE This is what I did up to now:

  1. Firstly, I configure the hosts file. I open the etc/hosts file with sudo and add the following line: 127.0.0.2 projects. Now I am supposed to be able to access http://projects from the browser

  2. Secondly, the Apache Virtual Directory. Inside the etc/apache2/sites-available folder I create a new file called projects and add the following code (inside /home/user/projects I have an index.html file):

    <VirtualHost *:80> ServerName com DocumentRoot /home/user/projects </VirtualHost>

    I saved and executed sudo a2ensite projects, to activate the host. The symbolic links have been created in /etc/apache2/sites-enabled

  3. Testing, after restarting Apache with sudo service apache2 restart. I only get this warning twice:

    Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName

    Now I enter http://projects in my browser but a 403 Forbidden error is displayed (You don't have permission to access / on this server). I changed permissions of the /home/user/projects with sudo chmod -R 755 /home/user/projects, it is executable yet the same result.

役に立ちましたか?

解決

For the warning you should just add ServerName in your global configuration file.

<VirtualHost 127.0.0.2:80> ServerName com DocumentRoot /home/user/projects </VirtualHost>

For the error you should changer the owner of your website folder like this: chown user_apache.group_apache /home/user/projects -R (for example in ubuntu/debian chown www-data.www-data /home/user/projects -R)

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top