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. |
| 23 | To enable the php56-apache2handler, run: |
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. |