1 Preliminary Note: - Hit Return
1 Preliminary Note: - Hit Return
In this tutorial, I use the hostname server1.example.comwith the IP address 192.168.1.100. These
settings might differ for you, so you have to replace them where appropriate.
Apache's default document root is /var/www on Debian, and the configuration file
is /etc/apache2/apache2.conf. Additional configurations are stored in subdirectories of
the /etc/apache2 directory such as /etc/apache2/mods-enabled (for Apache
modules), /etc/apache2/sites-enabled (for virtual hosts), and /etc/apache2/conf-enabled.
4 Installing PHP 7.1
We can install PHP and the Apache PHP module as follows:
apt-get -y install php7.0 libapache2-mod-php7.0
We must restart Apache afterward:
service apache2 restart
5 Testing PHP / Getting details about your PHP installation
The document root of the default web site is /var/www/html. We will now create a small PHP file
(info.php) in that directory and call it in a browser. The file will display lots of useful details about our
PHP installation, such as the installed PHP version.
nano /var/www/html/info.php
<?php
phpinfo();
Now we call that file in a browser (e.g. http://192.168.1.100/info.php):
As you see, PHP 7.0 is working, and it's working through the Apache 2.0 Handler, as shown in
the Server API line. If you scroll further down, you will see all modules that are already enabled in
PHP5. MySQL / MariaDB is not listed there which means we don't have MySQL support in PHP5 yet.
6 Getting MySQL and MariaDB Support in PHP
To get MySQL support in PHP, we will install the php7.0-mysql package. It's a good idea to install
some other PHP modules as well as you might need them for your applications. You can search for
available PHP 7 modules like this:
apt-cache search php7.0
Pick the ones you need and install them like this:
apt-get -y install php7.0-mysql php7.0-curl php7.0-gd php7.0-intl php-pear php-imagick php7.0-imap
php7.0-mcrypt php-memcache php7.0-pspell php7.0-recode php7.0-sqlite3 php7.0-tidy php7.0-xmlrpc
php7.0-xsl
Now restart Apache:
service apache2 restart
7 PHP Cache to improve the PHP speed
To speed up PHP, an Opcache should be installed. Check if the PHP Opcache module has been
installed and enabled correctly.Run this command:
php --version
The output shall contain the line I marked in red.
PHP 7.0.27-0+deb9u1 (cli) (built: Jan 5 2018 13:51:52) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.0.27-0+deb9u1, Copyright (c) 1999-2017, by Zend Technologies
If you do not see the Opcache module in the result, install it with this command:
apt-get -y install php7.0-opcache
There is one more cache which might be useful, it's name is APCu. APCu is a free PHP opcode cacher
for caching and optimizing PHP intermediate code.
APCu can be installed as follows:
apt-get -y install php-apcu
Now restart Apache:
service apache2 restart
Now reload http://192.168.1.100/info.php in your browser and scroll down to the modules section
again. You should now find lots of new modules there, including the MySQL module which is used as
MariaDB driver:
8 phpMyAdmin
phpMyAdmin is a web interface through which you can manage your MySQL and MariaDB databases.
It's a good idea to install it:
apt-get -y install phpmyadmin
You will see the following questions:
MySQL application password for phpmyadmin: <-- Press enter, apt will create a random password
automatically.
Afterwards, you can access phpMyAdmin under http://192.168.1.100/phpmyadmin/:
9 Enable MySQL root Login for phpMyAdmin
While you can log in as root user into MariaDB on the shell, the root login will not work in
phpMyAdmin. To allow the root user to use phpMyAdmin as well, run the following command on the
shell:
echo "UPDATE mysql.user SET plugin = 'mysql_native_password' WHERE user = 'root' AND plugin
= 'unix_socket';FLUSH PRIVILEGES;" | mysql -u root -p
10 Links
Apache: http://httpd.apache.org/
PHP: http://www.php.net/
MySQL: http://www.mysql.com/
Debian: http://www.debian.org/
phpMyAdmin: http://www.phpmyadmin.net/