Web development basic and advance tutorial, php basic tutorial, laravel basic tutorial, React Native tutorial

Saturday, May 17, 2025

Digital Occan install VPS ubuntu server with Apache, PHP, MySQL, MongoDB, Node.js, and a domain name

0 comments

 To set up an Ubuntu server with Apache, PHP, MySQL, MongoDB, Node.js, and a domain name (to host your website using your IP address initially), follow these steps. I’ll walk you through installing and configuring each component.

1. Update your server

Make sure your system is up to date:

sudo apt update && sudo apt upgrade -y

2. Install Apache
Apache is one of the most popular web servers.
sudo apt install apache2 -y

3. To ensure Apache starts automatically on boot:
sudo systemctl enable apache2

To check if Apache is working, open your browser and go to your server's IP address (http://your-ip-address), you should see the Apache2 Ubuntu Default Page.

3. Install PHP

To install PHP along with some common modules required for web applications:

sudo apt install php libapache2-mod-php php-mysql php-xml php-cli php-curl php-mbstring -y

To verify the PHP installation:

php -v

4. Install MySQL

MySQL is the database management system.

sudo apt install mysql-server -y

Secure MySQL installation (sets root password and secures it):
sudo mysql_secure_installation

5. Install MongoDB

MongoDB is a NoSQL database. You’ll use it alongside MySQL or for specific use cases.

sudo apt install mongodb -y

sudo systemctl start mongodb
sudo systemctl enable mongodb


Node.js allows you to run JavaScript code outside of the browser. It's useful for backend development or building front-end assets.

Add the NodeSource repository:

curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -

sudo apt install -y nodejs

Verify the installation:

node -v
npm -v

sudo mkdir -p /var/www/yourdomain.com/public_html

Set proper permissions:

sudo chown -R $USER:$USER /var/www/yourdomain.com/public_html

Create a sample index.php in your website directory:

echo "<?php phpinfo(); ?>" | sudo tee /var/www/yourdomain.com/public_html/index.php

Now create a Virtual Host configuration file:

sudo nano /etc/apache2/sites-available/yourdomain.com.conf

Add this to the file (replace yourdomain.com with your actual domain):

<VirtualHost *:80>
    ServerAdmin webmaster@yourdomain.com
    ServerName yourdomain.com
    DocumentRoot /var/www/yourdomain.com/public_html
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Enable the new site and rewrite module:

sudo a2ensite yourdomain.com.conf
sudo a2enmod rewrite

Then reload Apache to apply the changes:
sudo systemctl reload apache2

8. Configure Domain Name (DNS)

To access your server by a domain name:

  1. If you don’t have a domain: You’ll need to purchase one from a registrar (like GoDaddy, Namecheap, etc.).

  2. Point your domain to your server's IP address:

    • Go to your domain registrar's DNS management panel.

    • Add an A record that points your domain to your server’s IP address.

    • If you don't have a domain yet, you can access the site using the IP address directly.

9. Configure Firewall (UFW)

Make sure the server firewall allows web traffic (HTTP/HTTPS) and MySQL.


sudo ufw allow OpenSSH

sudo ufw allow 'Apache Full'

sudo ufw enable

10. Test Your Setup

  1. If you’ve set up everything correctly and DNS has propagated (which might take some time), you should be able to visit http://yourdomain.com in your browser and see the PHP info page (which proves PHP is running).

  2. Alternatively, if you're using the IP address directly, you should visit http://your-server-ip to verify Apache, PHP, and MySQL are running.

Optional: Additional Steps for Full Website Setup

  1. Install SSL (HTTPS) with Let's Encrypt:

    • Use certbot to secure your site with HTTPS. (Essential for security!)


sudo apt install certbot python3-certbot-apache -y

sudo certbot --apache -d yourdomain.com

  1. Install PHP frameworks or Node.js frameworks:

    • For PHP, you can install Laravel or Symfony.

    • For Node.js, you can use Express or NestJS.

Let me know if you need more detailed guidance on any of these steps!




No comments:

Post a Comment