MAMP

Hi there,

Here are few notes on how to set up a local server environment on Mac OS X by installing PHP, MySQL, and Apache using MAMP.

The goal of this post is to be able to have a sandbox (a local server environment) in order to create a web site prior to uploading it on the web.

4 Steps to follow

There is already a webpage with steps to follow in order to get this done:

Installing WordPress Locally on Your Mac With MAMP

• The URL (http or https) designates the protocol that is used to locate the file or resource on the World Wide Web (www). In other words, the protocol is in charge of “calling” the server on the Internet World Wide Web.

Dissecting a web address (the URL)

http(s)      ://      www.      (sub-domain.)      DomainName.      com

NOTE 1: Items in parentheses are optional.

For instance, let us dissect the web address for this site: PyProject where you are right now if you are reading these lines 😉

dissect_pyproject

https://www.pyproject.com/

  • Protocol : http
  • DomaineName: pyproject.com
  • Top-Level Domain: .com
    You can also have :
    .net
    .org
    .edu
    .ca
    .fr
  • root folder :

    The root directory of your website is the content that loads when visitors access your domain name in a Web browser.

    Your website’s root directory depends on whether the domain name is your primary domain name or another type […]

    Your primary domain name’s root directory is the root of the hosting account, which can be symbolized as a single forward slash (i.e. “/” without the quotation marks), or as an entirely blank field.
    Source: GoDaddy

    If all the wordpress files were directly placed into the htdocs directory, then the hierarchy be as follows:

    root_folder_hierarchy_2

    Once your implementation has been finished, verify this by typing:
    localhost:8888/

    Furthermore, if the wordpress folder was placed in the htdocs directory, then the hierarchy would be:

    root_folder_hierarchy_1

    Once your implementation has been finished, verify this by typing:
    localhost:8888/wordpress/

    Finally, taking this idea a step further, let us say that all the wordpress files placed in another file called toto, then the hierarchy would look like:

    root_folder_hierarchy_3

    Once your implementation has been finished, verify this by typing:
    localhost:8888/wordpress/toto/

hypertext access file (alias .htaccess file )

If needed, it is possible to delete the word from the root file.

.htaccess files provide a way to make configuration changes on a per-directory basis […]
.htaccess files (or “distributed configuration files”) provide a way to make configuration changes on a per-directory basis. A file, containing one or more configuration directives, is placed in a particular document directory, and the directives apply to that directory, and all subdirectories thereof.
Source: Apache.org

In addition, here is a useful tutorial in order to play with the .htaccess configuration file.

The Wikipedia explanation is also quite good:

A .htaccess (hypertext access) file is a directory-level configuration file supported by several web servers, used for configuration of site-access issues, such as URL redirection, URL shortening, Access-security control (for different webpages and files), and more.

Analogy by R:

htdocs est le dossier équivalent au dossier www sur ton serveur

Meaning, the htdocs file is the equivalent to the www-file on the server.

Sub-domain

In addition, let us say that I want to add a sub-domain like “portfolio”. Here is what the ulr structure will look like:

https://portfolio.pyproject.com/

      • Protocol : http
      • DomaineName: pyproject.com
      • Subdomain: portfolio
      • Top-Level Domain: .com
        You can also have :
        .net
        .org
        .edu
        .ca
        .fr

It is worth mentioning that the subdomain name replaced the “www” part.

GoDaddy has a usefule article on subdomains.

Furthermore, here is some info about the Domain Name System

The Domain Name System (DNS) has a tree structure or hierarchy, with each non-RR (resource record) node on the tree being a domain name. A subdomain is a domain that is part of a larger domain; the only domain that is not also a subdomain is the root domain.
Source: Wikipedia

IP address

An Internet Protocol address (IP address) is a numerical label assigned to each device connected to a computer network that uses the Internet Protocol for communication.
An IP address serves two principal functions:
• host or network interface identification and
• location addressing.
Internet Protocol version 4 (IPv4) defines an IP address as a 32-bit number.
Source: Wikipedia

Since we are setting up a local server environment, let us see the difference between a local IP address versus an external IP address.

External IP address:

      • Given by: Internet Service Provider
        When the web browser requests a webpage, it sends this IP address along with it.
        It is worth mentioning that every website has its own IP addres.
        If you are curious to know what is your external IP address, head to Bing or Google and type: “IP address” they will give it to you.
      • Dissecting the external IP address: Recall that the “Internet Protocol version 4 (IPv4) defines an IP address as a 32-bit number”
        This means that the IP address has 4 blocks of numbers each ranging from 0 to 255.

32-bit_IP_address

