How to Fix Permission of htdocs in Ubuntu
By default XAMPP server is installed on /opt/xampp directory. The htdocs directory where all the user files are kept is inside the xampp directory. So it is read only. So you cannot read, write, create, remove files of this directory. But that’s not what we want. We want to put our web development files on this directory. This is the topic of this tutorial.
This is a step-by-step tutorial on how to fix the permission of XAMPP server’s htdocs to make it readable and writeable by normal users. To follow this tutorial, you need to have the following requirements:
- A computer with Ubuntu operating system installed.
- XAMPP server software.
- Basic knowledge of Ubuntu terminal. With basic I mean, how to open a terminal on Ubuntu and how to execute commands.
Let’s get started.
Step 1: Open your terminal. Create a folder and name it “public_html” on your home directory using the following command.
Step 2: Now it’s time to edit the apache run user. The apache run user is the user that apache is running as. I am logged in as the user “ubuntu” on my Ubuntu operating system. So I will put “ubuntu” as the user and group. Change it to your login username.To do that type the following command on the terminal and press Enter.
“sudo gedit /opt/lamp/etc/httpd.conf”
You will be prompted for the password. Type in your password and press Enter.
Gedit text editor will open.
Step 3: Now scroll down and look for the line “User daemon”.
This is where we have to change. Replace “daemon” with your Ubuntu login username.
My username is “ubuntu”, so I will put that here.
Step 4: Now we have to tell the server to change the web root or the home directory of the webserver. On the same file, scroll down and look for the line “DocumentRoot”.
Change the DocumentRoot to the directory we created before on our home directory “public_html”.
Change “/opt/lamp/htdocs” to “/home/yourusername/public_html”
My username is “ubuntu” so I will be putting “/home/ubuntu/public_html”.
Also change the line after that to point to this directory as shown in the screenshot below.
Now once you’re done with editing, press Control and S at the same time to save the file. Then close gedit.
Step 5: Now we have to start the XAMPP server. Type in the following command and press enter to start XAMPP server. If you’re prompted for the password enter your user password.
“sudo /opt/lampp/xampp start”
XAMPP server has started.
Step 6: Now create a file inside your home directory’s public_html folder and name it “index.php”. Open it with your favorite text editor and type in some PHP code and save it. I am using gedit to write the php codes.
Step 7: Now open Mozilla Firefox or any other browser of your choice and go to http://127.0.0.1 or http://localhost.Voila! It’s working as expected.
That’s how you fix the permission problem with htdocs of XAMPP server on Ubuntu operating system.