Difference between revisions of "Apache 2"
(19 intermediate revisions by the same user not shown) | |||
Line 23: | Line 23: | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
− | apt | + | apt install apache2 apache2-utils |
− | + | apt install ssl-cert | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | apt | ||
</syntaxhighlight> | </syntaxhighlight> | ||
+ | Since Ubuntu 16.04 <code>apache2-mpm-prefork</code> is not required | ||
===Doc=== | ===Doc=== | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
− | apt | + | apt install apache2-doc |
</syntaxhighlight> | </syntaxhighlight> | ||
Line 63: | Line 58: | ||
+ | ==PHP 8== | ||
+ | 2021-11: PHP 8 is not included in Ubuntu 20.04 LTS. | ||
− | == | + | Source article: http://www.daxiongmao.eu/wiki/index.php?title=Apache_2&action=edit |
− | |||
− | === | + | ===Add PHP 8.0 repository=== |
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
− | apt- | + | apt install software-properties-common |
+ | add-apt-repository ppa:ondrej/php | ||
+ | apt update | ||
</syntaxhighlight> | </syntaxhighlight> | ||
+ | ===Install core packages=== | ||
− | + | To install the latest version of PHP: | |
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
− | apt-get install | + | # PHP core |
− | apt-get install | + | apt-get install php |
− | + | apt-get install php-cli | |
− | apt | + | # Apache2 support |
− | + | apt install libapache2-mod-php | |
− | |||
− | |||
</syntaxhighlight> | </syntaxhighlight> | ||
− | === | + | ===Modules PHP=== |
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
− | apt-get install | + | apt-get install php-cgi |
+ | #apt-get install php-opcache | ||
+ | apt-get install php-gd | ||
+ | apt-get install php-bz2 | ||
+ | apt-get install php-curl | ||
+ | apt-get install php-xmlrpc | ||
+ | apt-get install php-json | ||
+ | apt-get install php-mysql | ||
+ | apt-get install php-imap | ||
+ | apt-get install php-mbstring | ||
+ | # Performances | ||
+ | apt install php-fpm libapache2-mod-fcgid | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | Enable modules | |
− | |||
− | |||
− | |||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
− | + | sudo a2enmod proxy_fcgi setenvif | |
+ | sudo a2enconf php8.0-fpm | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | ===Utility=== | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | == | ||
− | |||
− | |||
− | |||
− | |||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
− | + | apt install php-pear | |
</syntaxhighlight> | </syntaxhighlight> | ||
+ | ===Configuration=== | ||
− | + | Edit '''PHP config''' file: | |
− | |||
− | |||
− | |||
− | |||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
− | + | vim /etc/php/8.0/cli/php.ini | |
</syntaxhighlight> | </syntaxhighlight> | ||
+ | * Let CGI behaves like before: set <code>cgi.fix_pathinfo=1</code> | ||
+ | * Adjust file upload size <code>upload_max_filesize = 32M</code> | ||
+ | * Adjust post size <code>post_max_size = 32M</code> | ||
+ | * Adjust time zone <code>date.timezone = Europe/Paris</code> | ||
+ | * Save path: <code>session.save_path = "/tmp"</code> | ||
+ | ===Check PHP version and configuration=== | ||
− | + | To ensure PHP 8.0 is well-installed just type: | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
− | + | php -v | |
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | ===Image Magick=== | |
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
− | + | apt install php-gd php-imagick imagemagick | |
</syntaxhighlight> | </syntaxhighlight> | ||
+ | ===Configuration=== | ||
− | + | Edit PHP config file: | |
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
− | + | vim /etc/php/8.0/apache2/php.ini | |
− | |||
− | |||
− | |||
− | |||
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | Add / uncomment the following lines in Dynamic extensions area | |
− | + | <syntaxhighlight lang="php"> | |
− | + | // PHP 8 (~ line 904) | |
− | <syntaxhighlight lang=" | + | extension=bz2 |
− | + | extension=curl | |
− | + | extension=gd | |
+ | extension=imap | ||
+ | extension=mysqli | ||
</syntaxhighlight> | </syntaxhighlight> | ||
+ | !! Note this is NOT required on Ubuntu 20.04 because these modules are enabled by default !! | ||
− | == | + | ==Firewall== |
− | + | see [[Firewall INPUT filters#Web server]] | |
− | + | Restart the firewall | |
− | |||
− | |||
− | |||
− | |||
− | |||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
− | + | /etc/init.d/firewall restart | |
</syntaxhighlight> | </syntaxhighlight> | ||
− | |||
− | |||
− | + | ==Test your installation== | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | Restart the Apache2 server | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
− | + | service apache2 restart | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | Create a simple PHP script | |
− | Create a | ||
− | |||
− | |||
− | |||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
− | + | vim /var/www/html/phpinfo.php | |
− | |||
− | |||
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | Put the following: | |
− | + | <syntaxhighlight lang="php"> | |
− | + | <?php | |
− | + | phpinfo(); | |
− | + | ?> | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | <syntaxhighlight lang=" | ||
− | |||
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | Adjust rights | |
− | |||
− | |||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
− | + | chown www-data:www-data /var/www/html/phpinfo.php | |
− | + | chmod 755 /var/www/html/phpinfo.php | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | You can now test your installation by going to 'http://localhost/phpinfo.php' or 'http://myServer/phpinfo.php'. You should see the default page. | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− |
Latest revision as of 16:38, 3 November 2021
Contents
Requirements
Before going through this tutorial, I recommend you to setup:
Installation
Apache 2
This will install web server + PHP + Perl + all required libraries.
Apache2 core
apt install apache2 apache2-utils
apt install ssl-cert
Since Ubuntu 16.04 apache2-mpm-prefork
is not required
Doc
apt install apache2-doc
Perl
apt-get install libapache2-mod-perl2 libapache2-mod-perl2-doc
SNMP
Sometimes you might encounter some SNMP errors on latest Debian based distributions.
In that case you have to install a new package and run it.
apt-get install snmp-mibs-downloader
download-mibs
source: http://www.podciborski.co.uk/miscellaneous/snmp-cannot-find-module/
PHP 8
2021-11: PHP 8 is not included in Ubuntu 20.04 LTS.
Source article: http://www.daxiongmao.eu/wiki/index.php?title=Apache_2&action=edit
Add PHP 8.0 repository
apt install software-properties-common
add-apt-repository ppa:ondrej/php
apt update
Install core packages
To install the latest version of PHP:
# PHP core
apt-get install php
apt-get install php-cli
# Apache2 support
apt install libapache2-mod-php
Modules PHP
apt-get install php-cgi
#apt-get install php-opcache
apt-get install php-gd
apt-get install php-bz2
apt-get install php-curl
apt-get install php-xmlrpc
apt-get install php-json
apt-get install php-mysql
apt-get install php-imap
apt-get install php-mbstring
# Performances
apt install php-fpm libapache2-mod-fcgid
Enable modules
sudo a2enmod proxy_fcgi setenvif
sudo a2enconf php8.0-fpm
Utility
apt install php-pear
Configuration
Edit PHP config file:
vim /etc/php/8.0/cli/php.ini
- Let CGI behaves like before: set
cgi.fix_pathinfo=1
- Adjust file upload size
upload_max_filesize = 32M
- Adjust post size
post_max_size = 32M
- Adjust time zone
date.timezone = Europe/Paris
- Save path:
session.save_path = "/tmp"
Check PHP version and configuration
To ensure PHP 8.0 is well-installed just type:
php -v
Image Magick
apt install php-gd php-imagick imagemagick
Configuration
Edit PHP config file:
vim /etc/php/8.0/apache2/php.ini
Add / uncomment the following lines in Dynamic extensions area
// PHP 8 (~ line 904)
extension=bz2
extension=curl
extension=gd
extension=imap
extension=mysqli
!! Note this is NOT required on Ubuntu 20.04 because these modules are enabled by default !!
Firewall
see Firewall INPUT filters#Web server
Restart the firewall
/etc/init.d/firewall restart
Test your installation
Restart the Apache2 server
service apache2 restart
Create a simple PHP script
vim /var/www/html/phpinfo.php
Put the following:
<?php
phpinfo();
?>
Adjust rights
chown www-data:www-data /var/www/html/phpinfo.php
chmod 755 /var/www/html/phpinfo.php
You can now test your installation by going to 'http://localhost/phpinfo.php' or 'http://myServer/phpinfo.php'. You should see the default page.