How to modify webpage content in Apache


To Modify Webpage content in Apache

Apache web server delivers web content and serve many queries at once. Normally webpage will be stored in /var/www/html. The procedures to modify the webpage content in Apache is explained.

Install the apache package

Execute the following command to install apache and its dependencies.

[root@linuxhelp Desktop]# yum install httpd*
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: centos.webwerks.com
 * extras: mirror.nbrc.ac.in
 * updates: mirror.nbrc.ac.in
Resolving Dependencies
--> Running transaction check
.
.
.
Installed:
  httpd.x86_64 0:2.4.6-40.el7.centos.1              httpd-devel.x86_64 0:2.4.6-40.el7.centos.1      
  httpd-manual.noarch 0:2.4.6-40.el7.centos.1       httpd-tools.x86_64 0:2.4.6-40.el7.centos.1      

Complete!


Go to the default web-root directory (/var/www/html/) and create a new directory.

[root@linuxhelp ~]# cd /var/www/html/
[root@linuxhelp html]# mkdir owndir


Open the newly created directory and create a file as index.html with the following HTML code.

[root@linuxhelp html]# cd owndir/
[root@linuxhelp owndir]# vim index.html

<!DOCTYPE html>

<html>
<body>
<p><a href="https://www.linuxhelp.com">Visit our LINUX tutorial</a></p>
</body>
</html>


Create an another file for configuring apache with the following configuration.

[root@linuxhelp ~]# vim /etc/httpd/conf.d/http.conf

<virtualhost *:80>

servername www.linuxhelp.com

documentroot /var/www/html/owndir

</virtualhost>

<directory /var/www/html/owndir>

require all granted

</directory>


Set the selinux context to the newly created file at the web-root directory.

[root@linuxhelp ~]# chcon -Rt httpd_sys_content_t /var/www/html/owndir/


Verify whether the assigned selinux policy is configured or not.

[root@linuxhelp ~]# ls -lZ /var/www/html/owndir/
-rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 index.html

Enable the apache service.

[root@linuxhelp ~]# systemctl enable httpd.service
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.


Enable the firewall settings for apache service and ports and finally reload firewall.

[root@linuxhelp ~]# firewall-cmd --permanent --add-service=http
success
[root@linuxhelp ~]# firewall-cmd --permanent --add-port=80/tcp
success
[root@linuxhelp ~]# firewall-cmd --reload
success


Now restart the apache service.

[root@linuxhelp ~]# systemctl restart httpd.service


Open the browser and navigate to http://<IP_address> to view the webpage content we created.

Tag : Apache
FAQ
Q
how to add the http port to host webpage in apache?
A
Use the following command to add the port for http in apache
# firewall-cmd --permanent --add-service=http

# firewall-cmd --permanent --add-port=80/tcp
Q
How to change the ownership of the web root directory file in apache?
A
you can use the following command to change the ownership of web root directory
# chown -R apache: apache
Q
in which location the web root directory located for apache?
A
The command to view web root dir for apache is
# cd /var/www/html/
Q
What are the content to be edited in apache config file to host web page?
A
Use the following content to edit the apache config file
# vim /etc/httpd/conf.d/http.conf

servername www.linuxhelp.com
documentroot /var/www/html/owndir


require all granted

Q
how to Install the apache package in centos 7?
A
you can install the apache package by following command
# yum install httpd