Managing your own web server from scratch may seem daunting, but by breaking it down into steps, you’ll learn how to control every part of your server, install essential software, and secure your site. This guide assumes you have been provided with an IP address and Ubuntu is pre-installed. We’ll guide you through connecting to your server, installing the necessary software, and even setting up FTP for file transfers.
Step 1: Connecting to Your Ubuntu Server
The first step is connecting to your server. You’ll use SSH (Secure Shell) to log in and interact with your server.
SSH provides a secure way to remotely log into another computer over a network. It encrypts the connection, ensuring that no one can intercept your commands or data. As a server administrator, you’ll be using this often to manage your server.
How to Connect:
Open Windows Terminal or Command Prompt (either will work on Windows). Run the following command:
ssh root@<your-ip-address>
Example:
ssh [email protected]
You’ll be prompted to enter the password that was sent to you when the server was provisioned. Once entered, you’ll have full control over the server.
Once connected, you’re ready to start configuring the server. This is where we’ll install software to serve websites.
Step 2: Update the Server
Whenever you log into a server for the first time, it’s important to update the system.
Updating the server ensures that all installed software is up-to-date and secure. It’s especially important on web servers, which are exposed to the internet and therefore more vulnerable to attacks.
How to Update: Run:
apt update && apt upgrade -y
apt update
: Downloads the latest package lists from the software repositories.apt upgrade -y
: Installs the newest versions of all the software installed on the system.
Once the server is up-to-date, you’re ready to install the web server software—NGINX.
Step 3: Install NGINX
NGINX is a popular, high-performance web server used to serve websites and handle HTTP requests. It’s widely used due to its efficiency in handling large amounts of traffic.
How to Install NGINX:Run the following command to install NGINX:
apt install nginx -y
Once installed, start the service and ensure it runs on boot:
systemctl start nginx
systemctl enable nginx
This starts NGINX and ensures it will automatically start when the server boots.
How to Test NGINX:Open a browser and visit your server’s IP address:
http://<your-ip-address>
You should see the NGINX welcome page.
Now that NGINX is running, let’s move on to installing PHP, which will allow your server to process dynamic content.
Step 4: Install PHP 8+
PHP is a server-side scripting language widely used to build dynamic websites. Installing PHP will allow your server to handle dynamic content, such as forms, logins, and other functionalities common in modern websites.
How to Install PHP 8+
First, you need to add the repository for PHP 8, as it’s not available by default in some versions of Ubuntu.
add-apt-repository ppa:ondrej/php
apt update
Install PHP 8.1 and the necessary extensions:
apt install php8.1 php8.1-fpm php8.1-mysql -y
Enable PHP-FPM
PHP-FPM (FastCGI Process Manager) improves PHP performance when used with NGINX. Enable and start PHP-FPM:
systemctl start php8.1-fpm
systemctl enable php8.1-fpm
After installing PHP, we’ll need a database to store data, so let’s install MariaDB.
Step 5: Install MariaDB
MariaDB is a powerful database management system that will store your website’s data, such as user information, product catalogs, and other dynamic content. It’s a fork of MySQL and is highly compatible with it.
How to Install MariaDB
Run the following command to install the database server:
apt install mariadb-server mariadb-client -y
Start the service and enable it to start on boot:
systemctl start mariadb systemctl enable mariadb
Secure MariaDB
MariaDB comes with some default settings that aren’t secure, so run the following command to remove insecure defaults:
mysql_secure_installation
This will guide you through setting a root password, disabling remote root logins, and removing test databases.
With the database installed, it’s time to configure NGINX to process PHP files, allowing your server to handle dynamic pages.
Step 6: Configure NGINX to Use PHP
NGINX serves static files like HTML, but with PHP installed, you need to configure it to handle dynamic requests (like forms or databases). This step configures NGINX to use PHP-FPM for processing PHP files.
How to Configure
Create a configuration file for your domain (yourdomain.com
):
nano /etc/nginx/sites-available/yourdomain.com
Add this configuration (replace yourdomain.com
with your domain):
server {
listen 80;
server_name yourdomain.com www.yourdomain.com;
root /var/www/yourdomain.com;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
Activate the Configuration
Enable the site by creating a symbolic link:
ln -s /etc/nginx/sites-available/yourdomain.com /etc/nginx/sites-enabled/
Test your configuration:
nginx -t
Reload NGINX:
systemctl reload nginx
You now have a working server that can process PHP. Next, let’s create a simple PHP page to test this setup.
Step 7: Create a “Hello World” PHP Page
This step will confirm that your NGINX and PHP configuration is working correctly by creating a simple PHP file to display a message.
How to Create a PHP File
First, create the root directory for your website:
mkdir -p /var/www/yourdomain.com
Set the correct permissions:
chown -R www-data:www-data /var/www/yourdomain.com
Create a PHP file to test:
nano /var/www/yourdomain.com/index.php
Add this code to display “Hello World!”:
<?php
echo "Hello World!";
?>
Visit Your Website
Go to http://yourdomain.com
in a web browser. If everything is working, you should see Hello World! displayed.
Now that your server is serving content, let’s make sure it’s secure by installing SSL with Let’s Encrypt.
Step 8: Install Let’s Encrypt SSL Certificate
SSL (Secure Sockets Layer) encrypts the data transmitted between your server and visitors, ensuring privacy and security. Let’s Encrypt provides free SSL certificates that are easy to install and manage.
How to Install Let’s Encrypt
Install Certbot and the NGINX plugin:
apt install certbot python3-certbot-nginx -y
Obtain an SSL Certificate:
Run this command to obtain a certificate (replace yourdomain.com
with your actual domain):
certbot --nginx -d yourdomain.com -d www.yourdomain.com
Certbot Configuration:
Certbot will ask you if you want to redirect HTTP traffic to HTTPS. Choose Yes to ensure all visitors use a secure connection.
Verify SSL Installation:
Open your website with HTTPS:
https://yourdomain.com
You should now see your website served securely.
After securing your site, the next step is deploying your website files, which requires setting up FTP for easy file transfers.
Step 9: Set Up FTP to Transfer Files to the Server
FTP (File Transfer Protocol) allows you to upload files from your local machine to your web server, making it easier to manage website content. We’ll use SFTP (Secure FTP) for this, which encrypts your file transfers.
How to Use SFTP
If you’re on Windows, you can use a program like FileZilla to connect to your server. Here’s how:
- Open FileZilla and click File > Site Manager.
- Create a new site:
- Host: Enter your server’s IP address.
- Protocol: Select SFTP.
- Login Type: Normal.
- User: Enter
root
(or another user if you’ve created one).
- User: Enter
- Password: Enter your root password.
/var/www/yourdomain.com
.
After uploading your website files, you can manage them through SSH or FileZilla. You’ve now completed the basic setup of your server and are ready to deploy and manage your website live.
Conclusion
You have successfully set up an unmanaged Ubuntu web server from scratch. You’ve learned how to:
- Connect to the server using SSH.
- Install and configure NGINX, PHP 8, and MariaDB.
- Serve dynamic PHP pages.
- Secure your website with SSL using Let’s Encrypt.
- Transfer files using SFTP.
With this foundation, you can now deploy websites, build applications, and manage your server independently. The next steps would be:
- Upload your full website using SFTP.
- Set up backups to protect your data.
- Monitor the server’s performance and security with tools like UFW for firewall management and fail2ban for intrusion prevention.
Isn’t it that easy?! Happy server managing!
Modmenu
Mod menu
Fffffff
Mod menu
HAHAHAH
Yeah
Where is the link?
hjgg
gggg
So good☺️
salamat
Thankyou
link
wkwwuehejeiie
Jkk
Bhhh
Get Password
Heeheheh
Haha
Asan
L love you.
I like
nice
Nice
Mk
Tk
Good
Hi
Baby