For configure a web server on a system Linux, it is essential to follow several key steps. First, start by preparing your system making sure it is up to date. Then proceed tofacility of Apache, a very popular open source web server, which will allow you to host your web applications.
Once Apache is installed, configure your website by creating the root of your file tree and placing a file there .html. Then activate the site with the appropriate commands to make the content accessible. To enrich your server, consider installing PHP and configure it to interact with your server.
Finally, don’t forget to secure your installation by configuring a firewall and by limiting access rights to files and databases, thus ensuring better protection of your server. By following these steps, you will be able to create a functional and secure web server on your Linux distribution.
Setting up a web server on Linux can seem intimidating at first, but with the right steps, it becomes a simple and structured process. This article will detail the essential steps to install and configure the Apache web server on a Linux distribution, such as Ubuntu. We’ll also discuss the need to install additional components such as PHP and MySQL, and provide tips for securing your server.
Prerequisites for installing Apache
Before starting the installation ofApache, it is crucial to prepare your system. Make sure you have access to a Linux server with administrator rights. For installation on Ubuntu, start by updating your system using the following command:
sudo apt update && sudo apt upgrade
Then check that a firewall is configured on your system to secure your installation. You can use UFW (Uncomplicated Firewall) to manage your firewall rules. Enable UFW with:
sudo ufw enable
Installing the Apache web server
To install Apache on your Linux system, run the following command:
sudo apt install apache2
Once the installation is complete, check if Apache is working correctly by going to the address http://localhost via your browser. You should see the Apache default page, which indicates that the server is up and running.
Setting up your first website under Apache
To set up your first site, you need to create a root for your web tree. By default, this root is usually found in /var/www/html. You can drop a test HTML file there named index.html by executing:
sudo nano /var/www/html/index.html
Add simple content like:
Welcome to my Apache server
My first website on Apache
After saving your file, make sure the permissions are set correctly to allow Apache to read this file:
sudo chown -R www-data:www-data /var/www/html
Configure PHP for your Apache server
If you plan to use PHP for your site development, first install the PHP package with the command:
sudo apt install php libapache2-mod-php
You can check your PHP installation by creating a file info.php in the file /var/www/html :
sudo nano /var/www/html/info.php
Add the following code:
Then access http://localhost/info.php to see the PHP configuration and make sure everything is working correctly.
Securing your web server
One of the first steps to ensuring the security of your server is to configure the firewall correctly. Make sure only the necessary ports are open, typically port 80 for HTTP and port 443 for HTTPS. You can open these ports using UFW:
sudo ufw allow 'Apache Full'
Also consider using SSL to encrypt communications between the server and users. For this you can install Certbot to obtain a free SSL certificate via Let’s Encrypt:
sudo apt install certbot python3-certbot-apache
Then, run the following command to automatically configure SSL:
sudo certbot --apache
User management and access rights
Proper configuration of users and access rights is essential to maintaining the security of your server. Avoid using the root account for common operations. Create a new user with limited privileges for managing your web server and configure the necessary groups and permissions to restrict access to sensitive files.
Additional tools and resources
To deepen your web server administration skills, check out additional resources. For example, discover the benefits of using Linux for developers or the containerization with Docker, and explore lesser known aspects of Linux to optimize your configurations.
Finally, it is useful to find out about the differences between Linux and Windows to put your development and server administration into perspective.