Notes about Setting up my Mac LAMP


Note-to-Self:
Some assertions here are no longer valid—since I’ve reconfigured my web server to utilize virtual hosts.


Introduction

Computer: Mac OS X Version 10.7.3 Lion.

Instructions: VerySimple Custom Software web site

Run Apache


http://sameh-labibs-imac.local/ is the only URL which should be used when trying to access the development web site on this computer. Don’t try to use something like http://sameh-labibs-imac.local/~samehlabib/. Much more on that to follow…


To refresh server disable/re-enable Web Sharing.

To see the IP information and the status of the web server go to System Preferences->Sharing.

the Apache error_log file

Its filesystem location:

/private/var/log/apache2/error_log

Edit httpd.conf and Others

/private/etc/apache2/httpd.conf

To enable PHP uncomment the following like this:

LoadModule php5_module libexec/apache2/libphp5.so

To be able to use .htaccess files set AllowOverride to “All.”

<Directory />
    Options FollowSymLinks
    AllowOverride All
    Order deny,allow
    Deny from all
</Directory>

Here are some more settings:

DocumentRoot "/Users/samehlabib/Sites"
ServerAdmin gxsam1968@yahoo.com
<IfModule dir_module>
    DirectoryIndex default.htm index.html index.php
</IfModule>

#
# This should be changed to whatever you set DocumentRoot to.
#
<Directory "/Users/samehlabib/Sites">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

Refresh the server per instructions above. I won’t keep saying this over and over. Remember to do it whenever you make changes to configuration files for any daemon.

Other Configuration Files

  • /private/etc/apache2/users/samehlabib.conf
    for making a lot of the same configurations you would do in httpd.conf except this time affecting samehlabib only. Here I’ve added FollowSymLinks and made AllowOverride All. I added FollowSymLinks to make my pages load faster. See code all the way at the bottom of this list item.

    However, only httpd.conf matters. Why? … For two reasons. One, because I want browsers to always access my development site by using http://sameh-labibs-imac.local/ (even though the directory they will be accessing is the Sites folder for samehlabib.) Two, http://sameh-labibs-imac.local/ uses httpd.conf. Again, let me emphasize /Users/samehlabib/Sites is the DocumentRoot of the web server. It is a design decision that this directory will always be the DocumentRoot for the web server on my Mac. The fundamental reason I chose this design is that many of my scripts assemble URLs to other files on my site; and, the manner in which my scripts assemble these URLs is by pre-appending the domain name to the location of the script. That is incompatible with having a ~samehlabib sandwiched in between the domain name and the file path.

    I want to mention the following because it relates to the design decision mentioned in the previous paragraph. I placed an informational index.html page in the DocumentRoot folder. Here is what it looks like:

  • <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html lang="en">
    
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>index.html</title>
    </head>
    <body>
    
    <h1 align="center">index.html</h1>
    <hr>
    
    <p>This page is a place holder.</p>
    
    <p>Its intended location is the Sites folder of my Mac. So, (if you
    see this page on my live site,) ignore it&mdash;it's here as a back-up.</p>
    
    <p>The <strong>Sites</strong> folder is<strong><code> DocumentRoot
    </code></strong>of my development web server.</p>
    
    <p>Projects can be found in sub-folders of Sites folder.</p>
    
    <hr>
    </body>
    </html>
    
    <Directory "/Users/samehlabib/Sites/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
    
  • /private/etc/php.ini
    In order for there to be a php.ini file which I can edit I must create it using php.ini.default as a template (/private/etc/php.ini.default.)

    Most of the changes I’ve made to php.ini relate to how the development environment differs from a production environment. I won’t list those changes here because the php.ini file does a good job of documenting how to choose those values.

    You have to (at least) make the following changes:

  • display_errors = On
    mysql.default_socket = /tmp/mysql.sock
    pdo_mysql.default_socket = /tmp/mysql.sock
    date.timezone = "America/New_York"
    include_path = ".:/usr/lib/php/pear"
    

Refresh the web server after making these changes.

Install MySQL

Download

I installed the 64-bit version mysql-5.5.23-osx10.6-x86_64.dmg.

To start/stop MySQL go to System Preferences->MySQL.

I registered an account with http://www.mysql.com.

Where is the mysql directory?

The directory called mysql is actually an alias to the version specific MySQL directory.

