apache2
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| apache2 [2025/02/25 21:53] – [Apache2] jianwu | apache2 [2025/03/13 12:22] (current) – [Ubuntu 24.04 LTS + Apache2 + PHP installarion and setting] jianwu | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | [[https:// | + | [[https:// |
| ===== Ubuntu 24.04 LTS + Apache2 + PHP installarion and setting ===== | ===== Ubuntu 24.04 LTS + Apache2 + PHP installarion and setting ===== | ||
| ^OS|Ubuntu 24.04.2 LTS| | ^OS|Ubuntu 24.04.2 LTS| | ||
| Line 105: | Line 105: | ||
| ==== Set to start ufw on boot ==== | ==== Set to start ufw on boot ==== | ||
| <code Diff> | <code Diff> | ||
| - | $ git diff etc/ | + | $ git diff /etc/ |
| diff --git a/ | diff --git a/ | ||
| index 8336b91..28fe534 100644 | index 8336b91..28fe534 100644 | ||
| Line 149: | Line 149: | ||
| </ | </ | ||
| - | @@@@@@@@@@@@@@@@@@@@ | ||
| - | (a2enmod is not necessary.) | ||
| - | <code Bash> | ||
| - | a2enmod | ||
| - | script that enables the specified module within the apache2 configuration. It does this by creating symlinks within | ||
| - | a2dismod | ||
| - | disables a module by removing those symlinks. | ||
| - | </ | ||
| - | @@@@@@@@@@@@@@@@@@@@ | ||
| ==== Create user wweb ==== | ==== Create user wweb ==== | ||
| :!: You can change the user name whatever you want. | :!: You can change the user name whatever you want. | ||
| Line 279: | Line 270: | ||
| ====/ | ====/ | ||
| <code Bash> | <code Bash> | ||
| - | | + | DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm |
| </ | </ | ||
| Line 347: | Line 338: | ||
| </ | </ | ||
| - | ==== Enabling SSL ==== | + | ===== Enabling SSL ===== |
| make wweb_ssl.conf from 000-default.conf | make wweb_ssl.conf from 000-default.conf | ||
| Line 376: | Line 367: | ||
| -- | -- | ||
| <code Bash> | <code Bash> | ||
| - | sudo a2ensite wweb_ssl.conf | + | $ sudo a2ensite wweb_ssl.conf |
| - | sudo a2enmod ssl | + | $ sudo a2enmod ssl |
| - | sudo systemctl reload apache2 | + | $ sudo systemctl reload apache2 |
| </ | </ | ||
| + | <code Bash> | ||
| + | a2enmod | ||
| + | script that enables the specified module within the apache2 configuration. It does this by creating symlinks within | ||
| + | a2dismod | ||
| + | disables a module by removing those symlinks. | ||
| + | </ | ||
| + | If you want to use self-signed certificates, | ||
| + | package (see below). Otherwise, just adjust the SSLCertificateKeyFile and | ||
| + | SSLCertificateFile directives in '/ | ||
| + | to point to your SSL certificate. | ||
| + | |||
| + | Then restart apache: | ||
| + | <code Bash> | ||
| + | $ sudo systemctl restart apache2 | ||
| + | </ | ||
| + | |||
| + | ===== Creating self-signed SSL certificates ===== | ||
| + | <code Bash> | ||
| + | $ apt list --installed 2>/ | ||
| + | ssl-cert/ | ||
| + | </ | ||
| + | If it isn't installed | ||
| + | <code Bash> | ||
| + | $ sudo apt install ssl-cert | ||
| + | </ | ||
| + | If you install the ssl-cert package, a self-signed certificate will be | ||
| + | |||
| + | automatically created using the hostname currently configured on your computer. | ||
| + | <code Bash> | ||
| + | SSLCertificateFile | ||
| + | SSLCertificateKeyFile | ||
| + | </ | ||
| + | You can recreate that certificate (e.g. after you have changed '/ | ||
| + | |||
| + | DNS to give the correct hostname) as user root with: | ||
| + | <code Bash> | ||
| + | $ make-ssl-cert generate-default-snakeoil --force-overwrite | ||
| + | </ | ||
| + | |||
| + | To create more certificates with different host names, you can use | ||
| + | |||
| + | make-ssl-cert / | ||
| + | |||
| + | This will ask you for the hostname and place both SSL key and certificate in | ||
| + | the file '/ | ||
| + | directive in the Apache config (you don't need the SSLCertificateKeyFile in | ||
| + | this case as it also contains the key). The file '/ | ||
| + | should only be readable by root. A good directory to use for the additional | ||
| + | certificates/ | ||
| + | |||
| + | make | ||
| + | / | ||
| + | <code Bash> | ||
| + | $ sudo cp / | ||
| + | </ | ||
| + | <code Bash> | ||
| + | $ diff -c / | ||
| + | *** / | ||
| + | --- / | ||
| + | *************** | ||
| + | *** 6,19 **** | ||
| + | default_bits | ||
| + | default_keyfile | ||
| + | distinguished_name | ||
| + | prompt | ||
| + | policy | ||
| + | req_extensions | ||
| + | x509_extensions | ||
| + | |||
| + | [ req_distinguished_name ] | ||
| + | ! commonName | ||
| + | |||
| + | [ v3_req ] | ||
| + | basicConstraints | ||
| + | subjectAltName | ||
| + | --- 6,27 ---- | ||
| + | default_bits | ||
| + | default_keyfile | ||
| + | distinguished_name | ||
| + | + attributes | ||
| + | prompt | ||
| + | policy | ||
| + | req_extensions | ||
| + | x509_extensions | ||
| + | |||
| + | [ req_distinguished_name ] | ||
| + | ! countryName | ||
| + | ! commonName | ||
| + | |||
| + | [ v3_req ] | ||
| + | basicConstraints | ||
| + | subjectAltName | ||
| + | + | ||
| + | + [ req_attributes ] | ||
| + | + challengePassword | ||
| + | + challengePassword_min | ||
| + | + challengePassword_max | ||
| + | + | ||
| + | </ | ||
| + | |||
| + | <code Bash> | ||
| + | $ make-ssl-cert [OPTION]... template output-certificate | ||
| + | </ | ||
| + | ^--force-overwrite|Always create a new certificate, | ||
| + | So, | ||
| + | <code Text> | ||
| + | $ sudo make-ssl-cert --force-overwrite / | ||
| + | Package configuration | ||
| + | ┌─────────────────┤ Configure an SSL Certificate. ├───────────────────────┐ | ||
| + | │ Please enter the host name to use in the SSL certificate. | ||
| + | │ │ | ||
| + | │ It will become the ' | ||
| + | │ │ | ||
| + | │ Host name: │ | ||
| + | │ │ | ||
| + | │ localhost_______________________________________________________________│ | ||
| + | │ │ | ||
| + | │ < | ||
| + | └─────────────────────────────────────────────────────────────────────────┘ | ||
| + | |||
| + | ┌──────────────────────────────┤ Configure an SSL Certificate. ├────────────────────────────────────────────────┐ | ||
| + | │ Please enter any additional names to use in the SSL certificate. | ||
| + | │ │ | ||
| + | │ It will become the ' | ||
| + | │ │ | ||
| + | │ Multiple alternative names should be delimited with comma and no spaces. For a web server with multiple DNS │ | ||
| + | │ names this could look like: │ | ||
| + | │ │ | ||
| + | │ DNS: | ||
| + | │ │ | ||
| + | │ A more complex example including a hostname, a WebID, an email address, and an IPv4 address: | ||
| + | │ │ | ||
| + | │ DNS: | ||
| + | │ │ | ||
| + | │ Alternative name(s): | ||
| + | │ │ | ||
| + | │ DNS: | ||
| + | │ │ | ||
| + | │ < | ||
| + | │ │ | ||
| + | └───────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ | ||
| + | </ | ||
| + | <code Bash> | ||
| + | $ sudo ll / | ||
| + | lrwxrwxrwx 1 root root 18 Feb 25 23:23 9ae71ddb.0 -> wweb_cert-file.crt | ||
| + | -rw------- 1 root root 2896 Feb 25 23:23 wweb_cert-file.crt | ||
| + | </ | ||
| + | |||
| + | For reference, Invoked with " | ||
| + | <code Bash> | ||
| + | $ make-ssl-cert generate-default-snakeoil --force-overwrite | ||
| + | </ | ||
| + | will generate: | ||
| + | <code Bash> | ||
| + | / | ||
| + | and | ||
| + | / | ||
| + | </ | ||
| + | |||
| + | ' | ||
| + | It can additionally create self-signed certificates for use as root CAs for example. | ||
| + | <code Bash> | ||
| + | $ sudo openssl req -new -newkey rsa:2048 -nodes -keyout wweb_server.key -out wweb_server.csr | ||
| + | ......+....+.....+.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*.+...+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*.+.+..+.+..+....+.....+.+..+............................+.....+....+.....+....+..+....+.........+.....+....+.....+............+.+..+.+..+....+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
| + | ..+........+.......+......+.....+..........+..+.+..+.........+....+..+...+.......+..+.+.....+.+...+...+..+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*...+...+...+..............+.+.....+.........+...+....+...+.....+.......+.....+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*....+......+........+......+...................+..+.............+.................+.........+...+.......+.....+...+.+..+...+.+.....+.+........+..........+.....+....+..+....+......+...........+.......+.....+.+..+..........+.........+........+.............+..+..........+..+.+...+..+............+...+....+.....+...+.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
| + | ----- | ||
| + | You are about to be asked to enter information that will be incorporated | ||
| + | into your certificate request. | ||
| + | What you are about to enter is what is called a Distinguished Name or a DN. | ||
| + | There are quite a few fields but you can leave some blank | ||
| + | For some fields there will be a default value, | ||
| + | If you enter ' | ||
| + | ----- | ||
| + | Country Name (2 letter code) [AU]:JP | ||
| + | State or Province Name (full name) [Some-State]: | ||
| + | Locality Name (eg, city) []: | ||
| + | Organization Name (eg, company) [Internet Widgits Pty Ltd]: | ||
| + | Organizational Unit Name (eg, section) []:Security | ||
| + | Common Name (e.g. server FQDN or YOUR name) []: | ||
| + | Email Address []: | ||
| + | |||
| + | Please enter the following ' | ||
| + | to be sent with your certificate request | ||
| + | A challenge password []:******** | ||
| + | An optional company name []: | ||
| + | </ | ||
| + | |||
| + | <code Bash> | ||
| + | $ sudo mv wweb_server.key / | ||
| + | $ sudo openssl x509 -req -signkey / | ||
| + | Certificate request self-signature ok | ||
| + | subject=C = JP, ST = Tokyo, L = Shinjuku-ku, | ||
| + | $ sudo mv wweb_server.csr wweb_server.crt / | ||
| + | </ | ||
| + | |||
| + | <code Bash> | ||
| + | $ sudo ls -la / | ||
| + | lrwxrwxrwx 1 root root 18 Feb 25 23:23 9ae71ddb.0 -> wweb_cert-file.crt | ||
| + | -rw------- 1 root root 2896 Feb 25 23:23 wweb_cert-file.crt | ||
| + | -rw------- 1 root root 1708 Feb 25 23:36 wweb_server.key | ||
| + | </ | ||
| + | <code Bash> | ||
| + | $ ll / | ||
| + | -rw-r--r-- 1 root root 1342 Feb 25 23:44 wweb_server.crt | ||
| + | -rw-r--r-- 1 root root 1106 Feb 25 23:41 wweb_server.csr | ||
| + | </ | ||
| + | |||
| + | The following sections are for reference. | ||
| + | |||
| + | ==== How to create a self-signed PEM file ==== | ||
| + | Privacy Enhanced Mail (PEM) files are concatenated certificate containers frequently used in certificate installations when multiple certificates that form a complete chain are being imported as a single file. They are a defined standard in RFCs 1421 through 1424. They can be thought of as a layered container of chained certificates. A .pem file is a container format that may just include the public certificate or the entire certificate chain (private key, public key, root certificates): | ||
| + | |||
| + | <code Bash> | ||
| + | Private Key | ||
| + | Server Certificate (crt, puplic key) | ||
| + | (optional) Intermediate CA and/or bundles if signed by a 3rd party | ||
| + | </ | ||
| + | |||
| + | <code Bash> | ||
| + | $ sudo openssl req -new -x509 -days 3650 -nodes -newkey rsa:2048 -keyout key.pem -out cert.pem | ||
| + | </ | ||
| + | |||
| + | ==== How to create a PEM file from existing certificate files that form a chain ==== | ||
| + | (optional) Remove the password from the Private Key by following the steps listed below: | ||
| + | <code Bash> | ||
| + | $ openssl rsa -in server.key -out nopassword.key | ||
| + | </ | ||
| + | Note: Enter the pass phrase of the Private Key. | ||
| + | |||
| + | Combine the private key, public certificate and any 3rd party intermediate certificate files: | ||
| + | <code Bash> | ||
| + | $ cat nopassword.key > server.pem | ||
| + | $ cat server.crt >> server.pem | ||
| + | </ | ||
| + | Note: Repeat this step as needed for third-party certificate chain files, bundles, etc: | ||
| + | <code Bash> | ||
| + | cat intermediate.crt >> server.pem | ||
| + | </ | ||
| + | |||
| + | ==== logs of apache2 | ||
| + | / | ||
| + | <code Bash> | ||
| + | export APACHE_LOG_DIR=/ | ||
| + | </ | ||
| + | / | ||
| + | <code Bash> | ||
| + | ErrorLog ${APACHE_LOG_DIR}/ | ||
| + | CustomLog ${APACHE_LOG_DIR}/ | ||
| + | </ | ||
| + | <code Bash> | ||
| + | / | ||
| + | access.log | ||
| + | error.log | ||
| + | </ | ||
| + | |||
apache2.1740488014.txt.gz · Last modified: 2025/02/25 21:53 by jianwu