Skip to content

Instantly share code, notes, and snippets.

@paill
Last active December 29, 2023 03:11
Show Gist options
  • Select an option

  • Save paill/ffd0ec0faa0eaf66f5c0 to your computer and use it in GitHub Desktop.

Select an option

Save paill/ffd0ec0faa0eaf66f5c0 to your computer and use it in GitHub Desktop.
How to setup your Mac and Development Environment for OS-X Yosemite

Setting up your Mac

Installing

Homebrew

  1. First, to check if Homebrew is already installed, type the following into the Terminal:

     brew --version
    
  2. If brew is installed, skip to step 6; otherwise continue following the install instructions.

  3. If it is not installed, launch Xcode and if prompted, agree to the Terms and Conditions. Then, open the Terminal and install the Command Line tools with this command:

     xcode-select --install
    
  4. You can go to the Homebrew site for more information, but to install Homebrew, run this command:

     ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    
  5. Once it has finished, ensure brew installed correctly by typing:

     brew --version
    
  6. Run the following command to ensure everything is configured properly:

     brew doctor
    
  7. Run the following command to ensure brew is up to date:

     brew update
    

Anaconda

  1. First, check if Anaconda is already install by running the command:

     conda --version
    
  2. If installed, skip to step X; otherwise continue.

  3. Download Anaconda. Choose the Anaconda Graphical Installer for Python 2.7 for Mac OS X.

  4. Open the installer and follow the directions.

  5. To make sure Anaconda properly installed, open a Terminal window and run:

     conda --version
    
  6. Make sure Anaconda is up to date by running:

     conda update anaconda
    

Git

  1. First, check if git is already install by running the command:

     git --version
    
  2. If already installed, move onto the next section; otherwise, continue.

  3. We will be using Homebrew to install git. Run the following commands in Terminal:

     brew update
     brew install git
     brew doctor
    

SQLite

  1. First, check if SQLite is already install by running the command:

     sqlite3 -version
    
  2. If already installed, move onto the next section; otherwise, continue.

  3. We will be using Homebrew to install SQLite. Run the following commands in Terminal:

     brew update
     brew install sqlite
     brew doctor
    

Sequel Pro

  1. First, go to Applications, and see if Sequel Pro is already installed.

  2. If already installed, move onto the next section; otherwise, continue.

  3. Download Sequel Pro and install.

  4. When finished installing, be sure to unmount the DMG file from your computer.

PyCharm

Note: PyCharm is merely a suggestion for what to use when working in Python.

  1. As a student, you qualify for a free license for PyCharm through JetBrains. Go to JetBrains and click on apply.

  2. Once you have applied and created an account through JetBrains, download the professional version of PyCharm.

  3. PyCharm requires Java which can be downloaded here. You can also install using Homebrew.

  4. When PyCharm asks for a license, provide your account login information for your JetBrains account. Your license must be renewed yearly.

Other IDE/TextEditor

You may want to download/try out other text editors or IDEs that fit your working style.

  • Spyder comes packaged with Anaconda. It is a Python IDE. To run it from the Terminal:

      /Users/<username>/anaconda/bin/spyder ; exit;
    
  • Komodo Edit is a fairly simple text-editor.

  • You could also try out PhpStorm and WebStorm also through JetBrains.

Setting Up a Local Development Environment

This a step by step guide on setting up the local web development environment on your Mac. The steps I include are taken from this tutorial. However, the tutorial also includes extra details that are not needed, so I include the necessary steps below.

Apache

Apache is a web server, and we will be using it to do web development locally. Apache 2.4 is pre-installed on OS-X Yosemite.

  • To start up the web server, open Terminal and run:

      sudo apachectl start
    
  • To stop the web server, open Terminal and run:

      sudo apachectl stop
    
  • To restart the web servera after having made configuration changes, open Terminal and run:

      sudo apachectl restart
    
  • To make sure Apache is working, start Apache , and then try to reach your server in a browser by pointing it at your localhost, you should see a simple header that says It works!.

  • Note: If you cannot reach your site via http://localhost you might need to add an alias in your /etc/hosts file: 127.0.0.1 localhost. It should exist by default.

Configuring Apache

