Difference between revisions of "Apache 2"

(Configuration)
 
(3 intermediate revisions by the same user not shown)
Line 23: Line 23:
  
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
apt-get install apache2 apache2-utils ssl-cert
+
apt install apache2 apache2-utils  
 +
apt install ssl-cert
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
Since Ubuntu 16.04 <code>apache2-mpm-prefork</code> is not required
 
Since Ubuntu 16.04 <code>apache2-mpm-prefork</code> is not required
 
===Additional libraries===
 
 
<syntaxhighlight lang="bash">
 
apt-get install libapache2-mod-fcgid libruby
 
</syntaxhighlight>
 
 
  
 
===Doc===  
 
===Doc===  
  
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
apt-get install apache2-doc
+
apt install apache2-doc
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Line 64: Line 58:
  
  
==PHP 7==
+
==PHP 8==
 +
2021-11: PHP 8 is not included in Ubuntu 20.04 LTS.
  
2016-09: Even though PHP7 has been released in 2015 it is not in the official repositories because '''it is not 100% backward compatible with PHP5'''. As it is not in the repositories '''you must install all applications manually''' (PHPMyAdmin, etc.)
+
Source article: http://www.daxiongmao.eu/wiki/index.php?title=Apache_2&action=edit
  
 +
===Add PHP 8.0 repository===
  
The following instructions are based on https://www.justegeek.fr/installer-php-7-0-apache2-debian-8/ && http://www.configserverfirewall.com/ubuntu-linux/install-php-7-on-ubuntu-14/
 
 
 
2016-12: '''PHP 7.0 is available in UBUNTU 16.10 and later'''
 
 
 
===(Ubuntu 16.04) PHP7 repository===
 
 
Add a new repository:
 
 
DEBIAN
 
<syntaxhighlight lang="bash">
 
echo "deb http://packages.dotdeb.org jessie all" > /etc/apt/sources.list.d/dotdeb.list
 
wget https://www.dotdeb.org/dotdeb.gpg && apt-key add dotdeb.gpg
 
apt-get update
 
</syntaxhighlight>
 
 
UBUNTU SERVER
 
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
add-apt-repository ppa:ondrej/php-7.0
+
apt install software-properties-common
apt-get update
+
add-apt-repository ppa:ondrej/php
 +
apt update
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 +
===Install core packages===
  
===Installation===
+
To install the latest version of PHP:
  
Remove PHP5 packages, if any:
 
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
apt-get --purge remove php5*
+
# PHP core
 +
apt-get install php
 +
apt-get install php-cli
 +
# Apache2 support
 +
apt install libapache2-mod-php
 
</syntaxhighlight>
 
</syntaxhighlight>
  
  
Install core packages
+
===Modules PHP===
 +
 
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
apt-get install php7.2
+
apt-get install php-cgi
apt-get install php7.2-cli
+
#apt-get install php-opcache
apt install php libapache2-mod-php
+
apt-get install php-gd
 
+
apt-get install php-bz2
# Debug symbols
+
apt-get install php-curl
apt-get install php7.2-dev
+
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
===Modules PHP7===
 
  
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
apt-get install php7.2-cgi
+
sudo a2enmod proxy_fcgi setenvif
apt-get install php7.2-opcache
+
sudo a2enconf php8.0-fpm
apt-get install php7.2-gd
 
apt-get install php7.2-bz2
 
apt-get install php7.2-curl
 
apt-get install php7.2-xmlrpc php7.2-xsl
 
apt-get install php7.2-soap
 
apt-get install php7.2-json
 
apt-get install php7.2-mysql
 
apt-get install php7.2-memcached
 
apt-get install php7.2-imap
 
apt-get install php7.2-mbstring
 
 
</syntaxhighlight>
 
</syntaxhighlight>
 
(i) do NOT install <code>php7.0-snmp</code> because it generates a lot of error, especially on AMAZON EC2.
 
  
 
===Utility===
 
===Utility===
  
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
apt-get install php-pear  
+
apt install php-pear  
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Line 142: Line 119:
  
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
vim /etc/php/7.2/cli/php.ini
+
vim /etc/php/8.0/cli/php.ini
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Line 153: Line 130:
 
===Check PHP version and configuration===
 
===Check PHP version and configuration===
  
To ensure PHP 7.0 is well-installed just type:  
+
To ensure PHP 8.0 is well-installed just type:  
  
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
php -v
 
php -v
</syntaxhighlight>
 
 
==PHP 5==
 
 
2016-09: PHP5 is the only version in the OFFICIAL repositories.
 
 
===Core===
 
 
<syntaxhighlight lang="bash">
 
apt-get install libapache2-mod-php5 php5 php5-common
 
</syntaxhighlight>
 
 
 
===Modules PHP5===
 
 
<syntaxhighlight lang="bash">
 
apt-get install php5-cli php5-cgi
 
apt-get install php5-curl php5-xmlrpc php5-xsl php5-dev php-pear
 
apt-get install php5-mysql
 
apt-get install php5-memcache php5-xcache
 
apt-get install php5-mhash php-auth php5-mcrypt mcrypt
 
apt-get install php5-imap
 
apt-get install php5-snmp
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Line 186: Line 140:
  
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
#PHP 5
+
apt install php-gd php-imagick imagemagick
apt-get install php5-gd php5-imagick imagemagick
 
 
 
#PHP 7
 
apt-get install php7.2-gd php-imagick imagemagick
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Line 198: Line 148:
  
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
#PHP 5
+
vim /etc/php/8.0/apache2/php.ini
vim /etc/php5/apache2/php.ini
 
 
 
#PHP 7.2
 
vim /etc/php/7.2/apache2/php.ini
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
Add / uncomment the following lines in Dynamic extensions area
 
Add / uncomment the following lines in Dynamic extensions area
 
<syntaxhighlight lang="php">
 
<syntaxhighlight lang="php">
// PHP 5 (~ line 865)
+
// PHP 8 (~ line 904)
extension=mysql.so
+
extension=bz2
extension=gd.so
+
extension=curl
 
+
extension=gd
 
+
extension=imap
// PHP 7  (~ line 904)
 
 
extension=mysqli
 
extension=mysqli
extension=gd2
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
  
!! Note this is NOT required on Ubuntu 14.04 because these modules are enabled by default !!
+
!! Note this is NOT required on Ubuntu 20.04 because these modules are enabled by default !!
  
 
==Firewall==
 
==Firewall==
Line 244: Line 188:
 
Create a simple PHP script
 
Create a simple PHP script
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
vim /var/www/phpinfo.php
+
vim /var/www/html/phpinfo.php
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Line 256: Line 200:
 
Adjust rights
 
Adjust rights
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
chown www-data:www-data /var/www/phpinfo.php
+
chown www-data:www-data /var/www/html/phpinfo.php
chmod 755 /var/www/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.
 
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 17:38, 3 November 2021



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.