Apache and Local Host Server CMD Step
Apache and Local Host Server CMD Step
Page |1
Here's a step-by-step manual to launch a web server on Ubuntu 20.04 using
Apache, one of the most widely used web servers.
### Prerequisites
- An Ubuntu 20.04 server (preferably with a non-root user with sudo
privileges).
- A basic understanding of terminal commands.
LINUX CMD
1. sudo apt update
2. sudo apt upgrade -y
LINUX CMD
3. sudo apt install apache2 -y
Page |2
### Step 3: Adjust the Firewall
If you have a firewall enabled, you need to allow traffic on port 80 (HTTP)
and port 443 (HTTPS).
LINUX CMD
4. sudo ufw allow 'Apache Full'
LINUX CMD
5. sudo ufw status
LINUX CMD
6. sudo systemctl status apache2
If Apache is running, you'll see a status message indicating that the service is
active.
Page |3
### Step 5: Test the Web Server
You can test if Apache is serving web pages by visiting your server's public
IP address in a web browser:
LINUX CMD
8. sudo mkdir -p /var/www/your_domain
LINUX CMD
Page |4
9. sudo chown -R $USER:$USER /var/www/your_domain
ex your_domain ismt.com
LINUX CMD
10. nano /var/www/your_domain/index.html
nano is a editor
ctrl + o to save content press enter
ctrl+ x to close nano text editor
html
<html>
<head>
<title>Welcome to Your_domain!</title>
</head>
<body>
<h1>Success! Your domain is working.</h1>
</body>
</html>
Page |5
6.4. Create a new virtual host configuration file.
LINUX CMD
11. sudo nano /etc/apache2/sites-available/your_domain.conf
conf
<VirtualHost *:80>
ServerAdmin webmaster@your_domain
ServerName your_domain
ServerAlias www.your_domain
DocumentRoot /var/www/your_domain
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
# your_domain is your web site like ismt.com
# here 80 is port number for http content
LINUX CMD
12. sudo a2ensite your_domain.conf
Page |6
6.6. Disable the default site, if desired.
LINUX CMD
13. sudo a2dissite 000-default.conf
# This will allow to show newly configure website instead of apache
into page
LINUX CMD
14. sudo systemctl restart apache2
LINUX CMD
15. sudo chown -R www-data:www-data /var/www/your_domain
16. sudo chmod -R 755 /var/www/your_domain
Page |7
### Step 8: Managing Apache (Optional)
Here are a few commands to manage the Apache service:
- **Stop Apache:**
LINUX CMD
1. sudo systemctl stop apache2
- **Start Apache:**
LINUX CMD
2. sudo systemctl start apache2
- **Restart Apache:**
LINUX CMD
3. sudo systemctl restart apache2
Page |8
LINUX CMD
5. sudo systemctl disable apache2
- **Access log:**
LINUX CMD
7. sudo tail /var/log/apache2/access.log
- **Error log:**
LINUX CMD
8. sudo tail /var/log/apache2/error.log
### Conclusion
Page |9
Your web server should now be up and running on Ubuntu 20.04. we can
start deploying our website files to the `/var/www/your_domain` directory
and manage your server using the commands provided
To restart a network adapter on Ubuntu 20.04, you can use the following
commands, depending on whether you want to restart a specific network
interface or all network interfaces.
LINUX CMD
1. sudo ip link set INTERFACE_NAME down
LINUX CMD
2. sudo ip link set INTERFACE_NAME up
P a g e | 10
For example, if your network interface is `enp3s0`:
LINUX CMD
3. sudo ip link set enp3s0 down
4. sudo ip link set enp3s0 up
To restart all network interfaces, you can use the `netplan` utility or the
`systemctl` command:
LINUX CMD
5. sudo netplan apply
LINUX CMD
P a g e | 11
6. sudo systemctl restart NetworkManager
LINUX CMD
7. sudo systemctl restart networking
This command restarts the networking service, which will bring down and up
all network interfaces as part of the restart process.
After restarting the network adapter, you can check the status of your
network interfaces:
LINUX CMD
8. ip a
P a g e | 12
This command will display the status of all network interfaces, showing
whether they are up and have an IP address assigned.
P a g e | 13