تغییر مسیر پوشه DocumentRoot وب سرور Lamp
وب سرور Lamp محبوب ترین ابزار برای برنامه نویسان لینوکس و ویندوز می باشد که از وب سرور برای اجرای اسکریپت ها و نمایش محتوای وب استفاده می شود.
معمولا پوشه اجرای اسکریپت ها در /var/www قرار گرفته است که در روت قرار گرفته است که نمی توان به راحتی به آن مسیر فایل ها را منتقل کرد, چرا که دسترسی به آن پوشه محدود شده است.
برای حل این مشکل می توانید مسیر پوشه www خارج از روت تغییر دهید که به آن دسترسی داشته باشید.
لینوکس اوبونتو و دبیان :
۱. دستور زیر را در خط فرمان وارد نمایید:
sudo nano /etc/apache2/sites-enabled/000-default.conf
محتوای زیر:
<VirtualHost *:80> # The ServerName directive sets the request scheme, hostname and port that # the server uses to identify itself. This is used when creating # redirection URLs. In the context of virtual hosts, the ServerName # specifies what hostname must appear in the request's Host: header to # match this virtual host. For the default virtual host (this file) this # value is not decisive as it is used as a last resort host regardless. # However, you must set it for any further virtual host explicitly. #ServerName www.example.com ServerAdmin webmaster@localhost DocumentRoot "/home/user/www" # Available loglevels: trace8, ..., trace1, debug, info, notice, warn, # error, crit, alert, emerg. # It is also possible to configure the loglevel for particular # modules, e.g. #LogLevel info ssl:warn ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined # For most configuration files from conf-available/, which are # enabled or disabled at a global level, it is possible to # include a line for only one particular virtual host. For example the # following line enables the CGI configuration for this host only # after it has been globally disabled with "a2disconf". #Include conf-available/serve-cgi-bin.conf </VirtualHost> # vim: syntax=apache ts=4 sw=4 sts=4 sr noet
در خط DocumentRoot قسمت user نام کاربری که در لینوکس تعریف کردید تغییر دهید و ذخیره کنید.
۲. دستور زیر را در خط فرمان وارد کنید:
sudo nano /etc/apache2/apache2.conf
محتوای زیر:
<Directory "/home/user/www"> Options Indexes FollowSymLinks AllowOverride None Require all granted </Directory>
در دایرکتوری قسمت user نام کاربری که در لینوکس تعریف کردید را تغییر دهید و ذخیره کنید.
برای سنت او اس, ردهت, فدورا
دستور زیر را در خط فرمان وارد کنید و مطابق نوشته های بالا تغییر دهید:
sudo nano /etc/httpd/conf/httpd.conf
از ویرایشگر nano برای باز کردن فایل استفاده می کنید برای ذخیره سازی آن اول دکمه Ctrl+X و بعد دکمه Y را بزنید.
در ادامه پوشه www در همان مسیری که تعریف کردید را ایجاد کنید و با دستور زیر وب سرور Lamp راه اندازی مجدد کنید.
sudo systemctl restart apache2
پیوند منابع