Ubuntu/Linux पर Apache
apache2 package नाम के तहत install करते हैं, इसे systemctl से manage करते हैं, और इसका configuration /etc/apache2/ के नीचे रखते हैं। यह lesson Ubuntu पर Apache install, start, और verify करने के exact commands से गुज़रता है।In this page:
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 करवाता है।
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 करते हैं।
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
# 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). #}
sites-enabled/के अंदर सीधे किसी file को edit करना -- यहsites-available/का एक symlink है, इसलिए बेहतर है वहाँ असली file पर changes करें, और rename करने के बादa2ensiteसे दोबारा enable करें।a2enmod/a2ensiteके बादsudo systemctl reload apache2भूल जाना, फिर सोचना कि module या site active क्यों नहीं लग रहा।- Ubuntu पर
apt install httpd(RHEL का package नाम) इस्तेमाल करना, जो exist ही नहीं करता -- Ubuntu का packageapache2है।
Chapter Quiz — Complete all 4 topics to unlock
0/4 topics done
Complete these topics first: