12.22.2024

01.22.2010

PHP 5 + Apache 2 + MySQL 5 on OS X via MacPorts

Filed under: note to self,server @ 14:28
# Displays all files in Finder.  Optional: personal preference.
$ defaults write com.apple.Finder AppleShowAllFiles YES
# Relaunch Finder

# Update MacPorts
$ sudo port selfupdate
$ sudo port -u upgrade outdated

# Install MySQL
$ sudo port install mysql5-server
$ sudo port load mysql5-server
$ sudo -u _mysql mysql_install_db5
$ sudo mysqld_safe5 &
$ sudo /opt/local/lib/mysql5/bin/mysql_secure_installation

# Install Apache, PHP (with PEAR), PHP MySQL bindings
$ sudo port install apache2
$ sudo port install php5 +apache2 +pear
$ sudo port install php5-mysql

# Configure Apache
# The following line may not be necessary
? sudo cp /opt/local/apache2/conf/httpd.conf.sample  /opt/local/apache2/conf/httpd.conf
$ cd /opt/local/apache2/modules
$ sudo /opt/local/apache2/bin/apxs -a -e -n "php5" libphp5.so
$ sudo nano /opt/local/apache2/conf/httpd.conf
# Set DirectoryIndex to:
# DirectoryIndex index.html index.php
#
# Change DocumentRoot to whatever (e.g. /Users/michael/Sites
#
# Change <directory "{old DocumentRoot}"> to <directory "{new DocumentRoot}">
#
# In that <directory "{new DocumentRoot}"> section change to the following.
# Options Indexes FollowSymLinks MultiViews
# AllowOverride All
#
# In <ifmodule mime_module> section, add the following two lines
# AddType application/x-httpd-php .php
# AddType application/x-httpd-php-source .phps
#
$ sudo port load apache2

# Configure PHP
$ sudo cp /opt/local/etc/php5/php.ini-development /opt/local/etc/php5/php.ini
$ sudo nano /opt/local/etc/php5/php.ini
# set mysql.default_socket, mysqli.default_socket and pdo_mysql.default_socket to
# /opt/local/var/run/mysql5/mysqld.sock

# Start Apache
# Make sure System Preferences → Sharing → Web Sharing is turned off. 
$ sudo /opt/local/etc/LaunchDaemons/org.macports.apache2/apache2.wrapper start
# You may get a window asking if httpd can accept incoming requests.  Approve it.

# Add DB and tables to MySQL for easy WordPress install
$ mysql5 -u root -p
> CREATE DATABASE database_name_here;
> GRANT ALL PRIVILEGES ON database_name_here.* TO "username_here"@"localhost" IDENTIFIED BY "password_here";
> FLUSH PRIVILEGES;
> EXIT

# Install and Configure phpMyAdmin (will need to restart Apache when done)
$ sudo port install phpmyadmin
$ sudo nano /opt/local/apache2/conf/httpd.conf
# Add section
# <Directory "/opt/local/www/phpmyadmin/">
#     Options Indexes MultiViews
#     AllowOverride None
#     Order allow,deny                                                                 
#     Allow from all
# </Directory>
#
# In <IfModule alias_module> section add the following
# Alias /phpMyAdmin "/opt/local/www/phpmyadmin"

$ sudo nano /opt/local/www/phpmyadmin/config.inc.php
# See http://www.phpmyadmin.net/documentation/Documentation.html#config
# Fill in $cfg['blowfish_secret']
# Set $cfg['Servers'][$i]['auth_type'] = 'config';
# Add $cfg['Servers'][$i]['user'] = 'root';
# Add $cfg['Servers'][$i]['password'] = '{root password}';


$ sudo /opt/local/apache2/bin/apachectl {start|restart|graceful|graceful-stop|stop}
$ sudo /opt/local/share/mysql5/mysql/mysql.server {start|stop|restart|reload|force-reload|status}

7 Comments

  1.  
    Daniel Howard 02.14.2010 @ 15:28

    If you’re going to do much dev work, this is a lot easier to pull off on Linux within a Virtual Machine.

    -danny

  2.  
    westi 02.18.2010 @ 13:27

    Some updated needed it seems:

    The +mysqlnd variant is obsolete. Please install the php5-mysql port instead.

    •  
      MDA 02.18.2010 @ 13:49

      Thanks – I wrote up these notes after doing things out of order.

      I edited the post to reflect my guess at what should work :)

  3.  
    Lenin 08.15.2010 @ 10:54

    Great post. Saved my day. I also recommend everyone to try this.

  4.  
    Mike 09.30.2010 @ 09:45

    Working like a charm so far, thanks. The phpmyadmin documentation link is broken. Here’s the new one:
    http://www.phpmyadmin.net/documentation/Documentation.html#config

    •  
      MDA 12.12.2010 @ 19:28

      Thanks! Updated.

© mdawaffe (Michael D Adams) - Powered by WordPress - Full Credits