Ինչպես տեղադրել Lighttpd-ը PHP-ով և անվճար Եկեք գաղտնագրենք SSL-ը Debian 11-ում
Այս ձեռնարկը գոյություն ունի ՕՀ-ի այս տարբերակների համար
- Debian 11 (Bullseye)
- Debian 8 (Jessie)
- Debian 7 (Wheezy)
- Debian 6 (սեղմում)
- Debian 5 (Լեննի)
- Debian 4 (Etch)
Այս էջում
- Նախադրյալներ
- Տեղադրեք Lighttpd
- Տեղադրեք PHP և PHP-FPM
- Կարգավորեք Lighttpd-ը PHP-FPM-ի համար
- Ստեղծեք Lighttpd վիրտուալ հոսթ
- Ապահովեք Lighttpd-ը Let's Encrypt-ով
- Եզրակացություն
Lighttpd-ն պարզ, արագ և ապահով վեբ սերվեր է: Այն չափսերով շատ փոքր է և չի պահանջում մեծ հիշողություն և պրոցեսորի օգտագործում, ինչը այն դարձնում է լավագույն սերվերներից մեկը ցանկացած հավելված հյուրընկալելու համար: Այն նախատեսված է առաքելության համար կարևոր միջավայրերի համար: Այն կարող է կառավարել մինչև 10,000 միացումներ մեկ սերվերի վրա: Այն առաջարկում է բազմաթիվ հնարավորություններ, այդ թվում՝ URL-վերագրում, ելք-սեղմում, իրադարձությունների մեխանիզմ, FastCGI, SCGI, Auth և այլն:
Այս ձեռնարկում մենք ձեզ ցույց կտանք, թե ինչպես տեղադրել Lighttpd-ը PHP-ով և Եկեք գաղտնագրենք SSL-ը Debian 11-ում:
Նախադրյալներ
- Debian 11-ով աշխատող սերվեր:
- Վավեր տիրույթի անուն, որը մատնանշված է սերվերի IP-ով:
- Սերվերի վրա կազմաձևված է արմատային գաղտնաբառը:
Տեղադրեք Lighttpd
Լռելյայնորեն, Lighttpd փաթեթը ներառված է Debian 11 պաշտոնական պահոցում: Դուք կարող եք տեղադրել այն՝ գործարկելով հետևյալ հրամանը.
apt-get install lighttpd -y
Lighttpd-ը տեղադրվելուց հետո գործարկեք Lighttpd ծառայությունը և միացրեք այն սկսելու համակարգի վերագործարկումից.
systemctl start lighttpd
systemctl enable lighttpd
Կարող եք նաև ստուգել Lighttpd-ի կարգավիճակը հետևյալ հրամանով.
systemctl status lighttpd
Դուք կստանաք հետևյալ արդյունքը.
? lighttpd.service - Lighttpd Daemon
Loaded: loaded (/lib/systemd/system/lighttpd.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2022-02-12 07:01:06 UTC; 12s ago
Process: 4663 ExecStartPre=/usr/sbin/lighttpd -tt -f /etc/lighttpd/lighttpd.conf (code=exited, status=0/SUCCESS)
Main PID: 4668 (lighttpd)
Tasks: 1 (limit: 2341)
Memory: 932.0K
CPU: 226ms
CGroup: /system.slice/lighttpd.service
??4668 /usr/sbin/lighttpd -D -f /etc/lighttpd/lighttpd.conf
Feb 12 07:01:06 debian11 systemd[1]: Starting Lighttpd Daemon...
Feb 12 07:01:06 debian11 systemd[1]: Started Lighttpd Daemon.
Այժմ բացեք ձեր վեբ զննարկիչը և մուտք գործեք Lighttpd վեբ էջ՝ օգտագործելով http://your-server-ip URL-ը: Դուք պետք է տեսնեք Lighttpd թեստային էջը հետևյալ էկրանին.
Ավարտելուց հետո կարող եք անցնել հաջորդ քայլին:
Տեղադրեք PHP և PHP-FPM
Հաջորդը, գործարկեք հետևյալ հրամանը՝ ձեր համակարգում PHP և PHP-FPM փաթեթները տեղադրելու համար:
apt-get install php php-cgi php-fpm php-mysql -y
Տեղադրվելուց հետո խմբագրեք php.ini ֆայլը և դրեք cgi.fix_pathinfo 1
nano /etc/php/7.4/fpm/php.ini
Փոխեք հետևյալ տողը.
cgi.fix_pathinfo=1
Պահպանեք և փակեք ֆայլը, երբ ավարտեք:
Որպեսզի Lighttpd-ն աշխատի PHP-FPM-ի հետ, դուք պետք է փոխարինեք լռելյայն PHP-CGI կոնֆիգուրացիան և PHP-FPM վարդակը.
Նախ, խմբագրեք PHP-FPM կազմաձևման ֆայլը.
nano /etc/php/7.4/fpm/pool.d/www.conf
Գտեք հետևյալ տողը.
listen = /run/php/php7.4-fpm.sock
Եվ փոխարինեք այն հետևյալ տողով.
listen = 127.0.0.1:9000
Պահպանեք և փակեք ֆայլը, այնուհետև վերագործարկեք PHP-FPM-ը՝ փոփոխությունները կիրառելու համար.
systemctl restart php7.4-fpm
Կարող եք նաև ստուգել PHP-FPM-ի կարգավիճակը՝ օգտագործելով հետևյալ հրամանը.
systemctl status php7.4-fpm
Դուք կստանաք հետևյալ արդյունքը.
? php7.4-fpm.service - The PHP 7.4 FastCGI Process Manager
Loaded: loaded (/lib/systemd/system/php7.4-fpm.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2022-02-12 07:04:35 UTC; 1min 7s ago
Docs: man:php-fpm7.4(8)
Process: 15141 ExecStartPost=/usr/lib/php/php-fpm-socket-helper install /run/php/php-fpm.sock /etc/php/7.4/fpm/pool.d/www.conf 74 (code=e>
Main PID: 15138 (php-fpm7.4)
Status: "Processes active: 0, idle: 2, Requests: 0, slow: 0, Traffic: 0req/sec"
Tasks: 3 (limit: 2341)
Memory: 8.8M
CPU: 54ms
CGroup: /system.slice/php7.4-fpm.service
??15138 php-fpm: master process (/etc/php/7.4/fpm/php-fpm.conf)
??15139 php-fpm: pool www
??15140 php-fpm: pool www
Feb 12 07:04:35 debian11 systemd[1]: Starting The PHP 7.4 FastCGI Process Manager...
Feb 12 07:04:35 debian11 systemd[1]: Started The PHP 7.4 FastCGI Process Manager.
Ավարտելուց հետո կարող եք անցնել հաջորդ քայլին:
Կարգավորեք Lighttpd-ը PHP-FPM-ի համար
Հաջորդը, դուք պետք է խմբագրեք Lighttpd կազմաձևման ֆայլը և փոխեք այն Fast CGI-ի միջոցով.
nano /etc/lighttpd/conf-available/15-fastcgi-php.conf
Գտեք հետևյալ տողերը.
"bin-path" => "/usr/bin/php-cgi",
"socket" => "/var/run/lighttpd/php.socket",
Եվ դրանք փոխարինեց հետևյալ տողերով.
"host" => "127.0.0.1",
"port" => "9000",
Պահպանեք և փակեք ֆայլը, այնուհետև միացրեք Fast CGI մոդուլները՝ օգտագործելով հետևյալ հրամանները.
lighty-enable-mod fastcgi
lighty-enable-mod fastcgi-php
Վերջապես, վերագործարկեք Lighttpd ծառայությունը՝ փոփոխությունները կիրառելու համար.
systemctl restart lighttpd
Ստեղծեք Lighttpd վիրտուալ հոսթ
Lighttpd-ը նաև թույլ է տալիս հյուրընկալել բազմաթիվ կայքեր՝ օգտագործելով վիրտուալ հոստինգ: Եկեք ստեղծենք նոր վիրտուալ հոսթի կազմաձևման ֆայլ՝ test.example.com անունով կայք տեղադրելու համար:
nano /etc/lighttpd/conf-available/test.conf
Ավելացնել հետևյալ տողերը.
$HTTP["host"] == "test.example.com" {
server.document-root = "/var/www/html/"
server.errorlog = "/var/log/lighttpd/example.com-error.log"
}
Պահպանեք և փակեք ֆայլը, այնուհետև ակտիվացրեք վիրտուալ հոսթը հետևյալ հրամանով.
ln -s /etc/lighttpd/conf-available/test.conf /etc/lighttpd/conf-enabled/
Հաջորդը, ստեղծեք index.php ֆայլ.
nano /var/www/html/index.php
Ավելացնել հետևյալ տողը.
<?php
phpinfo();
?>
Պահպանեք և փակեք ֆայլը, այնուհետև սահմանեք համապատասխան թույլտվություն և սեփականության իրավունք հետևյալ հրամանով.
chown -R www-data:www-data /var/www/html/
chmod -R 755 /var/www/html
Հաջորդը, վերագործարկեք Lighttpd ծառայությունը՝ փոփոխությունները կիրառելու համար.
systemctl restart lighttpd
Այժմ բացեք ձեր վեբ զննարկիչը և հաստատեք ձեր կայքը՝ օգտագործելով http://test.example.com URL-ը: Դուք պետք է տեսնեք PHP թեստային էջը հետևյալ էկրանին.
Ապահովեք Lighttpd-ը Let's Encrypt-ով
Lighttpd-ն թույլ է տալիս նաև պաշտպանել կայքը Let's Encrypt SSL-ով: Դա անելու համար նախ տեղադրեք Certbot հաճախորդը հետևյալ հրամանով.
apt-get install certbot -y
Հաջորդը, գործարկեք հետևյալ հրամանը՝ ձեր կայքի համար Let's Encrypt SSL-ը ներբեռնելու համար.
certbot certonly --webroot -w /var/www/html/ -d test.example.com
Ձեզանից կպահանջվի տրամադրել ձեր էլ. հասցեն և ընդունել լիցենզիայի ժամկետը, ինչպես ցույց է տրված ստորև.
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator webroot, Installer None
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): [email
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
Once the certificates are downloaded successfully, you should see the following output:
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/test.example.com/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/test.example.com/privkey.pem
Your cert will expire on 2022-05-11. To obtain a new or tweaked
version of this certificate in the future, simply run certbot
again. To non-interactively renew *all* of your certificates, run
"certbot renew"
- If you like Certbot, please consider supporting our work by:
Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate
Donating to EFF: https://eff.org/donate-le
Հաջորդը, դուք պետք է միավորեք և՛ վկայականը, և՛ մասնավոր բանալին մեկ ֆայլում: Դուք կարող եք դա անել հետևյալ հրամանով.
cat /etc/letsencrypt/live/test.example.com/cert.pem /etc/letsencrypt/live/test.example.com/privkey.pem > /etc/letsencrypt/live/test.example.com/web.pem
Հաջորդը, դուք պետք է խմբագրեք Lighttpd վիրտուալ հոսթ ֆայլը և սահմանեք Let's Encrypt SSL վկայագրի ուղին:
Դուք կարող եք դա անել հետևյալ հրամանով.
nano /etc/lighttpd/conf-enabled/test.conf
Փոխեք ֆայլը, ինչպես ցույց է տրված ստորև.
$HTTP["host"] == "test.example.com" {
server.document-root = "/var/www/html/"
}
$SERVER["socket"] == ":443" {
ssl.engine = "enable"
ssl.pemfile = "/etc/letsencrypt/live/test.example.com/web.pem"
ssl.ca-file = "/etc/letsencrypt/live/test.example.com/chain.pem"
server.name = "test.example.com"
server.document-root = "/var/www/html/"
server.errorlog = "/var/log/lighttpd/example.com_error.log"
accesslog.filename = "/var/log/lighttpd/example.com_access.log"
}
$HTTP["scheme"] == "http" {
$HTTP["host"] == "test.example.com" {
url.redirect = ("/.*" => "https://test.example.com$0")
}
}
Պահպանեք և փակեք ֆայլը: Այնուհետև վերագործարկեք Lighttpd ծառայությունը՝ կազմաձևման փոփոխությունները կիրառելու համար.
systemctl restart lighttpd
Այժմ դուք կարող եք ապահով մուտք գործել ձեր կայք՝ օգտագործելով https://test.example.com URL-ը:
Եզրակացություն
Շնորհավորում եմ: դուք հաջողությամբ տեղադրել եք Lighttpd-ը PHP-ով և Եկեք գաղտնագրենք SSL-ը Debian 11-ում: Այժմ կարող եք սկսել ձեր վեբկայքի տեղակայումը Lighttpd վեբ սերվերի միջոցով: Ազատորեն հարցրեք ինձ, եթե ունեք հարցեր: