Are you willing to host react on Apache ??
Here are few steps.
STEP 1 - Install Apache.
sudo apt install apache2
This command will install apache on you machine.
STEP 2 - Pull code.
Go to
cd /var/www/html
and pull your react code using git
sudo git clone <your-git-repo>
Install dependencies
sudo npm install
and build your react project using
sudo npm run build
you production will be in build folder now
STEP 3 - Configure your Apache config files
You will have to mention path of build folder in .config files.
edit /etc/apache2/apache2.conf
sudo vi /etc/apache2/apache2.conf
Comment existing Directory tags to avoid conflicts for example in my case I commented by adding # as shown below
#<Directory />
# Options FollowSymLinks
# AllowOverride None
# Require all denied
#</Directory>
#
#<Directory /usr/share>
# AllowOverride None
# Require all granted
#</Directory>
#<Directory /var/www/>
# Options Indexes FollowSymLinks
# AllowOverride None
# Require all granted
#</Directory>
#<Directory /srv/>
# Options Indexes FollowSymLinks
# AllowOverride None
# Require all granted
#</Directory>
STEP 4 - Add our React build directory into apache.conf.
Here in my case build of react is at /var/www/html/reactproject/build it may be different in your case replace this with you present build directory in following code
<VirtualHost *:80>
#ServerName yourserver.com
DocumentRoot /var/www/html/reactproject/build
# Relax Apache security settings
<Directory /var/www/html/reactproject/build>
Allow from all
Options -MultiViews
Require all granted
</Directory>
</VirtualHost>
STEP 5 - Restart and test
Every time you edit Apache files restart apache by using following command
sudo systemctl restart apache2.service
Check status
sudo systemctl status apache2.service
You are good to go. for further assistance feel free to contact me will love to help you out
IF YOU LIKED THIS ARTICLE MAKE SURE TO FOLLOW ME ON DEV.TO AND ON INSTAGRAM
Top comments (0)