0% found this document useful (0 votes)
32 views13 pages

Apache and Local Host Server CMD Step

Uploaded by

guptaniraj2051
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views13 pages

Apache and Local Host Server CMD Step

Uploaded by

guptaniraj2051
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

Contents

### Step 1: Update System Packages..........................................................................................................2


### Step 2: Install Apache...........................................................................................................................2
### Step 3: Adjust the Firewall...................................................................................................................3
### Step 4: Check Apache Status................................................................................................................3
### Step 5: Test the Web Server.................................................................................................................4
### Step 6: Set Up a Virtual Host (Optional)..............................................................................................4
### Step 7: Set Permissions and Ownership (Optional)..............................................................................7
### Step 8: Managing Apache (Optional)...................................................................................................9
### Step 9: Access Logs (Optional)..........................................................................................................10
### 1. **Restart a Specific Network Interface**......................................................................................11
### 2. **Restart All Network Interfaces**...............................................................................................12
### 3. **Restart the Networking Service**..............................................................................................13
### 4. **Verify the Network Status**......................................................................................................13

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.

### Step 1: Update System Packages


First, ensure that your system is up-to-date.

LINUX CMD
1. sudo apt update
2. sudo apt upgrade -y

### Step 2: Install Apache


Apache is the most popular web server. Install it using the `apt` package
manager.

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'

To verify that the rules were added, run:

LINUX CMD
5. sudo ufw status

### Step 4: Check Apache Status


Check if Apache is running by using the following command:

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:

7. http://your_server_ip ex: 192.168.0.5 # yours ip address of pc


# to see ip linux ip cmd -ifconfig
Windows os -ipconfig

You should see the default Apache welcome page.

### Step 6: Set Up a Virtual Host (Optional)


If you want to host multiple websites on the same server, you'll need to
configure virtual hosts. Here's how to set up a basic virtual host.

6.1. Create a directory for your website.

LINUX CMD
8. sudo mkdir -p /var/www/your_domain

6.2. Assign ownership of the directory with the `$USER` environment


variable.

LINUX CMD

Page |4
9. sudo chown -R $USER:$USER /var/www/your_domain
ex your_domain  ismt.com

6.3. Create a sample index page to test.

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

Add the following content:

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

Paste the following configuration:

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

6.5. Enable the new virtual host file.

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

6.7. Restart Apache to apply the changes.

LINUX CMD
14. sudo systemctl restart apache2

### Step 7: Set Permissions and Ownership (Optional)


Ensure the web server has the proper permissions to serve files.

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

- **Reload Apache without dropping connections:**


LINUX CMD
4. sudo systemctl reload apache2

- **Disable Apache from starting on boot:**

Page |8
LINUX CMD
5. sudo systemctl disable apache2

- **Enable Apache to start on boot:**


LINUX CMD
6. sudo systemctl enable apache2

### Step 9: Access Logs (Optional)


Apache keeps access and error logs that can be very helpful in diagnosing
issues.

- **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.

### 1. **Restart a Specific Network Interface**

If you want to restart a specific network interface (e.g., `eth0`, `enp3s0`,


`wlp2s0`, etc.), you can do so with the following commands:

1. **Bring the Interface Down:**

Replace `INTERFACE_NAME` with your actual network interface name.

LINUX CMD
1. sudo ip link set INTERFACE_NAME down

2. **Bring the Interface Up:**

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

### 2. **Restart All Network Interfaces**

To restart all network interfaces, you can use the `netplan` utility or the
`systemctl` command:

#### **Using netplan:**

LINUX CMD
5. sudo netplan apply

This command applies the current network configuration, effectively


restarting all network interfaces.

#### **Using systemctl:**

LINUX CMD

P a g e | 11
6. sudo systemctl restart NetworkManager

This command restarts the NetworkManager service, which manages network


interfaces on Ubuntu. This will restart all network interfaces managed by
NetworkManager.

### 3. **Restart the Networking Service**

Alternatively, you can restart the entire networking service:

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.

### 4. **Verify the Network Status**

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

You might also like