Skip to content

Instantly share code, notes, and snippets.

@imbudhiraja
Last active November 19, 2019 05:56
Show Gist options
  • Save imbudhiraja/8215398b89066d4cf53e58a784d850c5 to your computer and use it in GitHub Desktop.
Save imbudhiraja/8215398b89066d4cf53e58a784d850c5 to your computer and use it in GitHub Desktop.
-------------------------------------- SERVER SETUP STEPS -------------------------------------------------------
******************************* DEPENDENCIES INSTALLATION *******************************
1. Check ubuntu version using command, lsb_release -a
2. Install apache according to ubuntu version
3. apt-get update
4. apt-get install apache2
5. INSTALL NVM FROM HERE---------------- https://gist.github.com/d2s/372b5943bce17b964a79
6. Install Node - nvm install v8.9.0 or higher
7. Install MongoDB - https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/
8. Install PM2 globally - sudo npm install pm2 -g
9. apt-get install python-minimal
10. apt-get install git-core
11. sudo apt-get install g++ build-essential
12. cd /opt && git clone https://github.com/certbot/certbot.git - https://medium.com/@saurabh6790/generate-wildcard-ssl-certificate-using-lets-encrypt-certbot-273e432794d7
******************************* ENABLE REQUIRED PORTS AND MODES *******************************
1. sudo ufw allow 3003/tcp , here 3003 is port number
2. a2enmod rewrite
3. a2enmod proxy_http
4. a2enmod proxy
5. a2enmod proxy_wstunnel
******************************* GENERAL COMMANDS *******************************
sudo systemctl restart apache2
sudo systemctl stop apache2
sudo service mongod start
sudo service mongod restart
sudo service mongod stop
sudo service mongod status
apachectl configtest - Test all apache site or modes configurations
pm2 start file.js --name projectname
pm2 ls
pm2 delete processname or index
pm2 stop processname or index
pm2 restart processname or index
pm2 logs processname or index
pm2 start npm --name "next" -- start // start web server using NextJs
****************************** Clone Repo *****************************
1. cd /home
2. Git clone your repo(s) here.
******************************* Site Configuration *******************************
IF YOU WANT AN API SETUP FOLLOW API PROCESS ONLY or vice versa.
------------------------- (API e.g NodeJS) --------------------------
1. Goto cd /etc/apache2/sites-available
2. cp 000-default.conf api.example.conf
3. nano api.example.conf
4. Update the file with below code
```
<VirtualHost *:80>
ServerAdmin demo@example.io
DocumentRoot /home/foldername/
ServerName api.example.com
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/socket.io [NC]
RewriteCond %{QUERY_STRING} transport=websocket [NC]
RewriteRule /(.*) ws://127.0.0.1:3006/$1 [P,L]
ProxyPass /socket.io http://127.0.0.1:3006/socket.io
ProxyPassReverse /socket.io http://127.0.0.1:3006/socket.io
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:3005/
ProxyPassReverse / http://127.0.0.1:3005/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteCond %{SERVER_NAME} =api.example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
```
5. Save and Exit Ctrl + O and Ctrl + X
6. Enable site - a2ensite api.example.conf
7. apachectl configtest
8. sudo systemctl restart apache2
9. You will see refernce of this file in /etc/apache2/sites-enabled
10. Goto cd /home/foldername
11. npm i
12. pm2 start index.js --name projectname
------------------------- (Website e.g. ReactJS) --------------------------
1. Goto cd /etc/apache2/sites-available
2. cp 000-default.conf web.example.conf
3. nano web.example.conf
4. Update the file with below code
```
<VirtualHost *:80>
ServerAdmin demo@example.io
DocumentRoot /home/foldername/dist
ServerName web.example.com
<Directory /home/foldername/dist>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Allow from All
Require all granted
</Directory>
RewriteEngine on
RewriteCond %{SERVER_NAME} =web.example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
```
5. apachectl configtest
6. Save and Exit Ctrl + O and Ctrl + X
7. Enable site - a2ensite web.example.conf
8. sudo systemctl restart apache2
9. You will see refernce of this file in /etc/apache2/sites-enabled
ADDTIONAL INFO
1. DocumentRoot path must contain a index.html file.
2. cd /home/foldername/dist
3. nano .htaccess -
4. add below code then save and Exit
```
RewriteEngine On
# If an existing asset or directory is requested go to it as it is
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]
# If the requested resource doesn't exist, use index.html
RewriteRule ^ /index.html
```
******************************* ENABLE SSL *******************************
1. Go to cd /opt/certbot
2. Run ./certbot-auto and Follow instructions.
Good Byeeeee Have a happy time while server setup.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment