How to deploy a React App on Apache web server

后端 未结 8 2148
谎友^
谎友^ 2020-11-29 18:11

I have created a basic React App from https://www.tutorialspoint.com/reactjs/reactjs_jsx.htm here , I want to run this test code on Apache based server, I know that I need t

8条回答
  •  再見小時候
    2020-11-29 19:00

    1. Go to your project root directory cd example /home/ubuntu/react-js
    2. Build your project first npm run build
    3. check your build directory gracefully all the files will be available in the build folder.

      asset-manifest.json

      favicon.ico

      manifest.json

      robots.txt

      static assets

      index.html

      precache-manifest.ddafca92870314adfea99542e1331500.js service-worker.js

    4.copy the build folder to your apache server i.e /var/www/html

    sudo cp -rf build /var/www/html
    
    1. go to sites-available directory

      cd /etc/apache2/sites-available/

    2. open 000-default.conf file

      sudo vi 000-default.conf and rechange the DocumentRoot path

      enter image description here

    3. Now goto apache conf.

      cd /etc/aapche2

      sudo vi apache2.conf

      add the given snippet

    
    
                Options Indexes FollowSymLinks
    
                AllowOverride All
    
                Require all granted
    
        

    1. make a file inside /var/www/html/build

      sudo vi .htaccess

    Options -MultiViews
        
    RewriteEngine On
        
    RewriteCond %{REQUEST_FILENAME} !-f
    
    RewriteRule ^ index.html [QSA,L]

    9.sudo a2enmod rewrite

    10.sudo systemctl restart apache2

    1. restart apache server

      sudo service apache2 restart

      thanks, enjoy your day

提交回复
热议问题