setup.rst 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  1. .. _setup:
  2. Installation
  3. ============
  4. phpMyAdmin does not apply any special security methods to the MySQL
  5. database server. It is still the system administrator's job to grant
  6. permissions on the MySQL databases properly. phpMyAdmin's :guilabel:`Users`
  7. page can be used for this.
  8. .. warning::
  9. :term:`Mac` users should note that if you are on a version before
  10. :term:`Mac OS X`, StuffIt unstuffs with :term:`Mac` formats. So you'll have
  11. to resave as in BBEdit to Unix style ALL phpMyAdmin scripts before
  12. uploading them to your server, as PHP seems not to like :term:`Mac`-style
  13. end of lines character ("``\r``").
  14. Linux distributions
  15. +++++++++++++++++++
  16. phpMyAdmin is included in most Linux distributions. It is recommended to use
  17. distribution packages when possible - they usually provide integration to your
  18. distribution and you will automatically get security updates from your distribution.
  19. Debian
  20. ------
  21. Debian's package repositories include a phpMyAdmin package, but be aware that
  22. the configuration file is maintained in ``/etc/phpmyadmin`` and may differ in
  23. some ways from the official phpMyAdmin documentation.
  24. OpenSUSE
  25. --------
  26. OpenSUSE already comes with phpMyAdmin package, just install packages from
  27. the `openSUSE Build Service <http://software.opensuse.org/package/phpMyAdmin>`_.
  28. Ubuntu
  29. ------
  30. Ubuntu ships phpMyAdmin package, however if you want to use recent version, you
  31. can use packages from
  32. `PPA for Michal Čihař <https://launchpad.net/~nijel/+archive/phpmyadmin>`_.
  33. Gentoo
  34. ------
  35. Gentoo ships the phpMyAdmin package, both in a near stock configuration as well
  36. as in a ``webapp-config`` configuration. Use ``emerge dev-db/phpmyadmin`` to
  37. install.
  38. Mandriva
  39. --------
  40. Mandriva ships the phpMyAdmin package in their ``contrib`` branch and can be
  41. installed via the usual Control Center.
  42. Fedora
  43. ------
  44. Fedora ships the phpMyAdmin package, but be aware that the configuration file
  45. is maintained in ``/etc/phpMyAdmin/`` and may differ in some ways from the
  46. official phpMyAdmin documentation.
  47. Red Hat Enterprise Linux
  48. ------------------------
  49. Red Hat Enterprise Linux itself and thus derivatives like CentOS don't
  50. ship phpMyAdmin, but the Fedora-driven repository
  51. `Extra Packages for Enterprise Linux (EPEL) <http://fedoraproject.org/wiki/EPEL>`_
  52. is doing so, if it's
  53. `enabled <http://fedoraproject.org/wiki/EPEL/FAQ#howtouse>`_.
  54. But be aware that the configuration file is maintained in
  55. ``/etc/phpMyAdmin/`` and may differ in some ways from the
  56. official phpMyAdmin documentation.
  57. Installing on Windows
  58. +++++++++++++++++++++
  59. The easiest way to get phpMyAdmin on Windows is using third party products
  60. which include phpMyAdmin together with a database and web server such as
  61. `XAMPP <http://www.apachefriends.org/en/xampp.html>`_.
  62. You can find more of such options at `Wikipedia <https://en.wikipedia.org/wiki/List_of_AMP_packages>`_.
  63. .. _quick_install:
  64. Quick Install
  65. +++++++++++++
  66. #. Choose an appropriate distribution kit from the phpmyadmin.net
  67. Downloads page. Some kits contain only the English messages, others
  68. contain all languages. We'll assume you chose a kit whose name
  69. looks like ``phpMyAdmin-x.x.x -all-languages.tar.gz``.
  70. #. Untar or unzip the distribution (be sure to unzip the subdirectories):
  71. ``tar -xzvf phpMyAdmin_x.x.x-all-languages.tar.gz`` in your
  72. webserver's document root. If you don't have direct access to your
  73. document root, put the files in a directory on your local machine,
  74. and, after step 4, transfer the directory on your web server using,
  75. for example, ftp.
  76. #. Ensure that all the scripts have the appropriate owner (if PHP is
  77. running in safe mode, having some scripts with an owner different from
  78. the owner of other scripts will be a problem). See :ref:`faq4_2` and
  79. :ref:`faq1_26` for suggestions.
  80. #. Now you must configure your installation. There are two methods that
  81. can be used. Traditionally, users have hand-edited a copy of
  82. :file:`config.inc.php`, but now a wizard-style setup script is provided
  83. for those who prefer a graphical installation. Creating a
  84. :file:`config.inc.php` is still a quick way to get started and needed for
  85. some advanced features.
  86. Manually creating the file
  87. --------------------------
  88. To manually create the file, simply use your text editor to create the
  89. file :file:`config.inc.php` (you can copy :file:`config.sample.inc.php` to get
  90. a minimal configuration file) in the main (top-level) phpMyAdmin
  91. directory (the one that contains :file:`index.php`). phpMyAdmin first
  92. loads :file:`libraries/config.default.php` and then overrides those values
  93. with anything found in :file:`config.inc.php`. If the default value is
  94. okay for a particular setting, there is no need to include it in
  95. :file:`config.inc.php`. You'll probably need only a few directives to get going; a
  96. simple configuration may look like this:
  97. .. code-block:: xml+php
  98. <?php
  99. $cfg['blowfish_secret'] = 'ba17c1ec07d65003'; // use here a value of your choice
  100. $i=0;
  101. $i++;
  102. $cfg['Servers'][$i]['auth_type'] = 'cookie';
  103. ?>
  104. Or, if you prefer to not be prompted every time you log in:
  105. .. code-block:: xml+php
  106. <?php
  107. $i=0;
  108. $i++;
  109. $cfg['Servers'][$i]['user'] = 'root';
  110. $cfg['Servers'][$i]['password'] = 'cbb74bc'; // use here your password
  111. $cfg['Servers'][$i]['auth_type'] = 'config';
  112. ?>
  113. For a full explanation of possible configuration values, see the
  114. :ref:`config` of this document.
  115. .. index:: Setup script
  116. .. _setup_script:
  117. Using Setup script
  118. ------------------
  119. Instead of manually editing :file:`config.inc.php`, you can use the `Setup
  120. Script <setup/>`_. First you must manually create a folder ``config``
  121. in the phpMyAdmin directory. This is a security measure. On a
  122. Linux/Unix system you can use the following commands:
  123. .. code-block:: sh
  124. cd phpMyAdmin
  125. mkdir config # create directory for saving
  126. chmod o+rw config # give it world writable permissions
  127. And to edit an existing configuration, copy it over first:
  128. .. code-block:: sh
  129. cp config.inc.php config/ # copy current configuration for editing
  130. chmod o+w config/config.inc.php # give it world writable permissions
  131. On other platforms, simply create the folder and ensure that your web
  132. server has read and write access to it. :ref:`faq1_26` can help with
  133. this.
  134. Next, open ``setup/`` in your browser. If you have an existing configuration,
  135. use the ``Load`` button to bring its content inside the setup panel.
  136. Note that **changes are not saved to disk until you explicitly choose ``Save``**
  137. from the *Configuration* area of the screen. Normally the script saves the new
  138. :file:`config.inc.php` to the ``config/`` directory, but if the webserver does
  139. not have the proper permissions you may see the error "Cannot load or
  140. save configuration." Ensure that the ``config/`` directory exists and
  141. has the proper permissions - or use the ``Download`` link to save the
  142. config file locally and upload it (via FTP or some similar means) to the
  143. proper location.
  144. Once the file has been saved, it must be moved out of the ``config/``
  145. directory and the permissions must be reset, again as a security
  146. measure:
  147. .. code-block:: sh
  148. mv config/config.inc.php . # move file to current directory
  149. chmod o-rw config.inc.php # remove world read and write permissions
  150. rm -rf config # remove not needed directory
  151. Now the file is ready to be used. You can choose to review or edit the
  152. file with your favorite editor, if you prefer to set some advanced
  153. options which the setup script does not provide.
  154. #. If you are using the ``auth_type`` "config", it is suggested that you
  155. protect the phpMyAdmin installation directory because using config
  156. does not require a user to enter a password to access the phpMyAdmin
  157. installation. Use of an alternate authentication method is
  158. recommended, for example with HTTP–AUTH in a :term:`.htaccess` file or switch to using
  159. ``auth_type`` cookie or http. See the :ref:`faqmultiuser`
  160. for additional information, especially :ref:`faq4_4`.
  161. #. Open the `main phpMyAdmin directory <index.php>`_ in your browser.
  162. phpMyAdmin should now display a welcome screen and your databases, or
  163. a login dialog if using :term:`HTTP` or
  164. cookie authentication mode.
  165. #. You should deny access to the ``./libraries`` and ``./setup/lib``
  166. subfolders in your webserver configuration. For Apache you can use
  167. supplied :term:`.htaccess` file in that folder, for other webservers, you should
  168. configure this yourself. Such configuration prevents from possible
  169. path exposure and cross side scripting vulnerabilities that might
  170. happen to be found in that code.
  171. #. It is generally a good idea to protect a public phpMyAdmin installation
  172. against access by robots as they usually can not do anything good
  173. there. You can do this using ``robots.txt`` file in root of your
  174. webserver or limit access by web server configuration, see
  175. :ref:`faq1_42`.
  176. .. index::
  177. single: Configuration storage
  178. single: phpMyAdmin configuration storage
  179. single: pmadb
  180. .. _linked-tables:
  181. phpMyAdmin configuration storage
  182. ++++++++++++++++++++++++++++++++
  183. For a whole set of additional features (bookmarks, comments, :term:`SQL`-history,
  184. tracking mechanism, :term:`PDF`-generation, column contents transformation,
  185. etc.) you need to create a set of special tables. Those tables can be located
  186. in your own database, or in a central database for a multi-user installation
  187. (this database would then be accessed by the controluser, so no other user
  188. should have rights to it).
  189. Please look at your ``./examples/`` directory, where you should find a
  190. file called *create\_tables.sql*. (If you are using a Windows server,
  191. pay special attention to :ref:`faq1_23`).
  192. If you already had this infrastructure and upgraded to MySQL 4.1.2 or
  193. newer, please use :file:`examples/upgrade_tables_mysql_4_1_2+.sql`
  194. and then create new tables by importing
  195. :file:`examples/create_tables.sql`.
  196. You can use your phpMyAdmin to create the tables for you. Please be
  197. aware that you may need special (administrator) privileges to create
  198. the database and tables, and that the script may need some tuning,
  199. depending on the database name.
  200. After having imported the :file:`examples/create_tables.sql` file, you
  201. should specify the table names in your :file:`config.inc.php` file. The
  202. directives used for that can be found in the :ref:`config`.
  203. You will also need to have a controluser
  204. (:config:option:`$cfg['Servers'][$i]['controluser']` and
  205. :config:option:`$cfg['Servers'][$i]['controlpass']` settings)
  206. with the proper rights to those tables. For example you can create it
  207. using following statement:
  208. .. code-block:: mysql
  209. GRANT SELECT, INSERT, UPDATE, DELETE ON <pma_db>.* TO 'pma'@'localhost' IDENTIFIED BY 'pmapass';
  210. .. _upgrading:
  211. Upgrading from an older version
  212. +++++++++++++++++++++++++++++++
  213. Simply copy :file:`config.inc.php` from your previous installation into
  214. the newly unpacked one. Configuration files from old versions may
  215. require some tweaking as some options have been changed or removed.
  216. For compatibility with PHP 6, remove a
  217. ``set_magic_quotes_runtime(0);`` statement that you might find near
  218. the end of your configuration file.
  219. You should **not** copy :file:`libraries/config.default.php` over
  220. :file:`config.inc.php` because the default configuration file is version-
  221. specific.
  222. If you have upgraded your MySQL server from a version previous to 4.1.2 to
  223. version 5.x or newer and if you use the phpMyAdmin configuration storage, you
  224. should run the :term:`SQL` script found in
  225. :file:`examples/upgrade_tables_mysql_4_1_2+.sql`.
  226. .. index:: Authentication mode
  227. .. _authentication_modes:
  228. Using authentication modes
  229. ++++++++++++++++++++++++++
  230. :term:`HTTP` and cookie authentication modes are recommended in a **multi-user
  231. environment** where you want to give users access to their own database and
  232. don't want them to play around with others. Nevertheless be aware that MS
  233. Internet Explorer seems to be really buggy about cookies, at least till version
  234. 6. Even in a **single-user environment**, you might prefer to use :term:`HTTP`
  235. or cookie mode so that your user/password pair are not in clear in the
  236. configuration file.
  237. :term:`HTTP` and cookie authentication
  238. modes are more secure: the MySQL login information does not need to be
  239. set in the phpMyAdmin configuration file (except possibly for the
  240. :config:option:`$cfg['Servers'][$i]['controluser']`).
  241. However, keep in mind that the password travels in plain text, unless
  242. you are using the HTTPS protocol. In cookie mode, the password is
  243. stored, encrypted with the blowfish algorithm, in a temporary cookie.
  244. Then each of the *true* users should be granted a set of privileges
  245. on a set of particular databases. Normally you shouldn't give global
  246. privileges to an ordinary user, unless you understand the impact of those
  247. privileges (for example, you are creating a superuser).
  248. For example, to grant the user *real_user* with all privileges on
  249. the database *user_base*:
  250. .. code-block:: mysql
  251. GRANT ALL PRIVILEGES ON user_base.* TO 'real_user'@localhost IDENTIFIED BY 'real_password';
  252. What the user may now do is controlled entirely by the MySQL user management
  253. system. With HTTP or cookie authentication mode, you don't need to fill the
  254. user/password fields inside the :config:option:`$cfg['Servers']`.
  255. .. index:: pair: HTTP; Authentication mode
  256. HTTP authentication mode
  257. ------------------------
  258. * Uses :term:`HTTP` Basic authentication
  259. method and allows you to log in as any valid MySQL user.
  260. * Is supported with most PHP configurations. For :term:`IIS` (:term:`ISAPI`)
  261. support using :term:`CGI` PHP see :ref:`faq1_32`, for using with Apache
  262. :term:`CGI` see :ref:`faq1_35`.
  263. * See also :ref:`faq4_4` about not using the :term:`.htaccess` mechanism along with
  264. ':term:`HTTP`' authentication mode.
  265. .. index:: pair: Cookie; Authentication mode
  266. .. _cookie:
  267. Cookie authentication mode
  268. --------------------------
  269. * You can use this method as a replacement for the :term:`HTTP` authentication
  270. (for example, if you're running :term:`IIS`).
  271. * Obviously, the user must enable cookies in the browser, but this is
  272. now a requirement for all authentication modes.
  273. * With this mode, the user can truly log out of phpMyAdmin and log
  274. back in with the same username.
  275. * If you want to allow users to enter any hostname to connect (rather than only
  276. servers that are configured in :file:`config.inc.php`),
  277. see the :config:option:`$cfg['AllowArbitraryServer']` directive.
  278. * As mentioned in the :ref:`require` section, having the ``mcrypt`` extension will
  279. speed up access considerably, but is not required.
  280. .. index:: pair: Signon; Authentication mode
  281. Signon authentication mode
  282. --------------------------
  283. * This mode is a convenient way of using credentials from another
  284. application to authenticate to phpMyAdmin.
  285. * The other application has to store login information into session
  286. data.
  287. .. seealso::
  288. :config:option:`$cfg['Servers'][$i]['auth_type']`,
  289. :config:option:`$cfg['Servers'][$i]['SignonSession']`,
  290. :config:option:`$cfg['Servers'][$i]['SignonScript']`,
  291. :config:option:`$cfg['Servers'][$i]['SignonURL']`
  292. .. index:: pair: Config; Authentication mode
  293. Config authentication mode
  294. --------------------------
  295. * This mode is sometimes the less secure one because it requires you to fill the
  296. :config:option:`$cfg['Servers'][$i]['user']` and
  297. :config:option:`$cfg['Servers'][$i]['password']`
  298. fields (and as a result, anyone who can read your :file:`config.inc.php`
  299. can discover your username and password).
  300. * In the :ref:`faqmultiuser` section, there is an entry explaining how
  301. to protect your configuration file.
  302. * For additional security in this mode, you may wish to consider the
  303. Host authentication :config:option:`$cfg['Servers'][$i]['AllowDeny']['order']`
  304. and :config:option:`$cfg['Servers'][$i]['AllowDeny']['rules']` configuration directives.
  305. * Unlike cookie and http, does not require a user to log in when first
  306. loading the phpMyAdmin site. This is by design but could allow any
  307. user to access your installation. Use of some restriction method is
  308. suggested, perhaps a :term:`.htaccess` file with the HTTP-AUTH directive or disallowing
  309. incoming HTTP requests at one’s router or firewall will suffice (both
  310. of which are beyond the scope of this manual but easily searchable
  311. with Google).
  312. .. index:: pair: Swekey; Authentication mode
  313. .. _swekey:
  314. Swekey authentication mode
  315. --------------------------
  316. The Swekey is a low cost authentication USB key that can be used in
  317. web applications. When Swekey authentication is activated, phpMyAdmin
  318. requires the users's Swekey to be plugged before entering the login
  319. page (currently supported for cookie authentication mode only). Swekey
  320. Authentication is disabled by default. To enable it, add the following
  321. line to :file:`config.inc.php`:
  322. .. code-block:: php
  323. $cfg['Servers'][$i]['auth_swekey_config'] = '/etc/swekey.conf';
  324. You then have to create the ``swekey.conf`` file that will associate
  325. each user with their Swekey Id. It is important to place this file
  326. outside of your web server's document root (in the example, it is
  327. located in ``/etc``). A self documented sample file is provided in the
  328. ``examples`` directory. Feel free to use it with your own users'
  329. information. If you want to purchase a Swekey please visit
  330. `http://phpmyadmin.net/auth\_key <http://phpmyadmin.net/auth_key>`_
  331. since this link provides funding for phpMyAdmin.
  332. .. seealso:: :config:option:`$cfg['Servers'][$i]['auth_swekey_config']`
  333. Securing your phpMyAdmin installation
  334. +++++++++++++++++++++++++++++++++++++
  335. The phpMyAdmin team tries hard to make the application secure, however there
  336. are always ways to make your installation more secure:
  337. * remove ``setup`` directory from phpMyAdmin, you will probably not
  338. use it after initial setup
  339. * properly choose authentication method - :ref:`cookie`
  340. is probably the best choice for shared hosting
  341. * in case you don't want all MySQL users to be able to access
  342. phpMyAdmin, you can use :config:option:`$cfg['Servers'][$i]['AllowDeny']['rules']` to limit them
  343. * consider hiding phpMyAdmin behind authentication proxy, so that
  344. MySQL credentials are not all users need to login
  345. * if you are afraid of automated attacks, enabling Captcha by
  346. :config:option:`$cfg['CaptchaLoginPublicKey']` and
  347. :config:option:`$cfg['CaptchaLoginPrivateKey']` might be an option.