For some one who will use Nginx from Cetos Hi all, first im using Pro Version so some settings on the end is good for me!
Node.js is a cross-platform JavaScript run-time environment that allows server-side execution of JavaScript code. Node.js is mainly used on the back-end, but it is also popular as a full-stack and front-end solution.
npm, short for Node Package Manager is the default package manager for Node.js and the world’s largest software repository for the publishing of open-source Node.js packages.
This tutorial walks you through the steps to install Node.js and npm on a CentOS 7 machine. We will show you two different ways of installing Node.js and npm.
In the first part of this tutorial we will install Node.js and npm using the yum package manager from the NodeSource repository. In the second part, we will teach you how to install Node.js and npm using the nvm script.
If you need Node.js only for deploying Node.js applications then the simplest option is to install the Node.js packages using yum from the NodeSource repository.
PrerequisitesBefore continuing with this tutorial, make sure you are logged in as a user with sudo privileges. ifi is on server you must have Putty and you are probebly already log in!
Installing Node.js and npm on CentOS 7NodeSource is a company dedicated to providing enterprise-grade Node support and they maintain a consistently-updated Node.js repository for Linux distributions.
To install Node.js and npm from the NodeSource repositories on your CentOS 7 system, follow these steps:
1. Add NodeSource yum repositoryThe current LTS version of Node.js is version 10.x. If you want to install version 8 just change setup_10.x with setup_8.x in the command below.
Run the following curl command to add the NodeSource yum repository to your system:
curl -sL https://rpm.nodesource.com/setup_10.x | sudo bash -
2. Install Node.js and npmOnce the NodeSource repository is enabled, install Node.js and npm by typing:
sudo yum install nodejs
When prompted to import the repository GPG key, type y, and press Enter.
3. Verify the Node.js and npm InstallationTo check that the installation was successful, run the following commands which will print the Node.js and npm versions.
Print Node.js version:node --version
shuld be somthing like
v10.13.0
Print npm version:
npm --version
6.4.1
How to install Node.js and npm using NVMNVM (Node Version Manager) is a bash script used to manage multiple active Node.js versions. NVM allows us to install and uninstall any specific Node.js version which means we can have any number of Node.js versions we want to use or test.
To install Node.js and npm using NVM on your CentOS system, follow these steps:
1. Install NVM (Node Version Manager)To download the nvm install script run the following command:
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
The script will clone the nvm repository from Github to ~/.nvm and add the script Path to your Bash or ZSH profile.
=> Close and reopen your terminal to start using nvm or run the following to use it now:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
As the output above shows, you should either close and reopen your terminal or run the commands to add the path to nvm script to your current session.
To verify that nvm was properly installed type:
nvm --version
0.33.11
2. Install Node.js using NVMNow that the nvm tool is installed we can install the latest available version of Node.js, by typing:
nvm install node
some responce
Downloading and installing node v11.0.0...
Downloading https://nodejs.org/dist/v11.0.0/node-v11.0.0-linux-x64.tar.xz...
######################################################################## 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v11.0.0 (npm v6.4.1)
Creating default alias: default -> node (-> v11.0.0)
Verify the Node.js version, by typing:
node --version
v10.1.0
3. Install multiple Node.js versions using NVMLet’s install two more versions, the latest LTS version and version 8.12.0
nvm install --lts
nvm install 8.12.0
For each wersion you wont to install just type nvm install 1.1.1
Once LTS version and 8.12.0 are installed to list all installed Node.js instances type:
nvm ls
-> v8.12.0 # ACTIVE VERSION
v10.13.0
v11.0.0
default -> node (-> v11.0.0) # DEFAULT VERSION
node -> stable (-> v11.0.0) (default)
stable -> 11.0 (-> v11.0.0) (default)
iojs -> N/A (default)
lts/* -> lts/dubnium (-> v10.13.0)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.14.4 (-> N/A)
lts/carbon -> v8.12.0
lts/dubnium -> v10.13.0
The output tell us that the entry with an arrow on the left (-> v8.12.0), is the version used in the current shell session and the default version is set to v11.0.0. Default version is the version that will be active when opening new shells.
To change the currently active version you can use the following command:
nvm use 10.13.0
The output will look like something this:
Now using node v10.13.0 (npm v6.4.1)
To change the default Node.js version type:
nvm alias default 10.13.0
default -> 10.13.0 (-> v10.13.0)
Install development tools
To be able to build native modules from npm we will need to install the development tools and libraries:
sudo yum install gcc-c++ make
Conclusion
I have shown you two different ways to install Node.js and npm on your CentOS 7 server. The method you choose depends on your requirements and preferences. While installing the packaged version from the NodeSource repository is easier, the nvm method gives you more flexibility for adding and removing different Node.js versions on a per-user basis.
Now all you have to do is to install and run your script i will install Ghost on my production webserver. before that you must have this nvm installed cuz you have flexibility for all other node project on your website or webserver
1. Install a Process Manager
Next, install a process manager so you can control your Node.js applications. This process manager will allow you to keep applications alive forever, to reload them without downtime and to facilitate common system admin tasks. Enter the following command:
npm install pm2 -g
2. Install Ghost on CentOS 7
First, create a directory for your Ghost website:
mkdir /var/www/html/your_site
Enter the newly created dir:
cd /var/www/html/your_site
Download the latest Ghost version:
curl -L https://ghost.org/zip/ghost-latest.zip -o ghost.zip
Unzip the archive:
unzip ghost.zip
Delete the archive:
rm ghost.zip
Now install the app with the npm installer:
npm install -production
3. Configure Ghost CMS
After the installation is completed, configure Ghost and update the URL in the config file with your domain. Copy the example config into a new file:
cp config.example.js config.js
Open the file:
nano config.js
Find the ‘Production’ section and update the URL with your domain. After modifying it should look like this:
// ### Production
// When running Ghost in the wild, use the production environment.
// Configure your URL and mail settings here
production: {
url: 'http://your_domain',
Save and close the file.
Now you can use the process manager that we installed earlier to configure Ghost to run forever. Execute the below command:
NODE_ENV=production pm2 start index.js --name "Ghost"
To start/stop/restart Ghost you can use:
pm2 start Ghost
pm2 stop Ghost
pm2 restart Ghost
4. Configure Nginx to Act as a Reverse Proxy
Your next step is to configure Nginx to act as a reverse proxy for your Ghost application. Open a WebServers manage in your CWPAdmin:
Select Depends on your Configuration of webserver i prefer Nginx & Varnish & Apache, Save and Rebuild configuration.
When rebuild is finish, go to Manage WebServers Configuration select first user and then web site you wont to Configure
Press configure (blue BTN) you will se somthing like this picture
For this configuration select nginx -> proxy -> costum port
-leave Nginx Configuration default
-Chek Rebuild Configuration
- Enter costum your port
-enter your localhost 127.0.0.1 (if you get error in ghost that is configuration error and you must tell that is produstion value
www.yourwebsite.com but here you leave localhost settings coz node.js work in localhost)
5. Test and Restart Nginx Server
Test the Nginx configuration and restart Nginx so the changes can take effect:
# nginx -t
# service nginx restart
I will support this to developer of centos to add into their configuration and create this modern and magnificent CWP even more better
Any Additional test i will glad to help you!