/usr/local/mysql

Who owns the actual MySQL directory?

Notice I said “actual.” That is because I am referring to the version specific MySQL directory.

An account called system and a group called wheel.

Account system has rw and wheel has r.

Commonly used CL programs

/usr/local/mysql/bin/mysql
/usr/local/mysql/bin/mysqladmin

It is suggested that I alias them in my bash shell. Even better, add /usr/local/mysql/bin to my PATH environment variable.

alias mysql=/usr/local/mysql/bin/mysql
alias mysqladmin=/usr/local/mysql/bin/mysqladmin

The directory which contains data

/usr/local/mysql/data

Command to shut down the MySQL server

mysqladmin shutdown

The name of MySQL server binary

mysqld

CL start/stop the MySQL server using Startup Item

The Startup Item for MySQL is installed into /Library/StartupItems/MySQLCOM. The Startup Item installation adds a variable MYSQLCOM=-YES- to the system configuration file /etc/hostconfig. If you want to disable the automatic startup of MySQL, change this variable to MYSQLCOM=-NO-.

To start/stop MySQL go to System Preferences->MySQL.

You can start and stop MySQL by running the following commands in a terminal window.

shell> sudo /Library/StartupItems/MySQLCOM/MySQLCOM start

shell> sudo /Library/StartupItems/MySQLCOM/MySQLCOM stop

MySQL users

The user named root initially did not have a password. All you had to do was hit the enter key. Now it has a password. That password is the same as the one for samehrlabib.

I created a user called samehrlabib. His password is etnashar(nemra)_girls(3araby)_esm-kalby-el-tany.

Install phpMyAdmin (PMA)

I was able to successful install phpMyAdmin (PMA) using the instructions on the A Non-Programmer Approach to Django blog.

PMA runs in the browser. Here is the URL:

http://sameh-labibs-imac.local/phpMyAdmin/

directory location for PMA files

/usr/local/phpMyAdmin

config file for PMA

/usr/local/phpMyAdmin/config.inc.php

I had to edit this file to avoid a glitch:

$cfg['Servers'][$i]['host'] = '127.0.0.1';

I can also use the PMA setup wizard to configure phpMyAdmin further.

To configure httpd to resolve /phpMyAdmin

I created the file

/etc/apache2/other/phpMyAdmin.conf

containing

Alias /phpMyAdmin /usr/local/phpMyAdmin

<Directory /usr/local/phpMyAdmin>
    Options Indexes
    Order allow,deny
    Allow from all
</Directory>

Configurations I made to MySQL Server (using PMA)

I changed some of the default character sets and database engines to match what my web-host Netfronts uses.

Furthermore, I created a new database (samehrlabib_aTestMyLAMP) for testing my LAMP setup. Also, I gave samehrlabib privileges over this database.

SysAdmin Stuff

Good News! I can use GUI text editors (i.e., TextWrangler) to edit system configuration files if I do “Switch User” of my Mac GUI to root user.

More Good News! To navigate the file system on a Mac I can do Finder->Go->Go to the folder.

I ran into some problems which required me to do some command line system administrator type stuff. I had to wing it with the help of Mary Ann and Google. So, I’ll document what I learned right here so I don’t have to re-learn this stuff later.

sudo

sudo cp /private/etc/php.ini.default /private/etc/php.ini

sudo allows a permitted user to execute a command as the superuser or another user, as specified in the sudoers file.

vi

sudo vi /private/etc/apache2/httpd.conf

Vi is an editor which can work at the command line. Vi, being a sysadmin thing allowed me to edit and save files I otherwise could not save from a GUI test editor.

su

The su command opens up a shell for me as root.

The root user account is disabled on Mac computers by default. So, I had to reconfigure my Mac to have a root user. And, I had to pick a P/W. So, I chose the same one as my regular user account.

Advertisements

About samehramzylabib

See About on https://samehramzylabib.wordpress.com
This entry was posted in Configure My Systems, Version 2.0 Site Design. Bookmark the permalink.

3 Responses to Notes about Setting up my Mac LAMP

  1. Pingback: Lubuntu cont’d – add MySQL & phpMyAdmin | Sam's PHP How-To

  2. Pingback: Lubuntu cont’d — add PHP | Sam's PHP How-To

  3. Pingback: Testing the LAMP I have on My Mac | Sam's PHP How-To

Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s