Setting Up Your Server for Web Hosting
This overview covers the essential components you need to host websites on your dedicated server.
1. Choose a Web Server
Install either Nginx (recommended for performance) or Apache (recommended for .htaccess compatibility):
apt install nginx -y # or: apt install apache2 -y
2. Install PHP
apt install php php-fpm php-mysql php-curl php-gd php-mbstring php-xml -y
3. Install a Database
apt install mariadb-server -y
mysql_secure_installation
4. Point Your Domain to the Server
At your domain registrar or DNS provider, create an A record:
- Name:
@(root domain) andwww - Value: your server's IP address
DNS changes propagate within 1–24 hours.
5. Create a Virtual Host / Server Block
Create a config file for your domain (example for Nginx):
server {
listen 80;
server_name yourdomain.com www.yourdomain.com;
root /var/www/yourdomain.com;
index index.php index.html;
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/run/php/php8.1-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
6. Obtain an SSL Certificate
apt install certbot python3-certbot-nginx -y
certbot --nginx -d yourdomain.com -d www.yourdomain.com
7. Upload Your Site Files
Place your website files in /var/www/yourdomain.com/ using SFTP or SCP. Set correct ownership:
chown -R www-data:www-data /var/www/yourdomain.com