{"id":961,"date":"2014-12-11T15:35:50","date_gmt":"2014-12-11T15:35:50","guid":{"rendered":"http:\/\/www.nikola-breznjak.com\/blog\/?p=961"},"modified":"2015-08-16T20:08:56","modified_gmt":"2015-08-16T20:08:56","slug":"installing-men-npp-stack-mongodb-express-node-js-nginx-postgresql-php-on-centos-7-from-scratch","status":"publish","type":"post","link":"https:\/\/nikola-breznjak.com\/blog\/servers\/installing-men-npp-stack-mongodb-express-node-js-nginx-postgresql-php-on-centos-7-from-scratch\/","title":{"rendered":"Installing MEN NPP stack (MongoDB, Express, Node.js, Nginx, PostgreSQL, PHP) on CentOS 7 from scratch"},"content":{"rendered":"<p>I&#8217;ve been playing with my VPS that <a href=\"http:\/\/www.nikola-breznjak.com\/blog\/servers\/vps-with-1gb-of-ram-for-19-per-year\/\">I bought from<\/a>\u00a0WeLoveServers.net and I previously wrote about <a href=\"http:\/\/www.nikola-breznjak.com\/blog\/servers\/setting-up-your-own-vps-from-scratch\/\">how to set up your VPS from scratch<\/a>. Here I&#8217;ll show just brief commands for\u00a0installing a MEN NPP stack (MongoDB, Express, Node.js, Nginx, PostgreSQL, PHP)\u00a0on my CentOS machine.<\/p>\n<h3>Nginx<\/h3>\n<ul>\n<li>high performance web server that is much more flexible and lightweight than Apache<\/li>\n<li>SELinux &#8211; if you run into issues change the SELinux mode to <strong>permissive<\/strong> or <strong>disabled<\/strong><\/li>\n<li>sudo rpm -Uvh http:\/\/nginx.org\/packages\/centos\/7\/noarch\/RPMS\/nginx-release-centos-7-0.el7.ngx.noarch.rpm<\/li>\n<li>sudo yum install nginx<\/li>\n<li><strong>sudo systemctl start nginx.service<\/strong> or <strong>sudo service nginx start<\/strong><\/li>\n<li>sudo systemctl enable nginx.service (no alternative with sudo service)<\/li>\n<li>default server root directory <strong>\/usr\/share\/nginx\/html<\/strong> defined\u00a0\/etc\/nginx\/conf.d\/default.conf<\/li>\n<li><strong>server blocks<\/strong> (known as <strong>Virtual Hosts<\/strong> in Apache) are\u00a0created in <strong>\/etc\/nginx\/conf.d<\/strong>. Files that end with <strong>.conf<\/strong> in that directory will be loaded when Nginx is started<\/li>\n<li>main Nginx configuration file is located at \/etc\/nginx\/nginx.conf<\/li>\n<\/ul>\n<ul>\n<li><strong>sudo vi \/etc\/nginx\/conf.d\/default.conf<\/strong> looks like:\n<pre class=\"lang:default decode:true \">server {\r\n    listen       80;\r\n    server_name  localhost;\r\n\r\n    location \/ {\r\n        root   \/usr\/share\/nginx\/html;\r\n        index  index.html index.htm;\r\n    }\r\n    error_page   500 502 503 504  \/50x.html;\r\n    location = \/50x.html {\r\n        root   \/usr\/share\/nginx\/html;\r\n    }\r\n}<\/pre>\n<p>change to:<\/p>\n<pre class=\"lang:default decode:true\">server {\r\n    listen       80;\r\n    server_name  server_domain_name_or_IP;\r\n\r\n    root   \/usr\/share\/nginx\/html;\r\n    index index.php index.html index.htm;\r\n\r\n    location \/ {\r\n        try_files $uri $uri\/ =404;\r\n    }\r\n    error_page 404 \/404.html;\r\n    error_page 500 502 503 504 \/50x.html;\r\n    location = \/50x.html {\r\n        root \/usr\/share\/nginx\/html;\r\n    }\r\n\r\n    location ~ \\.php$ {\r\n        try_files $uri =404;\r\n        fastcgi_pass unix:\/var\/run\/php-fpm\/php-fpm.sock;\r\n        fastcgi_index index.php;\r\n        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;\r\n        include fastcgi_params;\r\n    }<\/pre>\n<\/li>\n<li><strong>sudo systemctl restart nginx<\/strong><\/li>\n<li><strong>sudo nginx -t<\/strong><br \/>\nnginx: the configuration file \/etc\/nginx\/nginx.conf syntax is ok<br \/>\nnginx: configuration file \/etc\/nginx\/nginx.conf test is successful<\/li>\n<\/ul>\n<h3><\/h3>\n<h3>Node.js<\/h3>\n<ul>\n<li>just a side note for Mac: <strong>brew install node<\/strong><\/li>\n<li>sudo yum install epel-release<\/li>\n<li>sudo yum install node<\/li>\n<li>sudo yum install npm<\/li>\n<\/ul>\n<h3>Express<\/h3>\n<ul>\n<li>npm install express<\/li>\n<\/ul>\n<h3>PHP<\/h3>\n<ul>\n<li><strong>sudo yum install php php-mysql php-fpm<\/strong><\/li>\n<li>sudo vi \/etc\/php.ini &#8211; in order to secure it do\u00a0<strong>cgi.fix_pathinfo=0<\/strong><\/li>\n<li><strong>sudo vi \/etc\/php-fpm.d\/www.conf<\/strong> set\u00a0line to\u00a0listen = \/var\/run\/php-fpm\/php-fpm.sock<\/li>\n<li><strong>sudo systemctl start php-fpm<\/strong><\/li>\n<li><strong>sudo systemctl enable php-fpm.service<\/strong> to start from boot<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h3>PostgreSQL<\/h3>\n<ul>\n<li>exclude the CentOS version of postgres in order to get the most recent version from the project&#8217;s website<\/li>\n<li><strong>sudo vim \/etc\/yum.repos.d\/CentOS-Base.repo<br \/>\n<\/strong>At the bottom of the <strong>[base]<\/strong> and <strong>[updates]<\/strong> sections, add a line that excludes the postgres packages:\u00a0<strong>exclude=postgresql*<\/strong><\/li>\n<li>Find the link for your version of the OS <a href=\"http:\/\/yum.postgresql.org\/repopackages.php\">here<\/a><\/li>\n<li>curl -O http:\/\/yum.postgresql.org\/9.4\/redhat\/rhel-7-x86_64\/pgdg-centos94-9.4-1.noarch.rpm<\/li>\n<li>rpm -ivh pgdg*<\/li>\n<li>yum list postgres*<\/li>\n<li>install\u00a0the -server package: <strong>sudo\u00a0postgresql94-server.x86_64<\/strong><\/li>\n<li><strong>sudo \/usr\/pgsql-9.4\/bin\/postgresql94-setup initdb<br \/>\n<\/strong><\/li>\n<li>chkconfig postgresql-9.3 on<\/li>\n<li>service postgresql-9.3 start<\/li>\n<li>postgres creates a user and a database called <strong>postgres<\/strong><\/li>\n<li>sudo\u00a0su &#8211; postgres<\/li>\n<li>psql<\/li>\n<li>\\?: Get a full list of psql commands, including those not listed here<\/li>\n<li>\\h: Get help on SQL commands. You can follow this with a specific command to get help with the syntax<\/li>\n<li>\\q: Quit the psql program and exit to the Linux prompt<\/li>\n<li>\\d: List available tables, views, and sequences in current database<\/li>\n<li>\\du: List available roles<\/li>\n<li>\\dp: List access privileges<\/li>\n<li>\\dt: List tables<\/li>\n<li>\\l: List databases<\/li>\n<li>\\c: Connect to a different database. Follow this by the database name<\/li>\n<li>\\password: Change the password for the username that follows<\/li>\n<li>\\conninfo: Get information about the current database and connection\n<pre class=\"lang:default decode:true \">CREATE TABLE new_table_name (\r\n    table_column_title TYPE_OF_DATA column_constraints,\r\n    next_column_title TYPE_OF_DATA column_constraints,\r\n    table_constraint\r\n    table_constraint\r\n) INHERITS existing_table_to_inherit_from;<\/pre>\n<p>&nbsp;<\/li>\n<\/ul>\n<h3>MongoDB<\/h3>\n<ul>\n<li>Instructions from <a href=\"http:\/\/docs.mongodb.org\/manual\/tutorial\/install-mongodb-on-red-hat-centos-or-fedora-linux\/\">here<\/a><\/li>\n<li>sudo vim\u00a0\/etc\/yum.repos.d\/mongodb.repo:\n<pre class=\"lang:default decode:true\">[mongodb]\r\nname=MongoDB Repository\r\nbaseurl=http:\/\/downloads-distro.mongodb.org\/repo\/redhat\/os\/x86_64\/\r\ngpgcheck=0\r\nenabled=1<\/pre>\n<\/li>\n<li><strong>sudo yum install -y mongodb-org<\/strong><\/li>\n<li>to prevent unintended upgrades, add to \/etc\/yum.conf file:<br \/>\nexclude=mongodb-org,mongodb-org-server,mongodb-org-shell,mongodb-org-mongos,mongodb-org-tools<\/li>\n<li>sudo service mongod start<\/li>\n<li>sudo chkconfig mongod on<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve been playing with my VPS that I bought from\u00a0WeLoveServers.net and I previously wrote about how to set up your VPS from scratch. Here I&#8217;ll show just brief&hellip;<\/p>\n","protected":false},"author":1,"featured_media":971,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[38],"tags":[],"class_list":["post-961","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-servers"],"_links":{"self":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts\/961","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/comments?post=961"}],"version-history":[{"count":7,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts\/961\/revisions"}],"predecessor-version":[{"id":982,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts\/961\/revisions\/982"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/media\/971"}],"wp:attachment":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/media?parent=961"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/categories?post=961"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/tags?post=961"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}