Node.js server with Apollo GraphQL and MySQL.
- Sign in to your DigitalOcean account.
- Select Create -> Droplet for creating a new droplet.
- From the Distributions list please select CentOS.
- Choose the plan and the datacenter region that meet your requirements.
- Also please alter the remaining options regarding your needs.
- Click on Create Droplet.
- Select Networking -> Firewalls -> Create Firewall.
- Set a name for your new Firewall.
- Add a Custom inbound rule with the TCP protocol using the port number 3001.
- Add a MySQL inbound rule with the TCP protocol using the port number 3306.
- Scroll down to the bottom of the page and apply the Firewall to the recently created droplet.
- Click on Create Firewall.
- Sign in to your droplet via terminal with root user.
- Install Node.js using
yum install -y nodejs
- Install MySQL using
yum install -y mysql-server
- Install Git using
yum install -y git
- Clone the following GitHub repo using
git clone https://github.com/relatedcode/apollo-mysql-server
- Enter the cloned repo folder with
cd apollo-mysql-server
- Start the MySQL Service using
service mysqld start
- Configure MySQL using
mysql_secure_installation
- Answer the following questions as described below.
- Would you like to setup VALIDATE PASSWORD component? -
No
- Please set the password for root here. New password: -
Related123
- Remove anonymous users? -
Yes
- Disallow root login remotely? -
No
- Remove test database and access to it? -
Yes
- Reload privilege tables now? -
Yes
- To customize your MySQL database and MySQL user account details make changes in the following files:
database/CreateDatabase.sql
database/CreateUser.sql
.env
- Enter MySQL console using
mysql -u root -p
- Enter the MySQL password provided earlier
Related123
- Create the MySQL database using
SOURCE database/CreateDatabase.sql;
- Create the MySQL user account using
SOURCE database/CreateUser.sql;
- Exit MySQL console using
EXIT;
- Install the predefined packages using
npm install
- Install PM2 using
npm install pm2 -g
- Start the Apollo server with
pm2 start index.js
- You can exit from the droplet using
exit
You can check the Apollo GraphQL admin page from your browser entering the server IP address with the port number (like this: http://your-server-ip-address:3001).
To connect your Database remotely using a Database Manager application, please use the following values:
- Host: your-server-ip-address
- Port: 3306
- User: remote
- Password: Related123
- Database: messenger