| 88 | '''''Note:''''' When you upgrade your Apache installation (e.g., `sudo port upgrade apache2`), be aware that the upgrade will not affect your `http.conf` file, but '''it will overwrite the other configuration files''', such as the `httpd-userdir.conf` file. Therefore, if you've made any changes to those files (e.g., activating User web pages), you will need to save your `httpd-userdir.conf` file before upgrading and then reapply your changes after the upgrade. However, it would probably be a good idea to save your `http.conf` file too, just to be safe. |
| 89 | |
| 90 | === Step 3: Install MySQL === |
| 91 | |
| 92 | {{{ |
| 93 | sudo port install mysql5 +server |
| 94 | }}} |
| 95 | |
| 96 | Activate your MySQL server installation so that it autostarts when you boot your machine: |
| 97 | |
| 98 | {{{ |
| 99 | sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist |
| 100 | }}} |
| 101 | |
| 102 | Set up the main database |
| 103 | |
| 104 | {{{ |
| 105 | sudo mysql5 mysql_install_db5 |
| 106 | sudo chown -R mysql:mysql /opt/local/var/db/mysql5/ |
| 107 | sudo chown -R mysql:mysql /opt/local/var/run/mysqld5/ |
| 108 | sudo chown -R mysql:mysql /opt/local/var/log/mysql5/ |
| 109 | }}} |
| 110 | |
| 111 | ''If that doesn't work try this:'' |
| 112 | {{{ |
| 113 | sudo mysql_install_db5 |
| 114 | sudo chown -R mysql:mysql /opt/local/var/db/mysql5/ |
| 115 | sudo chown -R mysql:mysql /opt/local/var/run/mysqld5/ |
| 116 | }}} |
| 117 | |
| 118 | Start the MySQL daemon |
| 119 | |
| 120 | {{{ |
| 121 | sudo /opt/local/bin/mysqld_safe5 & |
| 122 | }}} |
| 123 | |
| 124 | and then verify that it's running |
| 125 | |
| 126 | {{{ |
| 127 | ps –ax | grep mysql |
| 128 | }}} |
| 129 | |
| 130 | Set the MySQL `root` password (it's currently empty) |
| 131 | |
| 132 | {{{ |
| 133 | mysqladmin5 –u root –p password <new-password> |
| 134 | }}} |
| 135 | |
| 136 | where `<new-password>` is your new desired root password. |
| 137 | |
| 138 | Test everything by logging in to the server. |
| 139 | |
| 140 | {{{ |
| 141 | mysql5 -u root -p |
| 142 | }}} |
| 143 | |
| 144 | Once you're logged in, simply exit the session |
| 145 | |
| 146 | {{{ |
| 147 | mysql> exit |
| 148 | }}} |
| 149 | |
| 150 | As a last test, reboot your machine and then run |
| 151 | |
| 152 | {{{ |
| 153 | ps –ax | grep mysql |
| 154 | }}} |
| 155 | |
| 156 | again to verify that the daemon is still active. |
| 157 | |
| 158 | === Step 4: Install PHP === |
| 159 | |
| 160 | '''Note: Currently, the PHP5 installer uses wget to install the PEAR environment, but the installer does not list wget as a dependent component. So, the installation will fail during the staging operations if you do not manually install wget first.''' |
| 161 | |
| 162 | {{{ |
| 163 | sudo port install wget |
| 164 | sudo port install php5 +apache2 +mysql5 |
| 165 | }}} |
| 166 | |
| 167 | Register PHP with Apache |
| 168 | |
| 169 | {{{ |
| 170 | cd /opt/local/apache2/modules |
| 171 | sudo /opt/local/apache2/bin/apxs -a -e -n "php5" libphp5.so |
| 172 | }}} |
| 173 | |
| 174 | Update Apache's `httpd.conf` file to enhance the "DirectoryIndex" directive to include additional "index" files: |
| 175 | |
| 176 | {{{ |
| 177 | DirectoryIndex index.html index.cgi index.php |
| 178 | }}} |
| 179 | |
| 180 | Also, at the end of the `httpd.conf` file, add the following lines so that Apache includes the mod_php "AddType" configurations |
| 181 | |
| 182 | {{{ |
| 183 | # |
| 184 | # Include PHP configurations |
| 185 | # |
| 186 | Include conf/extras-conf/mod_php.conf |
| 187 | }}} |
| 188 | |
| 189 | You may also need to load the PHP module '''before''' including `mod_php.conf` as described above: |
| 190 | |
| 191 | {{{ |
| 192 | # Load the PHP module |
| 193 | LoadModule php5_module modules/libphp5.so |
| 194 | }}} |
| 195 | |
| 196 | Set up your PHP configuration files |
| 197 | |
| 198 | {{{ |
| 199 | cd /opt/local/etc |
| 200 | sudo cp php.ini-dist php.ini |
| 201 | sudo cp pear.conf.sample pear.conf |
| 202 | }}} |
| 203 | |
| 204 | Restart Apache so that your changes take effect |
| 205 | |
| 206 | {{{ |
| 207 | cd /opt/local/apache2/bin/ |
| 208 | sudo ./apachectl -k restart |
| 209 | }}} |
| 210 | |
| 211 | Create a file named `phpinfo.php` that contains the following three lines |
| 212 | |
| 213 | {{{ |
| 214 | !#php |
| 215 | <?php |
| 216 | phpinfo(); |
| 217 | ?> |
| 218 | }}} |
| 219 | |
| 220 | 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.2.6 as of this writing) and that MySQL support is active (you may want to search the page for "`mysql`"). |
| 221 | |
| 222 | As a last check, reboot and verify that everything has autostarted and is running (i.e., repeat the above tests). |
| 223 | |
| 224 | === Step 5: Install phpMyAdmin (optional) === |
| 225 | |
| 226 | Use MacPorts to install the latest version of `phpMyAdmin`. |
| 227 | |
| 228 | {{{ |
| 229 | sudo port install phpmyadmin |
| 230 | }}} |
| 231 | |
| 232 | Update Apache's `httpd.conf` file to find `phpmyadmin`. First add the following lines to the end of the file: |
| 233 | |
| 234 | {{{ |
| 235 | # Local access to phpmyadmin installation |
| 236 | Include conf/extra/httpd-phpmyadmin.conf |
| 237 | }}} |
| 238 | |
| 239 | and then create a file `/opt/local/apache2/conf/extra/httpd-phpmyadmin.conf` containing this text: |
| 240 | |
| 241 | {{{ |
| 242 | AliasMatch ^/phpmyadmin(?:/)?(/.*)?$ "/opt/local/www/data/phpmyadmin$1" |
| 243 | |
| 244 | <Directory "/opt/local/www/data/phpmyadmin"> |
| 245 | Options -Indexes |
| 246 | AllowOverride None |
| 247 | Order allow,deny |
| 248 | Allow from all |
| 249 | |
| 250 | LanguagePriority en de es fr ja ko pt-br ru |
| 251 | ForceLanguagePriority Prefer Fallback |
| 252 | </Directory> |
| 253 | }}} |
| 254 | |
| 255 | Finally, you need to set up the `phpMyAdmin` configuration to access mySQL. First, set up the config file: |
| 256 | |
| 257 | {{{ |
| 258 | cd /opt/local/www/data/phpmyadmin/ |
| 259 | cp libraries/config.default.php ./config.inc.php |
| 260 | }}} |
| 261 | |
| 262 | This will create a file `config.inc.php` in the `phpMyAdmin` folder. Edit that file, and locate the lines: |
| 263 | |
| 264 | {{{ |
| 265 | $cfg['Servers'][$i]['auth_type'] = 'config'; // Authentication method (config, http or cookie based)? |
| 266 | $cfg['Servers'][$i]['user'] = 'root'; // MySQL user |
| 267 | $cfg['Servers'][$i]['password'] = ; // MySQL password (only needed |
| 268 | // with 'config' auth_type) |
| 269 | }}} |
| 270 | |
| 271 | 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. |
| 272 | |
| 273 | To check your phpMyAdmin installation, point your browser to http://localhost/phpmyadmin (or http://localhost/~username/phpmyadmin if applicable) and verify that phpMyAdmin loads and can access your database (by providing a username and password, depending on the authentication method you selected). |
| 274 | |