Настройка Drupal multisite среды для разработчика на Mac OS X 10.8.5. Часть 2. Установка MySQL

Итак, что у нас есть на данный момент.

1) Mac OS X 10.8.5

Установка OS X Mountain Lion 10.8.5 на ноутбук Asus G73Jh

2) PHP 5.3.28 (установлен посредством Homebrew)

Настройка Drupal multisite среды для разработчика на Mac OS X 10.8.5

$ php --version
PHP 5.3.28 (cli) (built: Jan 23 2014 18:02:48) 
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2013 Zend Technologies

3) Apache HTTP Server 2.2.26 (встроен в Mac OS X 10.8.5)


$ httpd -v
Server version: Apache/2.2.26 (Unix)
Server built:   Dec 10 2013 22:06:35

Конфигруция:

3.1) /etc/hosts
  • 127.0.0.1 site1.example.com
  • 127.0.0.1 site2.example.com

3.2) /etc/apache2/httpd.conf
  • LoadModule php5_module /usr/local/Cellar/php56/5.6.0-rc.2/libexec/apache2/libphp5.so
  • Include /private/etc/apache2/extra/httpd-vhosts.conf

3.3) /private/etc/apache2/extra/httpd-vhosts.conf

NameVirtualHost *:80

<VirtualHost *:80>
    DocumentRoot "/Volumes/Projects/drupal"
    ServerName site1.example.com
    <Directory "/Volumes/Projects/drupal">
    Options Indexes FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot /Volumes/Projects/drupal
    ServerName site2.example.com
    <Directory "/Volumes/Projects/drupal">
    Options Indexes FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

Тут у нас мультисайтовая среда будет. Поэтому определено два виртуальных хоста. А папка указана одна и та же, чтобы не поддерживать две одинаковые инсталляции Drupal (движок то один и тот же).

Управление:
  • sudo apachectl start
  • sudo apachectl graceful

4) MySQL


Для полного счастья не хватает MySQL установим его.
Обновим имеющееся уже ПО.

$ brew update
$ brew doctor
$ brew upgrade

Далее устанавливаем MySQL.

Попытка №1. Не рабочий вариант. Просто для ознакомления


$ brew install mysql
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/mysql-5.6.20.mountain_lion.bottle.tar.gz
######################################################################## 100,0%
==> Pouring mysql-5.6.20.mountain_lion.bottle.tar.gz
==> Caveats
A "/etc/my.cnf" from another install may interfere with a Homebrew-built
server starting up correctly.

To connect:
    mysql -uroot

To have launchd start mysql at login:
    ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
Then to load mysql now:
    launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
Or, if you don't want/need launchctl, you can just run:
    mysql.server start
==> /usr/local/Cellar/mysql/5.6.20/bin/mysql_install_db --verbose --user=Abbas --basedir=/usr/local/Cellar/mysql/5.6.20 --datadir=/u
==> Summary
🍺  /usr/local/Cellar/mysql/5.6.20: 9579 files, 342M

Далее перезагружаем сервер и настраиваем безопасность.

$ mysql.server restart
 ERROR! MySQL server PID file could not be found!
Starting MySQL
.. SUCCESS! 
$ mysql_secure_installation



NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

Set root password? [Y/n] Y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] Y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] Y
 ... Success!

By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] Y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] Y
 ... Success!




All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!


Cleaning up...

Создадим файл /etc/my.cnf со следующим содержанием:

#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
# This will be passed to all mysql clients
# It has been reported that passwords should be enclosed with
# ticks/quotes escpecially if they contain "#" chars...
# Remember to edit /etc/mysql/debian.cnf when changing
# the socket location.
[client]
port        = 3306
#socket     = /var/run/mysqld/mysqld.sock
# Here is entries for some specific programs
# The following values assume you have at least 32M ram
# This was formally known as [safe_mysqld]. Both versions
# are currently parsed.
[mysqld_safe]
#socket     = /var/run/mysqld/mysqld.sock
#nice       = 0
[mysqld]
#
# * Basic Settings
#
#
# * IMPORTANT
#   If you make changes to these settings and your system uses
#   apparmor, you may also need to also adjust
#   /etc/apparmor.d/usr.sbin.mysqld.
#
#user       = mysql
#socket     = /var/run/mysqld/mysqld.sock
port        = 3306
#basedir    = /usr
#datadir    = /var/lib/mysql
#tmpdir     = /tmp
skip-external-locking
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address        = 127.0.0.1
#
# * Fine Tuning
#
key_buffer          = 16M
max_allowed_packet  = 16M
thread_stack        = 192K
thread_cache_size   = 8
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover         = BACKUP
#max_connections       = 100
#table_cache           = 64
#thread_concurrency    = 10
#
# * Query Cache Configuration
#
query_cache_limit   = 1M
query_cache_size    = 16M
#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
# As of 5.1 you can enable the log at runtime!
#general_log_file        = /var/log/mysql/mysql.log
#general_log             = 1
log_error                = /var/log/mysql/error.log
# Here you can see queries with especially long duration
#log_slow_queries   = /var/log/mysql/mysql-slow.log
#long_query_time = 2
#log-queries-not-using-indexes
#
# The following can be used as easy to replay backup logs or
# for replication.
# note: if you are setting up a replication slave, see
#       README.Debian about other settings you may need
#       to change.
#server-id          = 1
#log_bin            = /var/log/mysql/mysql-bin.log
expire_logs_days    = 10
max_binlog_size     = 100M
#binlog_do_db       = include_database_name
#binlog_ignore_db   = include_database_name
#
# * InnoDB
#
# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/.
# Read the manual for more InnoDB related options. There are many!
#
# * Security Features
#
# Read the manual, too, if you want chroot!
# chroot = /var/lib/mysql/
#
# For generating SSL certificates I recommend the OpenSSL GUI "tinyca".
#
# ssl-ca=/etc/mysql/cacert.pem
# ssl-cert=/etc/mysql/server-cert.pem
# ssl-key=/etc/mysql/server-key.pem
# Query Caching
query-cache-type = 1
# Default to InnoDB
default-storage-engine=innodb
[mysqldump]
quick
quote-names
max_allowed_packet  = 16M
[mysql]
#no-auto-rehash # faster start of mysql but no tab completition
[isamchk]
key_buffer      = 16M

