Set ดังนี้
$ sudo a2enmod userdir
$ sudo service apache2 restart
$ mkdir ~/public_html && chmod 755 ~/public_html
เรียกใช้งานได้ดังนี้
http://localhost/~jack/
ตอนนี้สามารถเรียกใช้ไฟล์ html ได้แล้ว แต่ยังไม่สามารถใช้งาน php ได้ เพราะโดย default แล้วจะไม่สามารถใช้งานได้เนื่องจากเรื่องของความปลอดภัย แต่สามารถแก้ไขให้ใช้งานได้ดังนี้
เปิดไฟล์ php5.conf
1 |
<strong>sudo nano /etc/apache2/mods-available/php5.conf</strong> |
comment out บรรทัด php_admin_value engine Off
Before:
1 2 3 4 5 6 7 |
<strong>…</strong> <strong> <IfModule mod_userdir.c></strong> <strong> <Directory /home/*/public_html></strong> <strong> php_admin_value engine Off</strong> <strong> </Directory></strong> <strong> </IfModule></strong> <strong> …</strong> |
After:
1 2 3 4 5 6 7 |
<strong>…</strong> <strong> <IfModule mod_userdir.c></strong> <strong> <Directory /home/*/public_html></strong> <strong> # php_admin_value engine Off</strong> <strong> </Directory></strong> <strong> </IfModule></strong> <strong> …</strong> |
Save and exit, then reload apache2 configuration with following commad:
1 |
<strong>sudo /etc/init.d/apache2 reload</strong> |
To testing PHP script work or not in the public_html directory, you can create some php script. In this case we are usingphpinfo, in terminal type following command
1 |
<strong>echo '<?php phpinfo(); ?>' > ~/public_html/info.php</strong> |
If you done, open the web browser then access http://[hostname]/~username/info.php.
Link Reference :
Ref: How to Enable and Configure Apache2 userdir Module in Ubuntu Server 12.04