Changes between Version 84 and Version 85 of howto/MAMP


Ignore:
Timestamp:
Dec 29, 2014, 4:57:49 AM (10 years ago)
Author:
magill@…
Comment:

reorganized MAMP page

Legend:

Unmodified
Added
Removed
Modified
  • howto/MAMP

    v84 v85  
    66
    77 * Apache 2.2.* - See: [[howto/Apache2]] for instructions on installation of Apache2
    8  * MySQL 5.6.*
    9  * PHP 5.4.*
     8 * MySQL 5.6.* - See: [[howto/MySQL]] for instructions on installation ofMySQL
     9 * PHP 5.6.* - See: [[howto/PhP]] for instructions on instalation of PhP
    1010
    1111
     12Simplified sequence:
    1213
     14Install Apache
     15Install MySQL
     16Install PhP
     17Modify Apache Configuration to support MySQL and PhP.
    1318
    14 = Step 3: Install MySQL = #mysql
     19= Integrate PhP with Apache =
    1520
    16 If you merely want to access a MySQL server running on another computer, skip to step 4. If you want to run a MySQL server on this computer, install MySQL like this:
    17 {{{
    18 sudo port install mysql51-server
    19 }}}
    20 mysql51-server is used in this example because it is the closest to the port that was previously used in this example, which was mysql5-server. However, there are newer versions of mysql in MacPorts that may be worth considering instead. The only reason for not using any of these newer versions in this example is because that would probably require making even more changes than the move to mysql51 required. If you are personally moving from the mysql5 port to the mysql51 port, you may want to add the `+openssl` variant, as the openssl support that had previously been available by default in the mysql5 port has been moved to a variant in the mysql51 port. Even though the mysql51-server port does not have this variant itself, if you supply the variant with your invocation of `port`, it will still get passed down to the mysql51 port, because it will be installed as a dependency. Also, mysql51 now uses the `port select` mechanism, so you will have to run one of the following to get the mysql commands in your PATH: either:
    21 {{{
    22 sudo port select mysql mysql51
    23 }}}
    24 or:
    25 {{{
    26 export PATH=$PATH:/opt/local/lib/mysql51/bin
    27 }}}
    28 Once you have done at least one of the two previous commands, then how to set up the main database depends on the version of OS X you're using.
     21If this is your first install, you need to enable php56-apache2handler in your web server.
    2922
    30 Set up the main database like this:
    31 {{{
    32 sudo -u _mysql mysql_install_db5
    33 sudo chown -R _mysql:_mysql /opt/local/var/db/mysql51/
    34 sudo chown -R _mysql:_mysql /opt/local/var/run/mysql51/
    35 sudo chown -R _mysql:_mysql /opt/local/var/log/mysql51/
    36 }}}
    37 
    38   ''If that fails to work, then try this:''
    39   {{{
    40 sudo mysql_install_db5
    41 sudo chown -R _mysql:_mysql /opt/local/var/db/mysql51/
    42 sudo chown -R _mysql:_mysql /opt/local/var/run/mysql51/
    43   }}}
    44 
    45 However, for '''OS X 10.4 and below''', up the main database like this:
    46 
    47 {{{
    48 sudo -u mysql mysql_install_db5
    49 sudo chown -R mysql:mysql /opt/local/var/db/mysql51/
    50 sudo chown -R mysql:mysql /opt/local/var/run/mysql51/
    51 sudo chown -R mysql:mysql /opt/local/var/log/mysql51/
    52 }}}
    53 
    54   ''If that fails to work, then try this:''
    55   {{{
    56 sudo mysql_install_db5
    57 sudo chown -R mysql:mysql /opt/local/var/db/mysql51/
    58 sudo chown -R mysql:mysql /opt/local/var/run/mysql51/
    59   }}}
    60 
    61 Activate your MySQL server installation so that it autostarts when you boot your machine:
    62 {{{
    63 sudo port load mysql51-server
    64 }}}
    65 
    66 and then verify that it is running:
    67 {{{
    68 ps -ax | grep mysql
    69 }}}
    70 
    71 Set the MySQL `root` password (it should currently be empty, see also the security option below):
    72 {{{
    73 mysqladmin5 -u root -p password <new-password>
    74 }}}
    75 
    76 where `<new-password>` is your new desired root password. You will be prompted for your existing password ("`Enter password:`"); since it is empty, just press Return.
    77 
    78 Test everything by logging in to the server.
    79 {{{
    80 mysql5 -u root -p
    81 }}}
    82 
    83 Once you are logged in, simply exit the session like this:
    84 {{{
    85 mysql> exit ;
    86 }}}
    87 
    88 If desired, reboot your machine and then run:
    89 {{{
    90 ps -ax | grep mysql
    91 }}}
    92 again to verify that the daemon is again running.
    93 
    94 
    95 == Optional database upgrade == #mysql_upgrade
    96 
    97 If the database exists from a previous installation, you may need to upgrade.
    98 
    99 {{{
    100 man mysql_upgrade
    101 sudo /opt/local/etc/LaunchDaemons/org.macports.mysql5/mysql5.wrapper restart
    102 sudo /opt/local/lib/mysql5/bin/mysql_upgrade -u root -p
    103 sudo /opt/local/etc/LaunchDaemons/org.macports.mysql5/mysql5.wrapper restart
    104 }}}
    105 (note: these instructions might not be applicable any longer...)
    106 
    107 
    108 == Optional security configuration == #mysql_security
    109 
    110 There is an interactive program to secure a MySQL installation.
    111 
    112 {{{
    113 $ man mysql_secure_installation
    114 $ /opt/local/bin/mysql_secure_installation5
    115 }}}
    116 
    117 The following is a more detailed process that may achieve the same results as the interactive program.  Place the following into {{{mysql_security.sql}}} and replace the {{{'MyNewPass'}}} with your root password.  Note that the SQL will remove all access for root from any location other than 'localhost'.  You might like to keep this SQL file - all the lines beginning with '--' are doc-comments about how to use it.
    118 
    119 {{{
    120 -- HOW TO USE THIS FILE (with a MacPorts installation):
    121 -- $ sudo /opt/local/etc/LaunchDaemons/org.macports.mysql5/mysql5.wrapper stop
    122 -- $ sudo mysqld_safe5 --init-file=mysql_security.sql &
    123 -- The init will terminate if there are any errors in the init file.
    124 -- Wait a bit to be sure the server is running.
    125 -- If it's running, then shutdown the server (root password required):
    126 -- $ /opt/local/bin/mysqladmin5 -u root -p shutdown
    127 -- Check that everything worked.  There may be an ERROR if the test database
    128 -- doesn't exist.  Otherwise there should be no errors in the file reported by
    129 -- 'mysqld_safe Logging to ..." during the mysql_safe5 startup from above:
    130 -- $ sudo tail -n 20 /opt/local/var/db/mysql5/*.err
    131 
    132 UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root';
    133 DELETE FROM mysql.user WHERE User='root' AND Host!='localhost';
    134 DELETE FROM mysql.user WHERE User='';
    135 FLUSH PRIVILEGES;
    136 DROP DATABASE test;
    137 DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%';
    138 }}}
    139 
    140 The server startup options {{{--skip-networking}}} and {{{--skip-grant-tables}}} may be useful while implementing security.  See also http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html#resetting-permissions-unix
    141 
    142 
    143 
    144 = Step 4: Install PHP = #php
    145 
    146 {{{
    147 sudo port install php54-apache2handler
    148 sudo port install php54-mysql
    149 }}}
    150 
    151 
    152   '''''Note:''''' the php54 port contains the core PHP features, but there are many optional features available in separate ports, some of which you may want to install as well (such as MySQL support via the php54-mysql port). Use `port search php54` to see all the ports that are available.
     23To enable the php56-apache2handler, run:
    15324
    15425Register PHP with Apache
     
    15627{{{
    15728cd /opt/local/apache2/modules
    158 sudo /opt/local/apache2/bin/apxs -a -e -n "php5" mod_php54.so
     29sudo /opt/local/apache2/bin/apxs -a -e -n "php5" mod_php56.so
    15930}}}
     31This should return the message:
     32 ''[activating module `php5' in /opt/local/apache2/conf/httpd.conf]''
    16033
    16134
    162 Update Apache’s `httpd.conf` file to enhance the "DirectoryIndex" directive to include additional "index" files. Search for:
     35Update Apache’s `httpd.conf` - ''/opt/local/apache2/conf/httpd.conf'' - file to enhance the "DirectoryIndex" directive to include additional "index" files. Search for:
    16336
    16437{{{
     
    17245}}}
    17346
    174 Also, at the end of the `httpd.conf` file, add the following lines so that Apache includes the mod_php "AddType" configurations
     47Verify that at the end of the `httpd.conf` file the following lines exist so that Apache includes the mod_php "AddType" configurations
    17548
    17649{{{
    177 #
    17850# Include PHP configurations
    179 #
    180 Include conf/extra/mod_php54.conf
     51Include conf/extra/mod_php56.conf
     52}}}
     53Verify that in the Dynamic Shared Object (DSO) Support  section the following have been added.
     54{{{
     55# Load the PHP module
     56LoadModule php5_module modules/mod_php56.so
    18157}}}
    18258
    183 You may also need to load the PHP module '''before''' including `mod_php.conf` as described above:
     59Note: either of the above two edits are only required if the lines are not present in the httpd.conf file, as the apxs command (executed above) will add those for you.
    18460
    185 {{{
    186 # Load the PHP module
    187 LoadModule php5_module modules/mod_php54.so
    188 }}}
    189 
    190 Notice either of the above commands are only required if not present in the httpd.conf file, as the apxs command (executed above) will write those for you.
    191 
    192 Set up your PHP configuration files
    193 
    194 {{{
    195 cd /opt/local/etc/php5
    196 sudo cp php.ini-development php.ini
    197 }}}
    198 or (depending on your needs)
    199 {{{
    200 cd /opt/local/etc/php5
    201 sudo cp php.ini-production php.ini
    202 }}}
    203 
     61= Step 3: MySqL setup for PhP =
    20462Setup the MySQL default socket to use the MacPorts configuration (/opt/local/var/run/mysql5/mysqld.sock)
    20563
     
    22987
    23088{{{
    231 sudo /opt/local/apache2/bin/apachectl -k restart
     89sudo port unload apache2
     90sudo port load apache2
    23291}}}
    23392
    234   '''''Note:''''' Make sure to use the full path as shown here, as `apachectl` in your PATH refers to the system provided Apache!
     93= Step 4: Craete phpinfo =
     94This is used to test the configuration after you have integrated it with Apache and MySQL.
    23595
    23696Create a file named `phpinfo.php` that contains the following three lines
     
    241101?>
    242102}}}
     103and place it in your Apache "`DocumentRoot`" directory (nominally: "`/opt/local/apache2/htdocs`") or your own user "`Sites`" directory if you activated user directories as specified above.
     104Point your browser to http://localhost/phpinfo.php (or http://localhost/~username/phpinfo.php as applicable) and verify that the correct version of PHP is active (v5.6.4 as of this writing) and that MySQL support is active (you may want to search the page for "`mysql`"). \\
     105Note that this file needs to be readable and executable.
    243106
    244 and place it in your Apache "`DocumentRoot`" directory (should be "`/opt/local/apache2/htdocs`") or your own user "`Sites`" directory if you activated user directories as specified above. Point your browser to http://localhost/phpinfo.php (or http://localhost/~username/phpinfo.php if applicable) and verify that the correct version of PHP is active (v5.3.0 as of this writing) and that MySQL support is active (you may want to search the page for "`mysql`").
    245 
    246 If by some reason the server still doesn't interpret PHP files (your web client tries to download them) it means the PHP configurations, as described above, are not taking effect and in that case you should open the httpd.conf file once again and search for the block
    247 
    248 {{{
    249 <IfModule mime_module>
    250 }}}
    251 
    252 And then add before the end
    253 
    254 {{{
    255 AddType application/x-httpd-php .php
    256 AddType application/x-httpd-php-source .phps
    257 }}}
    258 
    259 Then restart the server.
    260 
    261 As a last check, reboot and verify that everything has autostarted and is running (i.e., repeat the above tests).
    262 
    263 = Step 5: Install phpMyAdmin (optional) = #phpmyadmin
    264 
    265 Use MacPorts to install the latest version of `phpMyAdmin`.
    266 
    267 {{{
    268 sudo port install phpmyadmin
    269 }}}
    270 
    271 Update Apache’s `httpd.conf` file to find `phpmyadmin`. First add the following lines to the end of the file:
    272 
    273 {{{
    274 # Local access to phpmyadmin installation
    275 Include conf/extra/httpd-phpmyadmin.conf
    276 }}}
    277 
    278 and then create a file `/opt/local/apache2/conf/extra/httpd-phpmyadmin.conf` containing this text:
    279 
    280 {{{
    281 AliasMatch ^/phpmyadmin(?:/)?(/.*)?$ "/opt/local/www/phpmyadmin$1"
    282 
    283 <Directory "/opt/local/www/phpmyadmin">
    284   Options -Indexes
    285   AllowOverride None
    286   Order allow,deny
    287   Allow from all
    288  
    289   LanguagePriority en de es fr ja ko pt-br ru
    290   ForceLanguagePriority Prefer Fallback
    291 </Directory>
    292 }}}
    293 
    294 Restart Apache so that your changes take effect
    295 
    296 {{{
    297 sudo /opt/local/apache2/bin/apachectl -k restart
    298 }}}
    299 
    300   '''''Note:''''' Make sure to use the full path as shown here, as `apachectl` in your PATH refers to the system provided Apache!
    301 
    302 Finally, you need to set up the `phpMyAdmin` configuration to access mySQL. First, set up the config file:
    303 
    304 {{{
    305 cd /opt/local/www/phpmyadmin/
    306 sudo cp config.sample.inc.php config.inc.php
    307 }}}
    308 
    309 This will create a file `config.inc.php` in the `phpMyAdmin` folder. Edit that file, and locate the lines:
    310 
    311 {{{
    312 $cfg['Servers'][$i]['auth_type']     = 'config';    // Authentication method (config, http or cookie based)?
    313 $cfg['Servers'][$i]['user']          = 'root';      // MySQL user
    314 $cfg['Servers'][$i]['password']      = '';          // MySQL password (only needed
    315                                                     // with 'config' auth_type)
    316 }}}
    317 
    318 Where ' ' is an empty password; fill it with your MySQL root password. You can either change the 'auth_type' from 'config' to 'cookie' or 'httpd', or alternatively provide the password you selected for the root user in the 'password' option.
    319 
    320 There is also an interactive setup, see http://www.phpmyadmin.net/documentation/#setup_script and the demo at http://www.phpmyadmin.net/documentation/setup/
    321 
    322 To check your phpMyAdmin installation, point your browser to http://localhost/phpmyadmin and verify that phpMyAdmin loads and can access your database (by providing a username and password, depending on the authentication method you selected).
    323 
    324 
    325 == Optional pmadb == #phpMyAdmin_pmadb
    326 
    327 For additional features provided by pmadb (http://wiki.phpmyadmin.net/pma/pmadb), run
    328 {{{
    329 mysql5 -u root -p < /opt/local/www/phpmyadmin/examples/create_tables.sql
    330 }}}
    331 
    332 Then run this SQL to setup the pma 'controluser' (change the 'pmapass' to your password).
    333 {{{
    334 -- HOW TO USE THIS FILE (with MacPorts installation)
    335 -- mysql5 -u root -p < /opt/local/www/phpmyadmin/examples/create_tables.sql
    336 -- mysql5 -u root -p < mysql_phpMyAdmin_pmaSetup.sql
    337 
    338 CREATE USER 'pma'@'localhost' IDENTIFIED BY 'pmapass';
    339 
    340 GRANT USAGE ON mysql.* TO 'pma'@'localhost' IDENTIFIED BY 'pmapass';
    341 GRANT SELECT (
    342     Host, User, Select_priv, Insert_priv, Update_priv, Delete_priv,
    343     Create_priv, Drop_priv, Reload_priv, Shutdown_priv, Process_priv,
    344     File_priv, Grant_priv, References_priv, Index_priv, Alter_priv,
    345     Show_db_priv, Super_priv, Create_tmp_table_priv, Lock_tables_priv,
    346     Execute_priv, Repl_slave_priv, Repl_client_priv
    347     ) ON mysql.user TO 'pma'@'localhost';
    348 GRANT SELECT ON mysql.db TO 'pma'@'localhost';
    349 GRANT SELECT ON mysql.host TO 'pma'@'localhost';
    350 GRANT SELECT (Host, Db, User, Table_name, Table_priv, Column_priv)
    351     ON mysql.tables_priv TO 'pma'@'localhost';
    352 
    353 -- Privileges
    354 GRANT SELECT, INSERT, DELETE, UPDATE ON `phpmyadmin`.* TO 'pma'@localhost;
    355 }}}
    356 
    357 Finally, edit the config file, at {{{/opt/local/www/phpmyadmin/config.inc.php}}}, so it's like this:
    358 {{{
    359 /* User for advanced features */
    360 $cfg['Servers'][$i]['controluser'] = 'pma';
    361 $cfg['Servers'][$i]['controlpass'] = 'pmapass';
    362 /* Advanced phpMyAdmin features */
    363 $cfg['Servers'][$i]['pmadb'] = 'phpmyadmin';
    364 $cfg['Servers'][$i]['bookmarktable'] = 'pma__bookmark';
    365 $cfg['Servers'][$i]['relation'] = 'pma__relation';
    366 $cfg['Servers'][$i]['table_info'] = 'pma__table_info';
    367 $cfg['Servers'][$i]['table_coords'] = 'pma__table_coords';
    368 $cfg['Servers'][$i]['pdf_pages'] = 'pma__pdf_pages';
    369 $cfg['Servers'][$i]['column_info'] = 'pma__column_info';
    370 $cfg['Servers'][$i]['history'] = 'pma__history';
    371 $cfg['Servers'][$i]['designer_coords'] = 'pma__designer_coords';
    372 }}}
     107* Remember to return to [[howto/PhP]] to complete the PhP installation.
    373108
    374109