Question

How to Upload My Web Server after installation Apache, MySQL and PHP?

Posted October 19, 2020 156 views
ApacheHTML

Hello everyone,

I just install Apache, MySQL and PHP. when I call http://server ip, it shows Apache Default Webpages. I change index.html file name to index.html.org from /var/www/html. And it doesn’t show Apache default web page.

After that I download html website template from google and all of files include index.html. But when I call http://server ip, it shows, You don’t have permission to access this resource. How can I solve it.

If my ways are wrong, please tell me how to upload webpages to apache webserver.

Thank you for your time.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
2 answers

Hi @EiMonHtun,

So, you can check Apache’s DocumentRoot by viewing the following file :

/etc/apache2/sites-enabled/000-default.conf

In it, you should see a DocumentRoot. Usually, as you mentioned it’s /var/www/html. You can check just to be on the safe side.

Having said that, what I think you’ve done is created a new index.html with different ownership, most probably root:root`` however Apache has specific group and user that needs to be. Usually it'swww-data:www-data`“ however you can check that as well. Open the file

/etc/apache2/envvars

Inside search for

export APACHE_RUN_USER
export APACHE_RUN_GROUP

It will show you what group and user you should create the files with. Once you know what it should be, you can use the chown command on the files you’ve added.

Regards,
KFSys

  • I download web template include index.html from internet and copy to /var/www/html/. Is it correct and next step what should I do? please help me.

    • You’ve most probably copied it using the root user, no? In that case when you go to that directory and type in

      ls -lah
      

      Do you see the ownership of the files being root:root? If they are, then you need to change them to be the ownership of Apache. You can get the information from the envvars file I pointed out in the previous reply.

Hi,
Besides all the things mentioned by @KFSys, SELinux may be an another possible cause of your issue, if it is installed and enabled, of course. To check if it is enabled, run:

sestatus

Installed and enabled SELinux gives the output like:

Output
SELinux status: enabled SELinuxfs mount: /sys/fs/selinux SELinux root directory: /etc/selinux Loaded policy name: targeted Current mode: enforcing Mode from config file: enforcing Policy MLS status: enabled Policy deny_unknown status: allowed Max kernel policy version: 31

I highlighted the results indicating that SELinux is enabled and enforces its policies.
So, if you get the status as above, you can turn on SELinux permissive mode for troubleshooting purposes:

sudo setenforce 0

If you can get your website in the browser now, that may indicate that your website directories/files are labeled incorrectly, due to SELinux scheme. So, you need to check it out, and fix it. You mentioned that your website root directory is /var/www/html/. List its content with SELinux labels:

sudo ls -laZ /var/www/html/

You will get something similar to:

Output
drwxr-xr-x. qq qq system_u:object_r:httpd_sys_content_t:s0 . drwxr-xr-x. root root system_u:object_r:httpd_sys_content_t:s0 .. -rw-rw-r--. qq qq unconfined_u:object_r:httpd_sys_content_t:s0 index.html

I highlighted the correct label for website files and directories. If the label of your index file is different, you can add the correct one running:

sudo semanage fcontext -a -t httpd_sys_content_t "/var/www/html(/.*)?"

Actually, that command adds label to /var/www/html/ directory and all its content. Then, you need to set up the added label as a default one.

sudo restorecon -R -v /var/www/html

Now you can turn on SELinux enforcing mode

sudo setenforce 1

Let me know if it works, pls.

More info on SELinux you can find here.

Submit an Answer