Local IP address:

      • Given by: Network Router
        Routers with default settings provide a local IP address to all connected computers. This IP address is for internal use.
        Since the goal of this blog post is to set up a local server environment, this will become handy.
        The IP
      • Dissecting the local IP address: The network router will adjust the local IP addresses in order to provide hierarchical order information about the devices connected to it.
        Most local IP addresses start like this: 192 . 168 . ___ . ___
        The last digit represents the number of devices connected to it in the order of arrival.

MAMP administrator page

      • WordPress   ←   App MAMP  →   Internet (www)
        The objective is for WordPress.org to communiate with the Internet
      • WordPress   ←   App MAMP  →   Local Network (Network Router)

Local        ⇔        Web

locahost        ⇔        http(s)
local server environment                 web hosting services
MAMP        ⇔        Orongo/Bluhost/ …

localhost:8888/MAMP

Port: 8888
Software used: MAMP.app

      1. Click MAMP icon
      2. localhost:8888/MAMP/?language=English
        This step will open the MAMP dashboard
      3. PHP
        Click on php Info
        localhost:8888/MAMP/index.php …
        Apache port: 8888
        NOTE: This status site will warn us if there are updates to do.
      4. MySQL
        Click on phpMyAdmin
        phpMyAdmin Dashboard
        • localhost
        • 3306  →   phpMyAdmin port
        • root
        • root
        • /Application/MAMP/tmp/mysql/mysql.sock
        • This dashboard will allow you to save a DataBase when time comesExport method  →   Quick (by default)
        Import method  →   If there is a problem with the database and you need to re-install a database (previously saved), it will be done with this tab.

UTF8

According to Wikipedia, there are 52 official languages. So, the world has come with ways of writing these rich assortment of alphabets and characters.

The Unicode Character Table explains the UTF8 as follows:

A character in UTF8 can be from 1 to 4 bytes long. UTF-8 can represent any character in the Unicode standard. UTF-8 is backwards compatible with ASCII. UTF-8 is the preferred encoding for e-mail and web pages

Default configurations

      • Apache Port: 8888
      • Nginx Port: 7888
      • MySQL Port: 8889

Downloading WordPress

If you are following the steps enunciated on “Installing WordPress Locally on Your Mac With MAMP”, the last step is the WordPress download.

Web-server: Apache
Macintosh HD/Applications/MAMP/htdocs

      • Recall: htdocs is the root folder
        MAMP document root: htdocs

NOTE 2: The current PHP version is 7.2.1. So, befaure launching the website via the web hosting service, it will be important to verify the compatibility of the PHP version with WordPress.

NOTE 3: The local server environment can be on my computer as well as on the cloud.

Database

wordpress  →   collation  →   create

Query

NOTE 4: Before launching the website online, change the DataBase host.

      • Name: wordpress
      • Username: root
      • Pass…: root
      • Host: localhost

Voilà!

Install Django in a virtualenv

djangoproject

djangoproject

Installing Django in a virtual environment

Django is an open-source MTV (Model Template View) framework written in Python for building web applications.

Get Started:

Step 1) pip

If you already have Python 2 or Python 3 installed in your computer, go ahead and verify you have pip:

In your Terminal run:

$ which pip
/usr/local/bin/pip
$ pip –version
pip 9.0.1 from /Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg (python 2.7)

If you do not have pip, the run:

$ sudo easy_install pip

Step 2) virtual environment

Install the virtual environment

$ sudo pip install virtualenv

mac_terminal_pip_install_virtualenv

Done! The virtual environment is installed.

Navigate where you want to test/play with Django

Go to the main directory where you want to work.

Here are some useful commands to navigate in your Terminal:

  • pwd
  • ls
  • cd
  • cd ..
  • clear
  • mkdir

I decided to work from the Desktop:

~ $ cd Desktop

Create a directory where you want test/play with Django

Next, create a directory where you want to work from:

:Desktop $ mkdir DjangoVM

Name your virtual environment

It is time to name your brand new virtual environment:

DjangoVM $ virtual sandbox

I decided to name my virtual environment “sandbox” but you can name it whatever you like.

Congrats! Your virtual environment is now installed.

mac_terminal_virtualenv_name

See it for yourself:

:DjangoVM $ cd sandbox
:sandbox $ ls
bin                 lib
include        pip-selfcheck.json

Entering the Virtual Environment

enter_virtual_environment

$ source bin/activate
(sandbox)  :sandbox $

That’s it.

The name sounds cooler than what we just got. I mean, we had much more going on while installing pip or even virtualenv. Well, again, that is it.

Step 3) django

Before installing Django, let us check which version of Python we have. That way, we will pick the right Django version.