Далее:

$ unset TMPDIR
$ mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp

Installing MySQL system tables...2014-08-22 17:05:14 0 [Warning] Using unique option prefix key_buffer instead of key_buffer_size is deprecated and will be removed in a future release. Please use the full name instead.
2014-08-22 17:05:14 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
OK

Filling help tables...2014-08-22 17:05:20 0 [Warning] Using unique option prefix key_buffer instead of key_buffer_size is deprecated and will be removed in a future release. Please use the full name instead.
2014-08-22 17:05:20 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

  /usr/local/opt/mysql/bin/mysqladmin -u root password 'new-password'
  /usr/local/opt/mysql/bin/mysqladmin -u root -h MacBook-Abbas.local password 'new-password'

Alternatively you can run:

  /usr/local/opt/mysql/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:

  cd . ; /usr/local/opt/mysql/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl

  cd mysql-test ; perl mysql-test-run.pl

Please report any problems at http://bugs.mysql.com/

The latest information about MySQL is available on the web at

  http://www.mysql.com

Support MySQL by buying support/licenses at http://shop.mysql.com

WARNING: Found existing config file /usr/local/opt/mysql/my.cnf on the system.
Because this file might be in use, it was not replaced,
but was used in bootstrap (unless you used --defaults-file)
and when you later start the server.
The new default config file was created as /usr/local/opt/mysql/my-new.cnf,
please compare it with your file and take the changes you need.

WARNING: Default config file /etc/my.cnf exists on the system
This file will be read by default by the MySQL server
If you do not want to use this, either remove it, or use the
--defaults-file argument to mysqld_safe when starting the server

Снова перезапускаем сервер:

$ mysql.server restart

Вылезла ошибка:

 ERROR! MySQL server PID file could not be found!
Starting MySQL
. ERROR! The server quit without updating PID file (/usr/local/var/mysql/MacBook-Abbas.local.pid).

cat /usr/local/var/mysql/MacBook-Abbas.local.err показывает:

2014-08-22 17:35:10 54459 [ERROR] /usr/local/Cellar/mysql/5.6.20/bin/mysqld: Can't create/write to file '/usr/local/var/mysql/MacBook-Abbas.local.pid' (Errcode: 13 - Permission denied)
2014-08-22 17:35:10 54459 [ERROR] Can't start server: can't create PID file: Permission denied
140822 17:35:10 mysqld_safe mysqld from pid file /usr/local/var/mysql/MacBook-Abbas.local.pid ended

Пробовал решить так:
$ sudo chown -R _mysql /usr/local/var/mysql

