Linux under Apache to replace its working directory

Source: Internet
Author: User
Tags 403 forbidden error

Modify the default document directory for Apache2 (default is/var/www)
Modify command:sudo gedit/etc/apache2/sites-enabled/000-default
Locate the DocumentRoot in the document and modify the directory where you want to place the Web page file.
Restart Apache2 server after modification, restart command: sudo/etc/init.d/apache2 restart

In Linux under the development of HTML, PHP and other programs, the default to the/var/www directory to work, and the/var/www directory must have Superuser privileges to access, but also to change the permissions of this directory. Would it be nice to add a working directory of your own, for example:/home/konghy/www. Here is an implementation method, my Apache version is: Server version:apache/2.4.7 (Ubuntu).

1. Open the/etc/apache2/ports.conf file to add a port, such as add 8080 port, add Listen 8080 to the file

$ sudo vi /etc/apache2/ports. Conf

As shown below:

# If You just change the port or add more ports here, you'll likely also
# has to change the VirtualHost statement in
#/etc/apache2/sites-enabled/000- default.conf

listen 80
listen 8080

<ifmodule Ssl_module>
    443
</ Ifmodule>

<ifmodule mod_gnutls.c>
    Listen 443
</ifmodule>

# Vim:syntax=apache ts=4 sw=4 sts=4 sr noet


2.&NBSP; Copy/etc 000-default.conf file in/apache2/sites-available directory: &NBSP;

$ sudo cp /etc//sites-available /000-default. conf /etc/apache2/< Span class= "PLN" >sites-available/my< Span class= "pun". conf

Change documentroot/var/www/html to its own directory, for example: Documentroot/home/konghy/www

3.   my.conf soft links to sites-enabled:

$ sudo ln -s /etc< Span class= "pun" >/apache2/sites-available/my. conf /etc/apache2/< Span class= "PLN" >sites-enabled/myconf


4. Restart Apache Service

sudo service apache2 restart


5. in the/home/konghy/www directory, create a test page index.html, open in the browser: http://localhost:8080/if the display is normal, the configuration ends.

6. If the page does not display properly and prompts for 403 Forbidden error: You do not have the permission to access/on the this server.
Workaround: Open the/etc/apache2/apache2.conf file and add the content:

<directory /home/konghy/www>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>


7. in order to ensure that Apache access to your configured directory, Apache users can be added to their own user group, Apache's default user name is Www-data, modified by:

$ sudo usermod -a -G konghy www-data

Konghy the user group for the current user

Reprint http://konghy.blog.163.com/blog/static/2405390462015022515167/

Linux under Apache to replace its working directory

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.