I’ve been playing with my VPS that I bought from WeLoveServers.net and I previously wrote about how to set up your VPS from scratch. Here I’ll show just brief commands for installing a MEN NPP stack (MongoDB, Express, Node.js, Nginx, PostgreSQL, PHP) on my CentOS machine.
Nginx
- high performance web server that is much more flexible and lightweight than Apache
- SELinux – if you run into issues change the SELinux mode to permissive or disabled
- sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
- sudo yum install nginx
- sudo systemctl start nginx.service or sudo service nginx start
- sudo systemctl enable nginx.service (no alternative with sudo service)
- default server root directory /usr/share/nginx/html defined /etc/nginx/conf.d/default.conf
- server blocks (known as Virtual Hosts in Apache) are created in /etc/nginx/conf.d. Files that end with .conf in that directory will be loaded when Nginx is started
- main Nginx configuration file is located at /etc/nginx/nginx.conf
- sudo vi /etc/nginx/conf.d/default.conf looks like:
server { listen 80; server_name localhost; location / { root /usr/share/nginx/html; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } }
change to:
server { listen 80; server_name server_domain_name_or_IP; root /usr/share/nginx/html; index index.php index.html index.htm; location / { try_files $uri $uri/ =404; } error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } location ~ \.php$ { try_files $uri =404; fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }
- sudo systemctl restart nginx
- sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Node.js
- just a side note for Mac: brew install node
- sudo yum install epel-release
- sudo yum install node
- sudo yum install npm
Express
- npm install express
PHP
- sudo yum install php php-mysql php-fpm
- sudo vi /etc/php.ini – in order to secure it do cgi.fix_pathinfo=0
- sudo vi /etc/php-fpm.d/www.conf set line to listen = /var/run/php-fpm/php-fpm.sock
- sudo systemctl start php-fpm
- sudo systemctl enable php-fpm.service to start from boot
PostgreSQL
- exclude the CentOS version of postgres in order to get the most recent version from the project’s website
- sudo vim /etc/yum.repos.d/CentOS-Base.repo
At the bottom of the [base] and [updates] sections, add a line that excludes the postgres packages: exclude=postgresql* - Find the link for your version of the OS here
- curl -O http://yum.postgresql.org/9.4/redhat/rhel-7-x86_64/pgdg-centos94-9.4-1.noarch.rpm
- rpm -ivh pgdg*
- yum list postgres*
- install the -server package: sudo postgresql94-server.x86_64
- sudo /usr/pgsql-9.4/bin/postgresql94-setup initdb
- chkconfig postgresql-9.3 on
- service postgresql-9.3 start
- postgres creates a user and a database called postgres
- sudo su – postgres
- psql
- \?: Get a full list of psql commands, including those not listed here
- \h: Get help on SQL commands. You can follow this with a specific command to get help with the syntax
- \q: Quit the psql program and exit to the Linux prompt
- \d: List available tables, views, and sequences in current database
- \du: List available roles
- \dp: List access privileges
- \dt: List tables
- \l: List databases
- \c: Connect to a different database. Follow this by the database name
- \password: Change the password for the username that follows
- \conninfo: Get information about the current database and connection
CREATE TABLE new_table_name ( table_column_title TYPE_OF_DATA column_constraints, next_column_title TYPE_OF_DATA column_constraints, table_constraint table_constraint ) INHERITS existing_table_to_inherit_from;
MongoDB
- Instructions from here
- sudo vim /etc/yum.repos.d/mongodb.repo:
[mongodb] name=MongoDB Repository baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/ gpgcheck=0 enabled=1
- sudo yum install -y mongodb-org
- to prevent unintended upgrades, add to /etc/yum.conf file:
exclude=mongodb-org,mongodb-org-server,mongodb-org-shell,mongodb-org-mongos,mongodb-org-tools - sudo service mongod start
- sudo chkconfig mongod on