Birmingham mumbai



Download 15,21 Mb.
Pdf ko'rish
bet206/482
Sana13.01.2022
Hajmi15,21 Mb.
#355107
1   ...   202   203   204   205   206   207   208   209   ...   482
Bog'liq
Mastering Ubuntu Server Gain expertise in the art of deploying, configuring, managing, and troubleshooting Ubuntu Server by Jay LaCroix (z-lib.org)

[
 152 
]
What we've done here is theoretically scripted the setup of a web server. We could 
extend this script further by having it copy site content to 
/var/www/html
, enable a 
configuration file, and so on. But from the preceding script, you can probably see 
how scripting can be useful in condensing the amount of work you do. This script 
could be an advanced web server install script that you could simply copy to a new 
server and then run.
Notice that the example uses the 
-y
 option with 
apt
. If you weren't already aware, 
that automatically answers 
yes
 to prompts that may come up as part of the process. 
Scripts are typically not interactive, meaning there may not be an administrator 
sitting in front of it to answer prompts when they appear. Also, using the 
a2enmod
 
command to enable 
php7.4
 was not really necessary, as it would've been enabled 
automatically as part of installing the 
libapache2-mod-php7.4
 package. But I think 
you get the idea; we want to be explicit in scripts and type instructions for the exact 
state we want things to be in.
Now, let's get a bit more advanced with scripting. The previous script only installed 
some packages, something we probably could've done just as easily by copying and 
pasting the commands into the shell. Let's take this script a bit further. Let's write a 
conditional statement. Here's a modified version of the previous script:
#!/bin/bash
# Install Apache if it's not already present
if [ ! -f /usr/sbin/apache2 ]; then
    sudo apt install -y apache2
    sudo apt install -y libapache2-mod-php7.4
    sudo a2enmod php7.4
    sudo systemctl restart apache2
fi
Now it's getting a bit more interesting. The first line after the hash bang is a 
comment, letting us know what the script does:
# Install Apache if it's not already present 
Comments are ignored by the interpreter, but are useful in letting us know what a 
block of code is doing.
Next, we start an 
if
 statement:
if [ ! -f /usr/sbin/apache2 ]; then


Chapter 6

Download 15,21 Mb.

Do'stlaringiz bilan baham:
1   ...   202   203   204   205   206   207   208   209   ...   482




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish