I keep most of my Apache/PHP/Percona (MySQL) configuration stuff in a local Git repository so I can track changes and I symlink to those from where they should be so you will see commands such as
sudo ln -s ~/Documents/configs/PHP/fat-tony.local/php55.ini /opt/local/etc/php55/php.ini
If you don’t have a similar setup, just copy your configuration files to where they need to be.
I like to prepend some of the commands with
time
just for curiosity’s sake to see how long it takes.
Go to System Preferences -> Sharing and uncheck the Personal Web sharing. You will never turn Apache on/off here again.
macappstore://itunes.apple.com/app/xcode/id497799835?mt=12
Find the latest version in the Mac Dev Center. (You must have a free Apple Developer account.)
Either launch Xcode via GUI or run
sudo xcodebuild -license
Use the Mac OS X Mavericks Package (.pkg) Installer.
The installer will prepend your $PATH with the necessary /opt/local/bin:/opt/local/sbin:
As of Xcode 4.3 you need to make sure Xcode knows where to look.
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer/
sudo /opt/local/bin/port -v selfupdate
WTF‽ I thought you said this was going to tell me how to install PHP‽
perl5 is a depency of one of curl’s dependencies (curl-ca-bundle) and by default perl 5.12 will be installed, but later when we install percona-tookit we will need perl 5.16 so just go ahead and force perl 5.16 here so you don't end up with both 5.12 and 5.16.
There is no harm in having multiple versions installed, but installing only one will save a little bit of compile time.
time sudo port install perl5.16 perl5 +perl5_16
time sudo port install curl +ssl
Percona Server is an enhanced, drop-in MySQL® replacement and it isn’t controlled by Oracle.
A free open source solution, Percona Server is a MySQL alternative which offers breakthrough performance, scalability, features, and instrumentation. Self-tuning algorithms and support for extremely high-performance hardware make it the clear choice for organizations that demand excellent performance and reliability from their MySQL database server.
time sudo port install apr-util +percona percona +openssl percona-server intltool +perl5_16
Percona explains these best:
Percona Toolkit for MySQL is a collection of advanced command-line tools used by Percona MySQL Support staff to perform a variety of MySQL server and system tasks that are too difficult or complex to perform manually…
time sudo port install p5.16-dbd-mysql +percona percona-toolkit +perl5_16
ZSH
nano ~/.zshrc
or Bash:
nano ~/.bash_profile
Add the following line
export PATH=/opt/local/lib/percona/bin:$PATH
MacPorts’ Percona/MySQL looks for my.cnf
in the standard paths as defined by MySQL
You can put this in the global spot: /etc/my.cnf
or the one specific to this install /opt/local/etc/percona/my.cnf
sudo ln -s ~/Documents/configs/MySQL/fat-tony.local/percona-server.my.cnf /opt/local/etc/percona/my.cnf
If you do not have a
my.cnf
file or don't know where to start, the Percona Configuration Wizard for MySQL will build you a good base. The my.cnf file here is for my development machine which is a MacBook Pro “Core i7” 2.7 15" Retina 2013 with 16GB of RAM.
If this is a fresh Percona/MySQL install and you're not re-using existing data install the default tables
sudo -u _mysql /opt/local/lib/percona/bin/mysql_install_db
This installs and activates a launchd item.
Do not be confused by MacPorts' documentation referring to StartupItems. StartupItems is their term for special scripts that create launchd items I have no idea why they would choose terminology that makes you think it is a 10.4 (pre-launchd) StartupItem (which are deprecated).
sudo port load percona-server
To stop Percona/MySQL use
sudo port unload percona-server
sudo /opt/local/lib/percona/bin/mysql_secure_installation
If you don’t set a root password when it asks you to just ring your call button, and Tommy will come back there and hit you over the head with a tack hammer because you are a retard
sudo /opt/local/lib/percona/bin/mysql_upgrade -uroot -p
time sudo port install apr-util +percona php55 +apache2 php55-apache2handler php55-curl php55-exif php55-ftp php55-gd php55-geoip php55-gettext php55-http php55-iconv php55-imagick php55-imap php55-mailparse php55-mbstring php55-mcrypt php55-mysql +percona php55-openssl php55-pdflib php55-pear php55-posix php55-soap php55-sockets php55-solr php55-ssh2 php55-sqlite php55-xmlrpc php55-xsl php55-zip
If this is your development box also install Xdebug.
time sudo port install php55-xdebug
Please don’t install Xdebug on production machines!
Only really necessary if you are upgrading from an older version of PHP (Hat Tip) but doesn’t hurt to do it anyways.
sudo port select php php55
ZSH
nano ~/.zshrc
or Bash:
nano ~/.bash_profile
Add the following line
export PATH=/opt/local/apache2/bin:$PATH
sudo /opt/local/apache2/bin/apxs -a -e -n php5 /opt/local/apache2/modules/mod_php55.so
sudo ln -s ~/Documents/configs/PHP/fat-tony.local/php55.ini /opt/local/etc/php55/php.ini
NOTE: If you are also installing Percona probably need to update the
mysql.sock
paths in yourphp.ini
to reflect/opt/local/var/run/percona/mysqld.sock
. There are 3 possible places you may need to set this.
- mysql.default_socket
- mysqli.default_socket
- pdo_mysql.default_socket
Install Cronolog to rotate your log files
If you want to split your log files up into usable chunks.
time sudo port install cronolog
If you’re using the free GeoLite database PHP will probably not find it in the default install location.
sudo ln -s /opt/local/share/GeoIP/GeoIP.dat /opt/local/share/GeoIP/GeoIPCity.dat
sudo port load apache2
To stop Apache use
sudo port unload apache2
autojump is a faster way to navigate your filesystem. It works by maintaining a database of the directories you use the most from the command line. Directories must be visited first before they can be jumped to.
time sudo port install autojump
First we will install rvm for Ruby management.
curl -L https://get.rvm.io | bash
Now install Ruby. Change the version if necessary, but I chose ruby-2.0.0-p247, which is the same one that Apple installs by default in Mavericks.
rvm install ruby-2.0.0-p247
I received an error
Updating certificates in '/etc/openssl/cert.pem'. mkdir: /etc/openssl: Permission denied
but chose to ignore. Feel free to provide some info in the comments
Tell rvm
we want to use the ruby we just installed
rvm --default use ruby 2.0.0
I have some projects that are still using Capistrano 2 and some that are using the newer Capistrano 3 so I create a gemset for each. Your don’t need to make a gemset for your capistrano if you only use one version, but I only use Ruby for deploying and I like that having them gemsets makes it clear to me which version I am using. You could just install Capistrano in your default gemset if you like.
rvm gemset create capistrano3
rvm gemset create capistrano2
Finally we can actually install Capistrano. Also include @spike666’s Capistrano::Mailgun so you can send emails upon deploy.
Start with Capistrano 3. Also make this the default gemset.
rvm gemset use capistrano3 --default
gem install capistrano capistrano-mailgun
Now Capistrano 2 if you need it for legacy projects.
rvm gemset use capistrano2
gem install capistrano capistrano-mailgun
Thanks for this- great walk-through.
After getting this set up, I was having issues running .php scripts on my localhost. Basically, if I went to localhost/test.php, where test.php was a file that I added to /opt/local/apache2/htdocs, apache was just returning the code from the .php script, not actually rendering it.
To fix this, I added this to /opt/local/apache2/conf/httpd.conf: