Prereq: root + shell access + WAN-access to Ubuntu 18.04.2-server.
1) Add source for NodeJS: curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
2) Install NodeJS: sudo apt-get install -y nodejs
3) Install tools: sudo apt-get install -y build-essential
4) Install NPM: sudo apt install npm
5.1) Check NodeJS installation: nodejs --version
5.2) Check NPM installation: npm --version
6) Install Apache2: apt install apache2
7.1) Check if Apache2 running: netstat -anp | grep 80
7.2) systemctl status apache2.service
8) Change dir to Apache: cd /var/www/html/ (or /var/www/)
9) Make new directory for your react-app: mkdir test
10) Change dir: cd test
11) Install react-app: npm install -g create-react-app
12) Create react-app: create-react-app my-app
13) Change directory to your app: cd my-app/
14.1) Start dev-server: npm start
OR
14.2) Start prod-server: npm run build
15) Change dir to public folder (under my-app): cd public/
16) Make htaccess-file: vi .htaccess
Config:
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.html [QSA,L]
17) Edit sites-enabled: vi /etc/apache2/sites-enabled/000-default.conf
Config:
<VirtualHost *:80>
ServerName subdomain.domain.com
DocumentRoot /var/www/html/test/my-app/build
ServerAdmin uberadmin@domain.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory "/var/www/html/test/my-app/build">
RewriteEngine on
# Don't rewrite files or directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
# Rewrite everything else to index.html to allow html5 state links
RewriteRule ^ index.html [L]
</Directory>
</VirtualHost>
18) Restart Apache2: service apache2 restart
19) Access: http://subdomain.domain.com from a browser! BOOM!
Kommentarer
Skicka en kommentar