Сегодня речь пойдет, о том как в релизе Raspbian Stretch установить пакет LAMP (состоящий из Apache2 + Linux + Mysql + PHP), в дальнейшем эта заметка будет опорой при настроение на ней Web-сервисов. Да же самая сложная задача нуждается в разбивке на самые маленькие, где каждый пункт просто и понятен. Так вот эта заметка и есть тот самый маленький шажок к чему-то большему.
В наличии миникомпьютер Raspberry Pi 3 Model B настроенный по заметке и текущая система:
pi@raspberrypi:~ $ uname -a && lsb_release -a
Linux raspberrypi 4.9.45-v7+ #1031 SMP Fri Aug 25 19:02:16 BST 2017 armv7l GNU/Linux
No LSB modules are available.
Distributor ID: Raspbian
Description: Raspbian GNU/Linux 9.1 (stretch)
Release: 9.1
Codename: stretch
Поехали:
pi@raspberrypi:~ $ sudo nano /etc/apt/sources.list
deb http://mirrordirector.raspbian.org/raspbian/ stretch main contrib non-free rpi
pi@raspberrypi:~ $ sudo nano /etc/apt/preferences
Package: *
Pin: release n=jessie
Pin-Priority: 600
pi@raspberrypi:~ $ sudo apt-get update
Hit:1 http://mirrordirector.raspbian.org/raspbian stretch InRelease
Hit:2 http://archive.raspberrypi.org/debian stretch InRelease
Reading package lists... Done
Использую параметр t stretch
который означает, что использовать пакеты из этого релиза, вот выдержка из man apt-get
-t, --target-release, --default-release
This option controls the default input to the policy engine; it
creates a default pin at priority 990 using the specified release
string. This overrides the general settings in
/etc/apt/preferences. Specifically pinned packages are not affected
by the value of this option. In short, this option lets you have
simple control over which distribution packages will be retrieved
from. Some common examples might be -t '2.1*', -t unstable or -t
sid. Configuration Item: APT::Default-Release; see also the
apt_preferences(5) manual page.
На заметку: Чтобы ставить пакеты только из релиза stretch
нужно указывать:
apt-get install -f t stretch htop mysql-server
и т.д.
pi@raspberrypi:~ $ sudo apt-get install php5 mysql-common -y
pi@raspberrypi:~ $ sudo apt-get install mysql-server php5-mysql -y
The following packages have unmet dependencies:
php5-mysql : Depends: libmysqlclient18 but it is not installable
E: Unable to correct problems, you have held broken packages.
pi@raspberrypi:~ $ wget http://security.debian.org/debian-security/pool/updates/main/m/mysql-5.5/libmysqlclient18_5.5.57-0+deb7u1_armhf.deb
libmysqlclient18_5.5.57-0+deb7u1_armhf.tar
pi@raspberrypi:~ $ sudo dpkg -i libmysqlclient18_5.5.57-0+deb7u1_armhf.deb
pi@raspberrypi:~ $ sudo apt-get install mysql-server php5-mysql -y
pi@raspberrypi:~ $ sudo apt-get install php5 apache2 php5-gd php5-mysql php5-ldap php5-cgi php5-cli php-pear php5-xcache libapache2-mod-php5 php-imagick -y
Теперь обозначим системе какую версию интерпретатора языка php использовать как дефолтную:
pi@raspberrypi:~ $ sudo update-alternatives --config php
There are 2 choices for the alternative php (providing /usr/bin/php).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/php7.0 70 auto mode
1 /usr/bin/php5 50 manual mode
2 /usr/bin/php7.0 70 manual mode
Press <enter> to keep the current choice[*], or type selection number: 1
update-alternatives: using /usr/bin/php5 to provide /usr/bin/php (php) in manual mode
Если же в системе была установлена только версия PHP 5, то на обозначение какую использовать по умолчанию утилита ответит, что в системе только одна версия и ничего менять не нужно:
pi@raspberrypi:~ $ sudo update-alternatives --config php
There is only one alternative in link group php (providing /usr/bin/php): /usr/bin/php5
Nothing to configure.
Отобразить текущую установленную версию PHP в системе:
pi@raspberrypi:~ $ php --version
PHP 5.6.22-2+b3 (cli)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
Чтобы проверить, что PHP скрипты исполняются в браузере создадим всем узнаваемый скрипт отображающий информацию о системе:
pi@raspberrypi:~ $ sudo nano /var/www/html/info.php
<?php echo "server is online </br>"; phpinfo(); ?>
pi@raspberrypi:~ $ sudo service apache2 restart
http://IP&DNS/info.php
(Вывод должен быть таким, вот его небольшая часть приведена здесь)
Теперь проверяю, а как же подключиться к MySQL ведь в процессе установки не было запроса на указанием пароля на учетную запись root:
pi@raspberrypi:~ $ mysql -u root
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
pi@raspberrypi:~ $ sudo mysql -u root
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 10.1.23-MariaDB-9+deb9u1 Raspbian 9.0
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
Похоже, что это какая-то особенность установки нацеленная на безопасность, только вот как подключаться не используя sudo, а обычным пользователем как раньше.
MariaDB [(none)]> show grants;
+------------------------------------------------------------------------------------------------+
| Grants for root@localhost |
+------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED VIA unix_socket WITH GRANT OPTION |
| GRANT PROXY ON ''@'%' TO 'root'@'localhost' WITH GRANT OPTION |
+------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
pi@raspberrypi:~ $ sudo mysql -u root
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 6
Server version: 10.1.23-MariaDB-9+deb9u1 Raspbian 9.0
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MariaDB [mysql]> update user set plugin='' where User='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
MariaDB [mysql]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
MariaDB [mysql]> exit
Bye
и после этого доступ в консоль mysql из под обычного пользователя без повышения прав посредством sudo заработал, как нужно:
pi@raspberrypi:~ $ mysql -u root
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 7
Server version: 10.1.23-MariaDB-9+deb9u1 Raspbian 9.0
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
Работает. Теперь нужно назначить пароль на пользователя root в MariaDB:
pi@raspberrypi:~ $ sudo mysql_secure_installation
Enter current password for root (enter for none): нажимаю Enter
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
Set root password? [Y/n] y
New password: 712mbddr@
Re-enter new password: 712mbddr@
Password updated successfully!
Reloading privilege tables..
... Success!
Ну вот и всё, связка LAMP развернута, если нужен интерпретатор скриптов PHP версии 7, то все связанные пакеты ставятся следующим образом:
pi@raspberrypi:~ $ sudo apt-get install -t stretch php7.0 php7.0-curl php7.0-gd php7.0-fpm php7.0-cli php7.0-opcache php7.0-json php7.0-mbstring php7.0-xml php7.0-zip php7.0-mysql -y
pi@raspberrypi:~ $ sudo apt-get install -t stretch libapache2-mod-php7.0 -y
pi@raspberrypi:~ $ sudo apt-get install -t stretch mysql-server mysql-client -y
Нюанс с запуском mysql также устраняется действиями выше по выдачи полномочий запуска от имени текущего пользователя, а не с использованием sudo. На этом моя заметка завершена и я прощаюсь, до новых встреч, с уважением автор блога Олло Александр aka ekzorchik.