ข้ามไปที่เนื้อหาหลัก

Use PHP for user on Ubuntu Desktop

How to setup user run php script file on user for ubuntu.

1. Open terminal and add a user you want to work on system, By command. 


adduser username

(I have user imodclub).

2. Make Folder name public_html (not change name) at user home folder.

mkdir /home/username/public_html


3. Set owner public_html for user.

4. Install apache server and php script from software center

    4.1 Open software center and search apache2 and install.

    4.2  Search php5 and install.
finish and close software center.

5. Open terminal and make soft-link for load module on apache start, by command.

ln -s /etc/apache2/mods-available/userdir.load /etc/apache2/mods-enabled/userdir.load

ln -s /etc/apache2/mods-available/userdir.conf /etc/apache2/mods-enabled/userdir.conf

finish and check file.

more /etc/apache2/mods-available/userdir.conf


no config.

6. restart apache by command.

/etc/init.d/apache2 force-restart

7. Test HTML file.

create html file for test file on folder public_html

(Test for GUI)

7.1 open folder public_html and right click. select Create new Document--> Empty Document 

 set name document test.html

7.2 Open file test.html with text editor and insert text.

<html>
<title>test html for user</title>
<body>
Test html for user<br>
Test html for user<br>
Test html for user<br>
</body>
</html>

finish and save file.

7.3 run html file on browser by open a web browser. open URL

http://localhost/~user/test.html




8. Config apache to run script PHP for user

8.1 open terminal and edit php5.conf

nano /etc/apache2/mods-available/php5.conf

close tag (insert comment)     #            php_admin_value engine Off


 <IfModule mod_php5.c>
    <FilesMatch "\.ph(p3?|tml)$">
        SetHandler application/x-httpd-php
    </FilesMatch>
    <FilesMatch "\.phps$">
        SetHandler application/x-httpd-php-source
    </FilesMatch>
    # To re-enable php in user directories comment the following lines
    # (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it
    # prevents .htaccess files from disabling it.
    <IfModule mod_userdir.c>
        <Directory /home/*/public_html>
#            php_admin_value engine Off
        </Directory>
    </IfModule>
</IfModule>



finish and save.
8.2 restart apache2

8.3 test PHP File.

create php test.php on folder public_html and insert script.

<?php
echo "Hello public_html<br>";
echo "Hello public_html<br>";
echo "Hello public_html<br>";
echo "Hello public_html<br>";
echo "Hello public_html<br>";
echo "Hello public_html<br>";
echo "Hello public_html<br>";
echo "Hello public_html<br>";
echo "Hello public_html<br>";

?>


save and run

http://localhost/~user/test.php

the end.