Еше так:
$ chmod 0755 /var
$ chown root:wheel /var/tmp
$ sudo chmod 0771 /usr/local/var/mysql/*

И так:
$ sudo chown -R mysql /usr/local/var/mysql/

Попытка №2


Сносим всё:
brew uninstall mysql
rm -Rf /usr/local/var/mysql

И ставим заново:

$ brew install mysql
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/mysql-5.6.20.mountain_lion.bottle.tar.gz
Already downloaded: /Library/Caches/Homebrew/mysql-5.6.20.mountain_lion.bottle.tar.gz
==> Pouring mysql-5.6.20.mountain_lion.bottle.tar.gz
==> Caveats
A "/etc/my.cnf" from another install may interfere with a Homebrew-built
server starting up correctly.

To connect:
    mysql -uroot

To have launchd start mysql at login:
    ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
Then to load mysql now:
    launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
Or, if you don't want/need launchctl, you can just run:
    mysql.server start
==> /usr/local/Cellar/mysql/5.6.20/bin/mysql_install_db --verbose --user=Abbas --basedir=/usr/local/Cellar/mysql/5.6.20 --datadir=/usr/local/var/mysql --tmpdir=/tmp
==> Summary
🍺  /usr/local/Cellar/mysql/5.6.20: 9579 files, 342M

$ /usr/local/Cellar/mysql/5.6.20/bin/mysql_install_db --verbose --user=Abbas --basedir=/usr/local/Cellar/mysql/5.6.20 --datadir=/usr/local/var/mysql --tmpdir=/tmp
Installing MySQL system tables...2014-08-22 18:47:11 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2014-08-22 18:47:11 60045 [Note] InnoDB: Using atomics to ref count buffer pool pages
2014-08-22 18:47:11 60045 [Note] InnoDB: The InnoDB memory heap is disabled
2014-08-22 18:47:11 60045 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2014-08-22 18:47:11 60045 [Note] InnoDB: Memory barrier is not used
2014-08-22 18:47:11 60045 [Note] InnoDB: Compressed tables use zlib 1.2.3
2014-08-22 18:47:11 60045 [Note] InnoDB: Using CPU crc32 instructions
2014-08-22 18:47:11 60045 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2014-08-22 18:47:11 60045 [Note] InnoDB: Completed initialization of buffer pool
2014-08-22 18:47:11 60045 [Note] InnoDB: Highest supported file format is Barracuda.
2014-08-22 18:47:11 60045 [Note] InnoDB: 128 rollback segment(s) are active.
2014-08-22 18:47:11 60045 [Note] InnoDB: Waiting for purge to start
2014-08-22 18:47:11 60045 [Note] InnoDB: 5.6.20 started; log sequence number 1625997
2014-08-22 18:47:11 60045 [Note] RSA private key file not found: /usr/local/var/mysql//private_key.pem. Some authentication plugins will not work.
2014-08-22 18:47:11 60045 [Note] RSA public key file not found: /usr/local/var/mysql//public_key.pem. Some authentication plugins will not work.
2014-08-22 18:47:15 60045 [Note] Binlog end
2014-08-22 18:47:15 60045 [Note] InnoDB: FTS optimize thread exiting.
2014-08-22 18:47:15 60045 [Note] InnoDB: Starting shutdown...
2014-08-22 18:47:17 60045 [Note] InnoDB: Shutdown completed; log sequence number 1626007
OK

Filling help tables...2014-08-22 18:47:17 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2014-08-22 18:47:17 60046 [Note] InnoDB: Using atomics to ref count buffer pool pages
2014-08-22 18:47:17 60046 [Note] InnoDB: The InnoDB memory heap is disabled
2014-08-22 18:47:17 60046 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2014-08-22 18:47:17 60046 [Note] InnoDB: Memory barrier is not used
2014-08-22 18:47:17 60046 [Note] InnoDB: Compressed tables use zlib 1.2.3
2014-08-22 18:47:17 60046 [Note] InnoDB: Using CPU crc32 instructions
2014-08-22 18:47:17 60046 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2014-08-22 18:47:17 60046 [Note] InnoDB: Completed initialization of buffer pool
2014-08-22 18:47:17 60046 [Note] InnoDB: Highest supported file format is Barracuda.
2014-08-22 18:47:17 60046 [Note] InnoDB: 128 rollback segment(s) are active.
2014-08-22 18:47:17 60046 [Note] InnoDB: Waiting for purge to start
2014-08-22 18:47:17 60046 [Note] InnoDB: 5.6.20 started; log sequence number 1626007
2014-08-22 18:47:17 60046 [Note] RSA private key file not found: /usr/local/var/mysql//private_key.pem. Some authentication plugins will not work.
2014-08-22 18:47:17 60046 [Note] RSA public key file not found: /usr/local/var/mysql//public_key.pem. Some authentication plugins will not work.
2014-08-22 18:47:17 60046 [Note] Binlog end
2014-08-22 18:47:17 60046 [Note] InnoDB: FTS optimize thread exiting.
2014-08-22 18:47:17 60046 [Note] InnoDB: Starting shutdown...
2014-08-22 18:47:18 60046 [Note] InnoDB: Shutdown completed; log sequence number 1626017
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

  /usr/local/Cellar/mysql/5.6.20/bin/mysqladmin -u root password 'new-password'
  /usr/local/Cellar/mysql/5.6.20/bin/mysqladmin -u root -h MacBook-Abbas.local password 'new-password'

Alternatively you can run:

  /usr/local/Cellar/mysql/5.6.20/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:

  cd . ; /usr/local/Cellar/mysql/5.6.20/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl

  cd mysql-test ; perl mysql-test-run.pl

Please report any problems at http://bugs.mysql.com/

The latest information about MySQL is available on the web at

  http://www.mysql.com

Support MySQL by buying support/licenses at http://shop.mysql.com

WARNING: Found existing config file /usr/local/Cellar/mysql/5.6.20/my.cnf on the system.
Because this file might be in use, it was not replaced,
but was used in bootstrap (unless you used --defaults-file)
and when you later start the server.
The new default config file was created as /usr/local/Cellar/mysql/5.6.20/my-new.cnf,
please compare it with your file and take the changes you need.

Запускаем mysql_secure_installation предварительно убедившись что MySQL запущен.


--