ClickCease

Creating an Apache based YUM/DNF repository on RHEL 8

Introduction to Local Repositories

Repositories are used everywhere and can be accessed worldwide. You even know how to create your own repository using the RHEL DVD and installing packages through it. What we will do today is create a local repository on a machine (server) and allow access to other machines on that server through a web server.

Advantages of creating a local repository:

  • No need of an internet connection to download packages
  • Since the packages are available locally, the download speed increases

Pre-requisities:

In order to setup a local Apache based repository on RHEL8, please ensure that you meet the following requirements:

  • A local RHEL8 machine present to use as server
  • A local RHEL8 client machine present to check
  • RHEL8 Installation DVD
  • Apache Webserver package

Before starting, ensure that you have mounted the media which contains RHEL8

Part 1: Setting up the Server

Step 1: Creat a local YUM repository from the mounted media

1.1 Move the existing repo files in /etc/yum.repos.d to another location

mv /etc/yum.repos.d/*.repo /tmp/
creating an apache based yum/dnf repository

1.2 Now, create a directory for the repository using mkdir

mkdir /local_repo

(This directory will be used for serving files over the connection to other machines)

1.3 Now create the local repository configuration file in the /etc/yum.repos.d directory

touch /etc/yum.repos.d/local-dvd.repo
creating an apache based yum/dnf repository

1.4 Change permissions for this file using chmod

chmod u+rw,g+r,o+r /etc/yum.repos.d/local-dvd.repo
creating an apache based yum/dnf repository

Step 2: Copy media content to local directory

2.1 use the cd command to navigate to your RHEL8 ISO and copy it under /local_repo using the command given below

tar cvf - . | (cd /local_repo/; tar xvf -)

2.2 Once the files are done being copied, use the following to verify

ls -l /local_repo/
creating an apache based yum/dnf repository

Step 3: Configure the local YUM/DNF repository

3.1 Edit the repository configuration file which we created earlier using

vim /etc/yum.repos.d/local-dvd.repo

Ensure that it looks like this

creating an apache based yum/dnf repository

3.2 Now install the packages required to create, configure and manage the local repository

yum repolist
yum install createrepo yum-utils
creating an apache based yum/dnf repository

3.3 Run the createrepo command to create the repository

createrepo /local_repo/
creating an apache based yum/dnf repository

Step 4: Test and verify your local repository

yum clean all
yum repolist

4.1 Verify that the local repo was created through the ls command

ls /local_repo/repodata/
creating an apache based yum/dnf repository

Ensure that the results look similar

Step 5: Setting up the apache server

5.1 Install apache using the given command

yum install httpd

5.2 Start and enable apache using systemctl

systemctl start httpd
systemctl enable httpd

5.3 Configure the firewall so the Apache can be reached

firewall-cmd --zone=public --permanent --add-service=http 
firewall-cmd --zone=public --permanent --add-service=https 
firewall-cmd --reload success
creating an apache based yum/dnf repository

5.4 Configure apache through its configuration file

vim /etc/httpd/conf/httpd.conf

5.5 Find the line ‘DocumentRoot’ and ‘/var/www’ and change it as per the screenshot below

creating an apache based yum/dnf repository

5.6 Now start apache again

5.7 Once apache starts normally, remove the default welcome page so you can serve the repository files

rm -rvf /etc/httpd/conf.d/welcome.conf

5.8 Test apache using the command given below

httpd -t
creating an apache based yum/dnf repository

5.9 Restart apache

systemctl restart httpd

Step 6: Changing Permissions and setting up SELinux

6.1 We need to configure the security by changing permissions on the local_repo directory

setfacl -R -m u:apache:rwx /local_repo/
creating an apache based yum/dnf repository

6.2 Check whether SELinux is in enforcing mode

getenforce

6.3 If SELinux is not in enforcing mode, enforce it through

setenforce enforcing

6.4 Now, type

chcon -Rt httpd_sys_content_t /local_repo/
creating an apache based yum/dnf repository

Part 2: Setting up the client

Step 7: add the local repo to the client machine

vim /etc/yum.repos.d/local-rhel8.repo

7.1 Ensure that your configuration file looks like this, change IP address when required

creating an apache based yum/dnf repository

Step 8: Test the repo

yum clean all
yum install mc
creating an apache based yum/dnf repository

Additional

In case you are tired of the subscription manage error while running the YUM or DNF then simply go to the subscription manager config file and change a value.

vim /etc/yum/pluginconf.d/subscription-manager.conf

The value for enabled will be 1. Change it to 0.

creating an apache based yum/dnf repository

More Knowledge?

Check out our other free articles on our blog.
New to Linux? Go for the Linux course.
Want to learn automation? Try our Master Devops Program.
Fresher who needs a job? Our Job Guarantee Program is perfect for you.
If you are an expert with Linux, grow your career with AWS, Devops, Openstack or Openshift.