(sandbox)  :sandbox $ python -V
Python 2.7.10

If you want to take a break, read this WTF Moment.

python_django_versions

Here we are! The moment of truth. Let us run this command and install django.

(sandbox)  :sandbox $ pip install django==1.11
Collecting django==1.11
Downloading Django-1.11-py2.py3-none-any.whl (6.9MB)
100% |████████████████████████████████| 6.9MB 148kB/s
Collecting pytz (from django==1.11)
Downloading pytz-2017.3-py2.py3-none-any.whl (511kB)
100% |████████████████████████████████| 512kB 1.5MB/s
Installing collected packages: pytz, django
Successfully installed django-1.11 pytz-2017.3
(sandbox) Xis-MacBook-Pro:sandbox xi$

Look at that!

I recommend this YouTube video in case you want to learn more about:

(sandbox)  :sandbox $ pip freeze
Django==1.11
pytz==2017.3
(sandbox)  :sandbox $ pip install django --upgrade

Fun fact!

I met Kojo at PYCONCA 2017. Super cool guy who likes to talk about Django.

Here he is for you to meet:

Happy coding!

@codepyxi

PyCon 2014: What A Journey!

Hi there,

My experience at #pycon2014 was extraordinary. Here is why.

 

Networking @PyCon :

  • I met inspiring programmers/developers who were willing to share their experience and time. Amazing.
  • I talked with 99% of the booth presenters. The companies that were present in PyCon shared one characteristic: their hunger for innovation. Here is the complete list of the companies that were present:
  • I met women who code from around the world through PyLadies, Girl Develop It, MongoDB, and many other companies/institutions.
    • Kudos to all women who have paved my way into coding. Thank you!
PyLadies Booth - PyCon 2014

PyLadies Booth – PyCon 2014

 

PyCon 2014

PyCon 2014

 

PyCon 2014 - Palais de Congrès Montréal

PyCon 2014 – Palais de Congrès Montréal

 

Open Source Community :

  • What is Open Source?

Free and open-source software (FOSS) is computer software that can be classified as both free software and open source software. That is, anyone is freely licensed to use, copy, study, and change the software in any way, and the source code is openly shared so that people are encouraged to voluntarily improve the design of the software.

Source: Wikipedia / Free and Open Source Software

  •  How is the FOSS notion related to Python?

CPython, the reference implementation of Python, is free and open source software and has a community-based development model, as do nearly all of its alternative implementations. CPython is managed by the non-profit Python Software Foundation.

Source: Wikipedia / Python (programming language)

  •  PyCon 2014 gave me the opportunity to realize that there is a great Open Source Community that exists, collaborates, and thrives. I like to call it “Python Ecosystem”.
    • Moreover, I had the privilege to chat with a developer from Fastly. If I recall well, he mentioned something like “Just remember to give back whenever you develop something great”.  I will keep those wise words with me.
    • Here is a Tweet that illustrates the collaboration spirit at PyCon:

      This is the first day of Sprints at #pycon2014!! Looking forward for these 4 days of intensive learning, development and camaraderie! @pycon

      Source: Tryolabs / April 14th, 2014

 

Broadening my horizons @PyCon :

  • I attended several workshops and talks. All of them taught me something new.
    • Kudos to the Google team who presented on April 10th, 2014. The workshop was great and they kept their cool when they answered an inappropriate question. Greatness and Wisdom!

 

Programming Bucket List :

  • Professor Allen B. Downey: The Python knowledge I have acquired is mostly thanks to Professor Downey and the free book he wrote, Think Python: How to Think Like a Computer Scientist (2012)
    • On April 10th, 2014 I met and thanked Professor Downey in person at the O’Reilly booth at PyCon! Until today, I have spent dozens and dozens of hours learning with his book. As I previously mentioned, I read some chapter two or three times. The book includes some subtle humor. So, meeting him was definitely on my Programming Bucket List.
    • The second best quality of this book (the fist being that it is free!) is that it is written as if Professor Downey was standing before you trying to help you understand the concepts. Priceless! A great teacher is someone who teams up with you to successfully transmit knowledge.
  • Guido van Rossum: Guido, as everybody called him @PyCon (and not Mr van Rossum) gave a presentation on April 13th, 2014.
    • I am disappointed. I missed it.
    • I must make it to PyCon 2015 now!

 

@PyCon presentations :

Here are some links that can be useful to see PyCon 2014 presentations:

 

Special Thanks :

My PyCon journey was possible thanks to the support from PyLadies, Caktus Group and NumFocus.

Thank you for believing in me and offering me this opportunity.