Host react app using Apache httpd server on RHEL8
2 min readMar 17, 2021
This tutorial was tested on RHEL 8.3 platform.
- Install Apache Httpd
You can refer this article for how to setup local yum/dnf repository on RHEL 8.
# dnf install httpd
# systemctl enable httpd
# systemctl start httpd
# systemctl status httpd
# firewall-cmd --zone=public --permanent --add-service=http
# firewall-cmd --reload
# firefox localhost
2. Generate production build of your react project
here, Rect app name is myapp
$ cd myapp
$ npm run build
3. Copy and paste everything in build folder to your server
# cp -rf build/* /var/www/html/
4. Httpd configuration
Method 1:
Edit /etc/httpd/conf/httpd.conf
<Directory "/var/www/html">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.4/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride All
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.html [QSA,L]
#
# Controls who can get stuff from this server.
#
Require all granted
</Directory>
Method 2:
a) Edit /etc/httpd/conf/httpd.conf
<Directory “/var/www/html”>
…
AllowOverride All
…
</Directory>
b) create a “.htaccess” file in html directory and add this snippet
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.html [QSA,L]
4. Restart httpd service and test the application
# systemctl restart httpd
# firefox localhost
References: