LAMP Toolbox
Enabling Apache, PHP, and MySQL in OSX
Edit host file with Terminal
sudo nano /private/etc/hosts
Edit httpd.conf file with Terminal
- sudo nano /etc/apache2/httpd.conf
- enter the root user password
- scroll down with the cursor to line 114
- uncomment: #LoadModule php5_module
- ctrl+0 (WriteOut) to save the changes, press enter to save the file
Create a php.ini file
The default installation doesn't use the PHP configuration file php.ini. You need to need to make a copy of a file called php.ini.default, and edit it.
- cd /private/etc
- sudo cp php.ini.default php.ini
- edit the file: sudo nano php.ini
-
change the default error settings
from "error_reporting = E_ALL & ~E_NOTICE"
to "error_reporting = E_ALL" - ctrl+0 (WriteOut) to save the changes, press enter to save the file
Possible locations of the php.ini
- /usr/local/php5/lib/php.ini
- /private/etc/php.ini
File upload size in php.ini
Be careful to edit the correct php.ini file. Sometimes php.ini can exist several times and in the wrong location
-
post_max_size = xyzM
-
upload_max_filesize = xyzM
The same steps using TextWrangler
Restart Apache
sudo /usr/sbin/apachectl restart
if this error presents "/usr/sbin/apachectl: line 82: ulimit: open files: cannot modify limit: Invalid argument", edit apachectl using textwrangler:
- open /usr/sbin/apachectl
-
edit line 67
from ULIMIT_MAX_FILES="ulimit -S -n `ulimit -H -n`
to ULIMIT_MAX_FILES=""
Create a Virtual Host in OSX
-
Create a site directory cd ~/Sites/ mkdir mynewsite -
Activate virtual hosts in apache in /private/etc/apache2/httpd.conf
uncomment this line
# Virtual hosts
#Include /private/etc/apache2/extra/httpd-vhosts.conf -
edit file: /private/etc/apache2/extra/httpd-vhosts.conf
This configuration file holds your website virtual host location details.comment out the examples that may create errors
create root localhost
<VirtualHost *:80>
ServerAdmin email@bluewin.ch
DocumentRoot "/Users/username/Sites"
ServerName localhost
</VirtualHost>Create for each individual site an instance like this
<VirtualHost *:80>
ServerAdmin email@isoc.org
DocumentRoot "/Users/username/Sites/internetsociety.org"
ServerName internetsociety.local
</VirtualHost> -
Create a host file entry for each site:
127.0.0.1 localhost
127.0.0.1 internetsociety.local
127.0.0.1 anothersite
Flush DNS
Further to a change in the host file, dns needs to be flushed on the machine
- PC command line: ipconfig /flushdns
- OSX terminal: sudo dscacheutil -flushcache.
Mysql Management
Connect to mysql server using mysql client: /usr/local/mysql/bin/mysql -u rootusername
Stop mysql server: sudo /Library/StartupItems/MySQLCOM/MySQLCOM stop
Remove a Mysql server
- Use mysqldump to backup your databases to text files!
- Stop the database server
- sudo rm /usr/local/mysql
- sudo rm -rf /usr/local/mysql*
- sudo rm -rf /Library/StartupItems/MySQLCOM
- sudo rm -rf /Library/PreferencePanes/My*
- edit /etc/hostconfig and remove the line MYSQLCOM=-YES-
- rm -rf ~/Library/PreferencePanes/My*
- sudo rm -rf /Library/Receipts/mysql*
- sudo rm -rf /Library/Receipts/MySQL*
- sudo rm -rf /private/var/db/receipts/*mysql*
Configuration (exemple) de config.inc.php
<?php
$i=0;
$i++;
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = ''; // use here your password
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['AllowNoPassword'] = true;
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['socket']='/tmp/mysql.sock';
Import a sql database using terminal
ERROR 1153 (08S01) at line 7158: Got a packet bigger than 'max_allowed_packet' bytes
Errors
IMPORTANT: Can't connect to local MySQL server through socket or any other warnings/errors related to PDO
edit php.ini
mysql.default_socket =/tmp/mysql.sock
pdo_mysql.default_socket=/tmp/mysql.sock mysql.default_socket = /tmp/mysql.sock mysqli.default_socket = /tmp/mysql.sock
Filesharing via FTP on OSX
- OSX preferences > Sharing > File sharing > Options
- Share files and folders using ftp
- Use the provided ip address in the ftp client to connect (filezilla)
Clean URLs in Drupal
If clean urls don't work on a local drupal installation:
- login at ?q=user
- to switch temporaily to "normal urls": ?q=admin/config/search/clean-urls
- To enable clean urls on OSX 10.5, if the web root is: /Users/myname/Sites in the main httpd.conf file.
- sudo nano /private/etc/apache2/users/myusername.conf and change AllowOverrides to All