← Back to Apache Course | Chapter 1: Introduction & Setup | Lesson 3 of 4

Ubuntu/Linux पर Apache

Ubuntu और दूसरे Debian-based distributions Apache को apache2 package नाम के तहत install करते हैं, इसे systemctl से manage करते हैं, और इसका configuration /etc/apache2/ के नीचे रखते हैं। यह lesson Ubuntu पर Apache install, start, और verify करने के exact commands से गुज़रता है।

apt से Install करना

Ubuntu/Debian पर, package index update करें और apache2 package install करें:

`` sudo apt update sudo apt install apache2 ``

यह server के साथ एक default configuration और /var/www/html/ के नीचे एक sample "It works!" page install कर देता है।

systemctl से Service Manage करना

Ubuntu services manage करने के लिए systemd इस्तेमाल करता है। install करने के बाद, Apache आमतौर पर अपने आप start हो जाता है, लेकिन आप इसे explicitly control करते हैं:

`` sudo systemctl start apache2 sudo systemctl stop apache2 sudo systemctl restart apache2 sudo systemctl reload apache2 sudo systemctl enable apache2 ``

restart पूरी process को stop और start करता है (connections थोड़ी देर के लिए drop होते हैं); reload active connections को drop किए बिना configuration दोबारा पढ़ लेता है, जो किसी छोटे config change के बाद ज़्यादा safe है। enable Apache को हर boot पर automatically start करवाता है।

Note: जब भी कुछ गलत लगे तो sudo systemctl status apache2 इस्तेमाल करें -- यह दिखाता है कि service चल रही है या नहीं, और अक्सर एक खराब config की exact error line print कर देता है।

Ubuntu का Config Layout

Ubuntu Apache का configuration /etc/apache2/ के नीचे कई directories में बांटता है: apache2.conf main file है, sites-available/ में आपके बनाए virtual host definitions होते हैं, sites-enabled/ में उनके symlinks होते हैं जो असल में active हैं, और mods-available//mods-enabled/ modules के लिए वही काम करते हैं। यह एक Debian-specific convention है -- RHEL-based systems इसकी जगह एक single flatter conf.d/ directory इस्तेमाल करते हैं।

Sites और Modules Enable/Disable करना

symlinks को manually edit करने की बजाय, Ubuntu helper commands देता है: a2ensite/a2dissite sites-available/ से एक virtual host enable या disable करते हैं, और a2enmod/a2dismod modules के लिए वही करते हैं। उदाहरण के लिए, sudo a2enmod rewrite mod_rewrite enable करता है, और फिर आप इसे लागू होने के लिए Apache reload करते हैं।

Warning: a2enmod/a2ensite सिर्फ symlink बनाते हैं -- Apache तब तक change pick up नहीं करता जब तक आप बाद में sudo systemctl reload apache2 न चलाएं।

Install Verify करना

एक बार service चलने लगे, तो दो तरीकों से confirm करें: server पर ही curl -I localhost चलाएं और HTTP/1.1 200 OK देखें, फिर किसी दूसरी machine से browser में server का IP address visit करें और confirm करें कि default Apache Ubuntu welcome page दिख रहा है।

उदाहरण: Installing and enabling Apache on Ubuntu

apacheconf
# Install Apache
sudo apt update
sudo apt install apache2

# Start it now, and on every future boot
sudo systemctl start apache2
sudo systemctl enable apache2

# Check it's running
sudo systemctl status apache2
curl -I localhost
{# Flagged by hand after confirming a runner can't handle this example (a shell command / go.mod file stored as a TopicExample, a language feature the configured runner version doesn't support, or output that blows a runner's sandbox limit) -- see TopicExample.norun. Never render the run button for these, regardless of language, since it would just fail at execute_code (or worse, hang the Judge0 queue on a submission that can never finish cleanly). #}

⚠️ This example can't run in the browser editor. Try it in your own local environment instead.

{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. sites-enabled/ के अंदर सीधे किसी file को edit करना -- यह sites-available/ का एक symlink है, इसलिए बेहतर है वहाँ असली file पर changes करें, और rename करने के बाद a2ensite से दोबारा enable करें।
  2. a2enmod/a2ensite के बाद sudo systemctl reload apache2 भूल जाना, फिर सोचना कि module या site active क्यों नहीं लग रहा।
  3. Ubuntu पर apt install httpd (RHEL का package नाम) इस्तेमाल करना, जो exist ही नहीं करता -- Ubuntu का package apache2 है।
🔒

Chapter Quiz — Complete all 4 topics to unlock

0/4 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.