สร้าง public_html ใน Ubuntu 12.04

Set ดังนี้

$ sudo a2enmod userdir
$ sudo service apache2 restart
$ mkdir ~/public_html && chmod 755 ~/public_html

เรียกใช้งานได้ดังนี้

http://localhost/~jack/

ตอนนี้สามารถเรียกใช้ไฟล์ html ได้แล้ว แต่ยังไม่สามารถใช้งาน php ได้ เพราะโดย default แล้วจะไม่สามารถใช้งานได้เนื่องจากเรื่องของความปลอดภัย แต่สามารถแก้ไขให้ใช้งานได้ดังนี้

เปิดไฟล์ php5.conf

comment out บรรทัด  php_admin_value engine Off

Before:

After:

Save and exit, then reload apache2 configuration with following commad:

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

If you done, open the web browser then access http://[hostname]/~username/info.php.

apache2 userdir module testing phpinfo  How to Enable and Configure Apache2 Userdir Module in Ubuntu Server 12.04

Link Reference :

Ref: How to Enable and Configure Apache2 userdir Module in Ubuntu Server 12.04

Apache : How to Enable mod_rewrite on Ubuntu

เปิดใช้โมดูล mod_rewrite

sudo a2enmod rewrite

แก้ไฟล์คอนฟิก

sudo nano /etc/apache2/sites-enabled/000-default

แก้ไข none ให้เป็น all

<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
</Directory>

สุดท้าย บูต Apache ใหม่

sudo /etc/init.d/apache2 restart
ตรวจสอบว่าใช้ได้หรือยังด้วยคำสั่ง
apache2ctl -M

อย่าลืมตรวจสอบไฟล์ .htaccess มาได้ copy มาไว้ที่ /var/www แล้วหรือไม่ เพราะบางครั้ง มันไม่ได้ copy มา ไม่รู้ว่าทำไม ‘-_-

เท่านี้ Clean URL ก็จะใช้ได้แล้ว
ที่มา: drupal.in.thdrupal.org/

Apache on Mac

go to: System Preferences > Sharing

check on Web Sharing

Example, http://localhost

or http://localhost/~yourname/

Source Directory

/Library/WebServer/Documents

/Users/yourname/Sites/your web pages are here

Ref devarticles.com