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
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
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
index.php
in your website directory:yourdomain.com
with your actual domain):8. Configure Domain Name (DNS)
To access your server by a domain name:
-
If you don’t have a domain: You’ll need to purchase one from a registrar (like GoDaddy, Namecheap, etc.).
-
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
-
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). -
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
-
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
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!