Getting Started with Ubuntu Server for Web Development
Summary:
Introduction to Ubuntu server setup and best practices for beginners.
Web development often goes beyond writing code — hosting your applications on a reliable and secure server is just as important. Ubuntu Server, a free and popular Linux-based operating system, provides a solid foundation for hosting web projects. Whether you want to deploy a website, run APIs, or experiment with new frameworks, Ubuntu Server is an excellent starting place for both novices and professionals.
In this article, we'll walk you through the essentials of getting started with Ubuntu Server, including installation, configuration, and best practices tailored for web development.
Why Choose Ubuntu Server?
- Open Source & Free: Ubuntu Server is entirely free and open source, allowing you to customize it without licensing constraints.
- Community Support: With vast documentation and a large user base, getting help is easy.
- Stability and Security: Regular updates and long-term support (LTS) versions keep your server secure over time.
- Compatibility: A wide range of web frameworks, databases, and tools are readily available.
1. Setting Up Ubuntu Server
Choosing Your Environment
There are different ways to run Ubuntu Server:
- Cloud Providers: AWS, Azure, Google Cloud, and others offer Ubuntu Server images.
- Virtual Machines: Use software like VirtualBox or VMware on your local machine.
- Physical Hardware: Install directly on a dedicated server or an old PC.
Downloading the ISO
Visit the official Ubuntu Server downloads page to get the latest LTS version.
Basic Installation Steps
-
Create Bootable Media:
Use tools like Rufus (Windows) or Balena Etcher (Mac/Linux) to write the ISO to a USB stick. -
Boot and Install:
Boot from your media and follow the text-based installer. The steps are straightforward:- Language selection
- Network configuration
- Disk partitioning (the installer can auto-partition for you)
- Create a user account and set a password
-
Select SSH Installation:
When prompted, select the option to install OpenSSH Server if you plan to access the server remotely. -
Finish Installation:
Reboot and remove the installation media.
2. First Steps After Installation
Update the System
Keep your new server up-to-date for security and performance:
sudo apt update
sudo apt upgrade -y
Secure SSH Access
Change Default Port (Optional):
Edit /etc/ssh/sshd_config
and change the line:
Port 22
to another number (e.g., 2222), then restart SSH:
sudo systemctl restart ssh
Disable Root Login:
In sshd_config
, set:
PermitRootLogin no
Then restart SSH again.
Use SSH Keys:
Generate a key pair on your local machine:
ssh-keygen
Copy your public key to the server:
ssh-copy-id username@server_ip
3. Installing a Web Server Stack
Most websites and apps need a web server and a database. Here’s how to install the popular LAMP stack (Linux, Apache, MySQL, PHP):
sudo apt install apache2
sudo apt install mysql-server
sudo apt install php libapache2-mod-php php-mysql
Test Apache:
Go to http://your_server_ip
in a browser. You should see the Apache welcome page.
Test PHP:
echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php
Visit http://your_server_ip/info.php
. Delete this file after testing for security.
4. Deploying Your First Website
Uploading Files
- Via SCP:
From your local machine:scp -r /path/to/website username@server_ip:/var/www/html/
- Via Git:
Install git and clone your repository:sudo apt install git git clone https://github.com/your/repo.git /var/www/html/
Setting Permissions
Web server must be able to read your files:
sudo chown -R www-data:www-data /var/www/html/
sudo chmod -R 755 /var/www/html/
5. Essential Best Practices
- Regular Updates:
Automate updates withunattended-upgrades
or remember to update often. - Firewall Configuration:
Useufw
(Uncomplicated Firewall) to restrict unnecessary ports:sudo ufw allow 80/tcp sudo ufw allow 443/tcp sudo ufw allow [your_ssh_port]/tcp sudo ufw enable
- Backups:
Schedule regular backups of your server and databases. - Monitoring:
Use tools likehtop
,vnstat
, or setup simple monitoring like UptimeRobot to check your server's health. - Document Your Setup:
Keep a configuration file and notes for your deployments and changes. - Learn the Basics of the Terminal:
Basic command-line skills will empower you to troubleshoot and manage your server more efficiently.
Conclusion
Setting up Ubuntu Server for web development lays the groundwork for successful, scalable projects. By starting with best practices in configuration and security, even beginners can deploy robust websites and applications. With time, your confidence managing Linux servers will grow — opening the door to even more advanced deployments and optimizations.
Happy hosting!
Further reading: