Skip to content

Instantly share code, notes, and snippets.

@kenichi-shibata
Forked from paill/InstallGuide.md
Created March 13, 2023 16:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kenichi-shibata/e58fecc99ae45d41f33661a0014fbaa8 to your computer and use it in GitHub Desktop.
Save kenichi-shibata/e58fecc99ae45d41f33661a0014fbaa8 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

Geting an Admin Account

  • In order to install and configure your Mac, you need to be an Administrator on your computer. Either, contact Paul or Charlie, and they will create an account for you.

Installing of Software

Homebrew

  • Homebrew is an easy to use package manager for OS X. We will be using it to install most of the software we need.
  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
    

Node.js & npm

  • Node.js is a JavaScript platform for easily building fast, scalable network applications.

  • npm is a package manager for JavaScript, and is the default for Node.js.

  1. First, check if Node.js & npm are already installed by running the commands:

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

  3. We will be using Homebrew to install Node.js and npm. With Homebrew, installing both is done with single package called node. Run the following commands in Terminal:

     brew update
     brew install node
     brew doctor
    
  4. To make sure sure Node.js and npm installed correctly, run the commands:

     node --version
     npm --version
    

Anaconda

  • Anaconda is a distribution of Python that handles package management. conda is its package management system. It comes with multiple Python packages already included such as SQLAlchemy, pandas, and NumPy.
  1. First, check if Anaconda is already installed by running the command:

     conda --version
    
  2. If installed, move onto the next section; 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
    

Git

  • Git is a version control system that we will be using to organize our projects clearly and efficiently.
  1. First, check if git is already installed 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
    
  4. To make sure git installed properly, run the command:

     git --version
    

SQLite

  • SQLite is serverless, zero-configuration, transactional SQL database that allows for quick sharing and testing as each database is simply a created file. sqlite3 is its command line tool.
  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
    
  4. To make sure SQLite install properly, run the command:

     sqlite3 -version
    

Sequel Pro

  • Sequel Pro is an easy-to-use Mac database management application for working with MySQL databases allowing for direct access to MySQL databases on local and remote servers.
  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

  • PyCharm is an IDE used for programming in Python. It provides code analysis, a graphical debugger, an integrated unit tester, and integration with version control systems (Git)

Note: PyCharm is merely a suggestion.

  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 can 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 includes extra details that are not needed, so I provide only the necessary steps below as well as how to set up your first WordPress site.

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 server 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.

Document Root

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
    

User & Group

  1. 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
    
  2. Now, save and close the file.

Create a Sites Folder

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

  2. 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
    
  3. 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
    

Apache Setup

  1. 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
    
  2. 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
    
  3. Restart Apache again, now that PHP has been installed.

     sudo apchectl restart
    

Validating PHP Installation

  1. 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(); ?>
    
  2. 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.

  • IMPORTANT NOTE: Be sure to delete info.php once you are sure PHP is running properly. phpinfo(); can be a potential security vulnerability, so it is important to remove it when you no longer need it.

MySQL

  • While SQLite is useful for quick database creation and sharing, MySQL is scalable, secure and necessary for WordPress. You can work with MySQL through Sequel Pro or the command line tool mysql.
  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 following 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

  • Now, we are going to walk through setting up a WordPress site in for local development.
  1. First, make sure the Apache and MySQL servers are running.

  2. Next, go to WordPress.org and download the lasted version of WordPress.

  3. Place the downloaded zip file in your Sites directory. Note: I recommend you create a subdirectory for your WordPress sites within your Sites directory. For the remainder of this tutorial, I assume your WordPress site is under the directory WordPress_Sites.

  4. Unzip the file, and rename the result folder to whatever you would like such as MyWordPressSite.

  5. Now, we need to created the MySQL database for the site. Open Terminal and access the MySQL server:

     mysql -u root -p
    
  6. You will be prompted for the password for root, which you should have set earlier. If not, by default root has no password.

  7. Inside the MySQL monitor, create a database for your site with whatever name you would like. Be sure to end your command with a semi-colon ;. Example:

     CREATE DATABASE first_wordpress_site;
    
  8. Close the MySQL monitor, and navigate to your WordPress site from a web browser. Example link: http://localhost/WordPress_Sites/MyWordPressSite/

  9. Follow the instructions on the screen. Provide the name of the database you just created. The database username and password are your login credentials for the MySQL server. The database host is 127.0.0.1 or localhost. For table prefix, name this something other than wp_ for security purposes. Be sure to include an underscore after the prefix.

  10. If everything was entered properly, upon clicking Submit, you should move onto the next page.

  11. Finish following the instructions, and when you are done creating an account and logging in, you will have your WordPress site!

  • Note: If you wish to delete your WordPress site, remove the corresponding WordPress folder from your Sites directory. Then go into the MySQL monitor on the command line and execute the command:

      DROP DATABASE <database_name>;
    

Enabling Pretty Permalinks for WordPress MuliSite

Git Tools

Branches & Merging

GitHub vs BitBucket

Installing Additional Python Libraries

  • Use conda whenever possible to install new Python packages. Use conda search to find packages.

  • If conda does not have a package, use pip instead. Use pip search to find packages, and pip install to install them. pip is another broader Python package management system.

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