We are going to change the document root for Apache, so it points to a folder in our home directory.

  1. To do so, we need to edit Apache's configuration file. You can use whatever command line editor you are comfortable with, just realize this is a root-owned folder so you will need to use sudo to be able to edit and save the file. I prefer to use vim:

     sudo vim /etc/apache2/httpd.conf
    
  2. Search for the term DocumentRoot, and you should see the line:

     DocumentRoot "/Library/WebServer/Documents"
    
  3. Change that line to the directory you want to point to on your account where <username> is your username:

     DocumentRoot "/Users/<username>/Sites"
    
  4. You also need to change the <Directory> tag reference right below the DocumentRoot line. This should also be changed to point to your new document root also:

     <Directory "/Users/<username>/Sites">
    
  5. In that same <Directory> block you will find an AllowOverride setting, this should be changed as follows:

     AllowOverride All
    
  6. Now we have the Apache configuration pointing to a Sites folder in our home directory. One problem still exists, however. By default, Apache runs as the user _www and group _www. This will cause permission problems when trying to access files in our home directory. About a third of the way down the httpd.conf file there are two settings to set the User and Group Apache will run under. Change these to match your user account (replace <username> with your real username), with a group of staff:

     User your_user
     Group staff
    
  7. Now, save and close the file.

  8. Restart your Apache with sudo apachectl restart to pick up the changes you made to the configuration file.

  9. Now, you need to create a Sites folder in the root of your home directory. You can do this in Terminal, or in Finder. In this new Sites folder create a simple index.html and put some dummy content in it like: <h1>My User Web Root</h1>.

     mkdir ~/Sites
     echo "<h1>My User Web Root</h1>" > ~/Sites/index.html
    
  10. Pointing your browser to http://localhost should display your new message. If you have that working, Apache has been correctly configured!

PHP

  • We will be installing PHP 5.4 through Homebrew. PHP is used for web development, and the backend of Wordpress is written in it.
  1. First, make sure Homebrew is up to date.

     brew update
     brew doctor
    
  2. Next, we have to tap into the PHP formulas from Homebrew.

     brew tap homebrew/dupes
     brew tap homebrew/versions
     brew tap homebrew/homebrew-php
    
  3. Once that is complete, install PHP 5.4.

     brew install php54
     brew doctor
    
  4. You have successfully installed PHP 5.4 but we need to tell Apache to use it. You will again need to edit the /etc/apache2/httpd.conf file and search for #LoadModule php5_module. You will notice that this is line is commented out. We can ignore it because this is pointing to the version of PHP that came with OS X. Below the other LoadModule lines, add this:

     # Brew PHP LoadModule
     LoadModule php5_module /usr/local/opt/php54/libexec/apache2/libphp5.so
    
  5. You should also take this time to uncomment the mod_rewrite.so module definition so that it will be available:

     LoadModule rewrite_module libexec/apache2/mod_rewrite.so
    
  6. Restart Apache again, now that PHP has been installed.

     sudo apchectl restart
    
  7. We need to make sure PHP is installed and running as expected. Simply create a file called info.php in your Sites folder you created earlier. In that file, just enter the line:

     <?php phpinfo(); ?>
    
  8. Point your browser to http://localhost/info.php and you should see a PHP information page:

PHP 5.4 Info Page

  • If you see a similar phpinfo result, Apache and PHP are running successfully.

MySQL

  • While SQLite is useful for quick database creation and sharing, MySQL is scalable, secure and necessary for Wordpress.
  1. We will be using MariaDB which is a drop-in replacement for MySQL and is easily installed and updated with Homebrew. Open Terminal, and run the follwing commands:

     brew update
     brew install mariadb
     brew doctor
     unset TMPDIR
     mysql_install_db
    
  2. After a successful installation, you can start the server:

     mysql.server start
    
  3. If you are successful, you will see the following:

     Starting MySQL
     .. SUCCESS!
    
  4. Change the MySQL server password and secure your installation. The simplest way to do this is to use the provided script:

     /usr/local/bin/mysql_secure_installation
    
  5. Just answer the questions and fill them in as is appropriate for your environment.

  6. To stop the MySQL server, use the command:

     mysql.server stop
    

Wordpress

Git Tutorial

Github vs Bitbucket

Installing Additional Python Libraries

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment