How to Set Up a LAMP/LEMP Stack on Your Dedicated Server
Setting up a LAMP (Linux, Apache, MySQL, PHP) or LEMP (Linux, Nginx, MySQL, PHP) stack on your dedicated server allows you to host websites, applications, and databases efficiently. Follow this step-by-step guide to install and configure your preferred stack on your QuickServers dedicated server.
Step 1: Update Your Server
-
Before installing any software, update your server’s package list.
-
Run the following command:
sudo apt update && sudo apt upgrade -y
-
This ensures all installed packages are up to date.
Step 2: Install Apache or Nginx
-
To install Apache (for LAMP), run:
sudo apt install apache2 -y
-
To install Nginx (for LEMP), run:
sudo apt install nginx -y
-
Once installed, start and enable the service:
sudo systemctl start apache2 sudo systemctl enable apache2
or
sudo systemctl start nginx sudo systemctl enable nginx
Step 3: Install MySQL
-
Install MySQL with the following command:
sudo apt install mysql-server -y
-
Secure the MySQL installation:
sudo mysql_secure_installation
-
Follow the prompts to set a root password and remove insecure settings.
Step 4: Install PHP
-
Install PHP along with commonly used extensions:
sudo apt install php php-mysql php-cli php-common php-mbstring php-xml php-curl -y
-
Restart your web server to apply changes:
sudo systemctl restart apache2
or
sudo systemctl restart nginx
Step 5: Verify the Installation
-
Create a PHP test file:
sudo nano /var/www/html/info.php
-
Add the following content:
<?php phpinfo(); ?>
-
Save the file and access
http://your-server-ip/info.php
in a web browser. If the PHP information page loads, the installation is successful.
Step 6: Secure Your Server
-
Enable UFW and allow only necessary ports:
sudo ufw allow OpenSSH sudo ufw allow 80/tcp sudo ufw allow 443/tcp sudo ufw enable
-
This helps protect your server from unauthorized access.
Your LAMP or LEMP stack is now set up on your QuickServers dedicated server. You can start deploying websites and applications efficiently.