MacOS

From eBabel wiki
Jump to: navigation, search

Customize Terminal prompt

Check if the bash profile file exists:

ls ~/.bash_profile

If the file doesn't exist, create it:

touch ~/.bash_profile
vi ~/.bash_profile

Enter this line to make your Terminal prompt completely blank:

export PS1=""

You can insert a funny emoji character while in edit mode in vim with menu option Edit > Emoji & Symbols

Useful links

How to hibernate

Setup mysql root user

Once you've installed MySQL, you'll need to establish the "root" password. If you don't establish a root password, then, well, there is no root password, and you don't need a password to log in.

So, that being said, you need to establish a root password.

Using terminal enter the following:

Installation: Set root user password:

/usr/local/mysql/bin/mysqladmin -u root password NEW_PASSWORD_HERE

If you've made a mistake, or need to change the root password use the following:

Change root password:

cd /usr/local/mysql/bin/
./mysql -u root -p

> Enter password: [type old password invisibly]

use mysql;
update user set password=PASSWORD("NEW_PASSWORD_HERE") where User='root';
flush privileges;
quit

Run a website

sudo vi /etc/hosts

Add an entry that points to 127.0.0.1

cd ~/Sites/
mkdir nameOfNewLocalSiteDirectory

Edit your website configuration file:

sudo vi /etc/apache2/users/YourUsername.conf

Add the following block:

<VirtualHost *:80>
       ServerName yourlocaldomain.loc
       DocumentRoot /Users/YourUsername/Sites/nameOfNewLocalSiteDirectory
</VirtualHost>

Finally, restart Apache:

sudo apachectl -k restart

You can now browse:

http://yourlocaldomain.loc

Specify a default page

sudo vi /etc/apache2/users/YourUsername.conf

Add or edit the line in bold:

<Directory "/Users/YourUsername/Sites/">
   Options Indexes MultiViews
   AllowOverride None
   Order allow,deny
   Allow from all
   DirectoryIndex index.htm index.php
</Directory>

This will make index.htm and index.php the default pages for all sites.

Host several sites

When hosting several sites, it's important that the first line of your /etc/apache2/users/YourUsername.conf file reads:

NameVirtualHost *:80


Install LAMP on Mac OS

Turn on Apache

Go to System Settings->Sharing and turn on Web Sharing. If necessary click the button that says “Create Home Folder” which will create a folder called “Sites” in your home directory. You now have a web server that you can access at http://localhost/~username/ (“username” being your own account login name)

Edit /private/etc/apache2/httpd.conf

To enable PHP uncomment (remove the number sign at the beginning of) the line:

#LoadModule php5_module libexec/apache2/libphp5.so

(optional) you can re-map the server root to your home website directory by editing DocumentRoot:

DocumentRoot “/Users/username/Sites”

If you wish to use .htaccess files then look a bit further down AllowOverride and set it to “All” like so:

Options FollowSymLinks
AllowOverride All
Order deny,allow
Deny from all

root wheel permission on httpd.conf

If you can't edit the httpd.conf file, try:

sudo chmod u+w /etc/apache2/httpd.conf

Edit /private/etc/apache2/users/username.conf

Your user directory has it’s own permissions as well which are located in this separate file. You may wish to enable FollowSymLinks and AllowOverride again here by changing these two lines like so:

Options Indexes MultiViews FollowSymLinks
AllowOverride All

Copy /private/etc/php.ini.default to /private/etc/php.ini

OSX includes a default php.ini file that you can use but you must rename or copy it first. If you don’t do this then PHP will still run but it will just be using the default initialization settings with no way for you to override them.

Edit these settings in php.ini (some of these settings will not come into play until they are installed)

display_errors = On
mysql.default_socket = /tmp/mysql.sock
pdo_mysql.default_socket=/tmp/mysql.sock
date.timezone = ‘America/Chicago’
include_path = “.:/usr/lib/php/pear”

(Optional) Install PEAR

If you use the PEAR libraries you can install them using the included phar file like so:

sudo php /usr/lib/php/install-pear-nozlib.phar
sudo pear config-set php_ini /private/etc/php.ini
sudo pecl config-set php_ini /private/etc/php.ini
sudo pear upgrade-all

Install MySQL

Download the latest MySQL dmg installer from mysql.com.

To decide if your Mac is 32 bits of 64 bits, check About This Mac and the value of Processor.

In Terminal, once MySQL has been started, run:

sudo /usr/local/mysql/bin/mysql

Add MySQL to $PATH

Test if mysql is already in the path:

echo $PATH | grep mysql

Add the path to MySQL:

vi ~/.bash_profile

Add the following line:

export PATH=/usr/local/mysql/bin:$PATH

Finally, logout and log back in.

It will now be possible to run MySQL from the command line with the command:

mysql

MySQL run from PHP

MySQL may not work on your Mac OS X. If you get a message about the mysql.socket not being found, modify the file:

sudo vi /private/etc/php.ini

If that file doesn't exist, make a copy of /private/etc/php.ini.default

The correct location of mysql.sock should be /tmp/mysql.sock instead of the default /var/mysql/mysql.sock

In php.ini, update the following locations:

pdo_mysql.default_socket=/tmp/mysql.sock
mysql.default_socket = /tmp/mysql.sock
mysqli.default_socket = /tmp/mysql.sock

(Optional) Install Apache Plugins

If you use encryption you may need to install mcrypt. Instructions have been provided by Michael Gracie

If you use the Zend debugger you can install that using these instructions.