Jeune ingénieur ingénu, reporter-bloggeur de mes aventures à l'étranger et de tout le reste. 
Mes iPhone App
Le célèbre 'JapanEasy' ainsi que Wormwar un jeu de stratégie de serpents, et BrainGame, un jeu de mémoire très sympa. The famous 'JapanEasy' and other games I developed
Road trip au Danemark
Une semaine sur la terre des vikings
Enigme
Un petit remue-méninges...
Programmation
Tutoriels, conseils pour bien démarrer, outils à utiliser
Hawaï
Une perle verte sur l'océan
Le Japonais
Retour sur une expérience peu commune
Apple
Ma première journée là-bas !!!
Happy few
Un film détonnant
AppEngine
L'hébergement gratuit par Google
Automator et Applescript
Impimer plusieurs liens URL / pages internet en PDF
Print many URL / webpages in PDF
Alcatraz
un petit tour sur cette île mythique
Super Cluedo
devenez détective
SQL injections and Timestamps problems
Solution propre pour éviter les problèmes d'échappements d'apostrophes et de guillemets et d'update de timestamp en php/MySQL.
Clean solution to avoid quote escaping and timestamp update problems in php/MySQL.
Wikileaks
Le site de la honte
Mes codes open source
Des dizaines de programmes open source pour apprendre à programmer dans plein de langages
Tutoriel Cocoa / Objective-C
Explications claires pour bien apprendre les bases et la création d'un vrai programme Cocoa avec interface. Nombreux code sources
Petites nouvelles
s'agit-il de stagiaires ? :)
Url propres avec .htaccess
Url propre, sans slash final
Clean url with no trailing slash
Niigata
week-end découverte
San José Sharks vs Vancouver Canucks
un match de hockey vu du stade !
Troubleshooting with iOS
Comment : intercepter le tap sur un UITextView, comprendre pourquoi son application crashe avant même de se lancer, avoir un navigation controller qui fonctionne dans un tabviewcontroller et problèmes width/height après rotation.
How to intercept taps on a UITextView, understand why ones app crashes before any execution, have a NavigationController imbricated in a TabViewController and width/height problems after rotation
Créer un site web : Tutoriel complet
Créer, designer, héberger, rentabiliser
2012
Mai
19
First part in French, second part in English.
Si vous êtes sur Mac OS Lion et que vous cherchez à avoir MAMP, vous êtes au bon endroit, que ce soit parce que vous n'y connaissez rien et que vous voulez simplement avoir un petit site en php/mysql sur votre ordi ou soit parce que vous avez peur d'avoir tout bousillé votre précédente config en passant à Lion. C'est mon cas, j'ai du réinstaller MAMP puis modifier tout un tas de fichiers config d'apache car MAMP ne permettait pas de faire des symlinks vers ~/Sites et je ne voulais pas déplacer mes fichiers vers MAMP/htdocs. J'ai bien du passer 10 heures à me dépatouiller avec tout un tas de choses et donc je souhaite aider ceux qui ont été dans ma situation.
Bref voici comment faire : plan d'action avant d'entrer dans les détails.
Installer Homebrew : /usr/bin/ruby -e "$(/usr/bin/curl -fksSL https://raw.github.com/mxcl/homebrew/master/Library/Contributions/install_homebrew.rb)". C'est un utilitaire similaire à MacPorts. Seulement j'ai suivi beaucoup de tutoriels pour résoudre mon problème qui demandaient d'installer des choses avec MacPorts et à chaque fois il y avait un problème et je ne pouvais pas terminer les installations.
brew install mysql
unset TMPDIR
mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp
sudo mkdir /var/mysql
sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock
Initialisation de MySQL avec création d'utilisateur "root" et mot de passe "root". Vous pouvez bien sûr changer mais bon, c'est courant de prendre ça.
mysql.server start
mysqladmin -u root password root
mysqladmin -u root -h localhost
mysql.server start
Ceci est facultatif, c'est seulement si vous avez peur d'avoir touché à trop de fichiers de config et que plus rien ne fonctionne.
rm -f ~/.pearrc rm -rf ~/.pear brew unlink php brew install autoconf sudo chmod a+w /usr/local/share/emacs/ sudo chmod a+w /usr/local/share/emacs/site-lisp/ brew link autoconf brew tap josegonzalez/homebrew-php brew install php --with-mysql --with-apache open ~/.bashrc
Ajoutez ces deux lignes puis sauvegardez le fichier
alias pear="php /usr/lib/php/pear/pearcmd.php" alias pecl="php /usr/lib/php/pear/peclcmd.php"
source ~/.bashrc pear config-set auto_discover 1 pear update-channels pear upgrade sudo pecl install apc-beta mongo memcachepear install pear.phpunit.de/PHPUnit sudo pear install PHP_CodeSniffer-beta sudo pear install pear.phpunit.de/PHPUnit brew link php
Ceci n'est pas facultatif.
Maintenant qu'on a installé pas mal de trucs il faut modifier les fichiers de config d'Apache pour qu'il lise nos sites dans ~/Sites, qu'il accepte php5 et d'autres petites choses.
sudo chmod a+w v /etc/apache2/httpd.conf
open /etc/apache2/httpd.conf
Un fichier s'ouvre. On va modifier plusieurs lignes. Je conseille de ne pas remplacer les lignes déjà existantes mais de les copier, de les commenter en écrivant à côté "changeThomas" (ou ce que vous voulez), puis de modifier la copie de la ligne non commentée. Comme ça quand vous reviendrez modifier le fichier dans 1 an vous pourrez savoir exactement qu'est ce qui était d'origine et qu'est ce que vous avez rajouté.
Même chose sur /etc/php.ini :
sudo chmod a+w /etc/php.ini
open /etc/php.ini
Les dernières lignes vous permettront via phpMyAdmin de gérer des grosses bases de données (pour pouvoir en importer / exporter). 2Mo est assez ridicule.
phpMyAdmin est un petit site web qui tournera en local qui vous permet de voir, modifier, ... vos bases de données MySQL.
brew install phpmyadmin
mkdir /usr/local/share/phpmyadmin/config
sudo chmod o+w /usr/local/share/phpmyadmin/config
Création de fichier :
open /etc/apache2/other/mod_phpmyadmin.conf
# changeThomas: rien dans ce fichier avant AliasMatch ^/phpmyadmin(?:/)?(/.*)?$ "/usr/local/share/phpmyadmin$1"Options -Indexes AllowOverride None Order allow,deny Allow from all LanguagePriority fr en es de ja ko pt-br ru ForceLanguagePriority Prefer Fallback
phpMyAdmin a besoin de libmcrypt (une librairie de php). Désolé pour cette partie fastidieuse, surtout qu'elle est quasi optionnelle puisque phpMyAdmin affiche des avertissements si l'on n'a pas cette librairie mais les choses devraient marcher quand même (vos sites en php et mysql).
Téléchargez Libmcrypt et dernière version de php
Créez un dossier nommé SourceCache sur le bureau, placez-y les zip que vous venez de télécharger et dézippez les.
Téléchargez aussi Xcode 4.1 tools sur l'App Store et installez les.
cd ~/Desktop/SourceCache
MACOSX_DEPLOYMENT_TARGET=10.7 CFLAGS='-O3 -fno-common -arch i386 -arch x86_64' LDFLAGS='-O3 -arch i386 -arch x86_64' CXXFLAGS='-O3 -fno-common -arch i386 -arch x86_64' ./configure --disable-dependency-tracking
cd libmcrypt-2.5.8
MACOSX_DEPLOYMENT_TARGET=10.7 CFLAGS='-O3 -fno-common -arch i386 -arch x86_64' LDFLAGS='-O3 -arch i386 -arch x86_64' CXXFLAGS='-O3 -fno-common -arch i386 -arch x86_64' ./configure --disable-dependency-tracking
make -j6
sudo make install
cd ../php-5.3.6/
cd ext/mcrypt/
/usr/bin/phpize
MACOSX_DEPLOYMENT_TARGET=10.7 CFLAGS='-O3 -fno-common -arch i386 -arch x86_64' LDFLAGS='-O3 -arch i386 -arch x86_64' CXXFLAGS='-O3 -fno-common -arch i386 -arch x86_64' ./configure --with-php-config=/Developer/SDKs/MacOSX10.7.sdk/usr/bin/php-config
MACOSX_DEPLOYMENT_TARGET=10.7 CFLAGS='-O3 -fno-common -arch i386 -arch x86_64' LDFLAGS='-O3 -arch i386 -arch x86_64' CXXFLAGS='-O3 -fno-common -arch i386 -arch x86_64' ./configure --with-php-config=/usr/bin/php-config
make -j6
sudo make install
phpMyAdmin a un seul petit truc embêtant : il nous demande notre mot de passe à chaque fois que l'on s'en sert et toutes les 10 minutes. Le mieux est je pense de désactiver le mot de passe surtout si vous êtes le seul à vous servir de votre ordinateur.
Ouvrez /usr/local/share/phpmyadmin/config.inc.php et vérifiez que vous avez ces lignes :
$cfg['Servers'][$i]['verbose'] = '';
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['port'] = '';
$cfg['Servers'][$i]['socket'] = '';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['extension'] = 'mysqli';
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = '';
$cfg['Servers'][$i]['AllowNoPassword'] = true;
$cfg['Servers'][$i]['AllowNoPasswordRoot'] = true;
Ouf ça devrait être fini. Reste maintenant à lancer tout ça. Pour que vos sites soient accessibles en local, il faut 1) démarrer le serveur apache et 2) lancer mysql (facultatif si votre site ne se connecte pas à des bases de données)
Apache peut se démarrer soit par Préférences Système -> Partage -> cocher "partage web", soit par ligne de commande : sudo /usr/sbin/apachectl start (ou restart ou stop)
MySQL se lance juste avec mysqld &
Vous pouvez bien sûr demander à votre mac de lancer Apache et MySQL au démarrage de votre ordinateur, mais il sera forcément un poil plus lent à démarrer. Si oui, faites "open /System/Library/LaunchDaemons/org.apache.httpd.plist" et faites en sorte que vous avez ce fichier :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Disabled</key>
<true/>
<key>Label</key>
<string>org.apache.httpd</string>
<key>OnDemand</key>
<false/>
<key>ProgramArguments</key>
<array>
<string>/usr/sbin/httpd</string>
<string>-D</string>
<string>FOREGROUND</string>
<string<-D>/string>
<string<WEBSHARING_ON>/string>
</array>
<key>SHAuthorizationRight</key>
<string>system.preferences</string>
</dict>
</plist>
Attention, mysqld plante parfois pour démarrer si le serveur n'a pas été éteint la dernière fois qu'on n'a pas éteint son ordi. On peut lancer le moniteur d'activité et quitter le processus "mysqld" pour le relancer via le terminal, ou faire "ps | grep mysqld | grep -v 'grep' | cut -d" " -f3 | xargs kill {}; mysqld &". Je vous invite à vous faire un alias dans votre .bashrc !
Une fois tout ça fait, vous devriez pouvoir accéder à http://localhost/phpmyadmin/index.php et à vos sites web !
Si j'ai oublié de citer une étape, merci de me dire où ça bloque, j'essayerai de vous aider !
If you are on Mac OS Lion and you try to get MAMP fully functional, you are at the right place, either because you don't know much and just want to have a local php/MySQL local website or because you messed up a lot of config files trying to migrate from 10.6 to 10.7. This is the reason of the existence of this tutorial. I couldn't get MAMP working properly, I didn't want to move my websites from ~/Sites to MAMP/htdoc and symlinks were failing. After reading hundreds of good and bad tutorials, here is a (hopefully) good way to get everything set up on your machine.
Summary of what we are going to do, before getting into the nitty gritty
Install Homebrew : /usr/bin/ruby -e "$(/usr/bin/curl -fksSL https://raw.github.com/mxcl/homebrew/master/Library/Contributions/install_homebrew.rb)". This is a utility similar to MacPorts. Many other tutorials to solve MAMP problems ask you to use MacPorts but it always broke somewhere for me and I always had a few dependencies missing.
brew install mysql
unset TMPDIR
mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp
sudo mkdir /var/mysql
sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock
Initialisation of MySQL with username "root" and password "root" (very common).
mysql.server start
mysqladmin -u root password root
mysqladmin -u root -h localhost
mysql.server start
This is optional, do it only if nothing works fine and you changed apache config files without knowing what you were doing (don't be ashamed, anyone does that, there is no need to try to understand what's really happening when typing all these commands).
rm -f ~/.pearrc
rm -rf ~/.pear
brew unlink php
brew install autoconf
sudo chmod a+w /usr/local/share/emacs/
sudo chmod a+w /usr/local/share/emacs/site-lisp/
brew link autoconf
brew tap josegonzalez/homebrew-php
brew install php --with-mysql --with-apache
open ~/.bashrc
Ajoutez ces deux lignes puis sauvegardez le fichier
alias pear="php /usr/lib/php/pear/pearcmd.php"
alias pecl="php /usr/lib/php/pear/peclcmd.php"
source ~/.bashrc
pear config-set auto_discover 1
pear update-channels
pear upgrade
sudo pecl install apc-beta mongo memcachepear install pear.phpunit.de/PHPUnit
sudo pear install PHP_CodeSniffer-beta
sudo pear install pear.phpunit.de/PHPUnit
brew link php
This is not optional.
Now that lots of stuff are installed, we need to tell Apache that our home directory for websites is ~/Sites, tell him to accept php5 and few other things.
sudo chmod a+w v /etc/apache2/httpd.conf
open /etc/apache2/httpd.conf
This opens a file. I advise that every time you change a line in a config file, you make a copy of the original line that you are modifying and comment it out just above your modification.
Same thing with /etc/php.ini :
sudo chmod a+w /etc/php.ini
open /etc/php.ini
The 2 last changes will enable you to use phpMyAdmin with databases larger than 2 or 8 Mo.
phpMyAdmin is like a little local website that helps you create, modify, ... your MySQL databases.
brew install phpmyadmin
mkdir /usr/local/share/phpmyadmin/config
sudo chmod o+w /usr/local/share/phpmyadmin/config
Create file :
open /etc/apache2/other/mod_phpmyadmin.conf
# changeThomas: empty file before AliasMatch ^/phpmyadmin(?:/)?(/.*)?$ "/usr/local/share/phpmyadmin$1"Options -Indexes AllowOverride None Order allow,deny Allow from all LanguagePriority fr en es de ja ko pt-br ru ForceLanguagePriority Prefer Fallback
phpMyAdmin needs libmcrypt (a php library) to run. Sorry for this fastidious part, even though almost optional, if you really can't make this part work move on things are gonna be ok but you will have ugly warnings in phpMyAdmin.
DownloadLibmcrypt and the last version of php.
Make a directory called SourceCache on your desktop and put them the 2 zip files and unzip them there.
Install Xcode 4.1 tools from the App Store.
cd ~/Desktop/SourceCache
MACOSX_DEPLOYMENT_TARGET=10.7 CFLAGS='-O3 -fno-common -arch i386 -arch x86_64' LDFLAGS='-O3 -arch i386 -arch x86_64' CXXFLAGS='-O3 -fno-common -arch i386 -arch x86_64' ./configure --disable-dependency-tracking
cd libmcrypt-2.5.8
MACOSX_DEPLOYMENT_TARGET=10.7 CFLAGS='-O3 -fno-common -arch i386 -arch x86_64' LDFLAGS='-O3 -arch i386 -arch x86_64' CXXFLAGS='-O3 -fno-common -arch i386 -arch x86_64' ./configure --disable-dependency-tracking
make -j6
sudo make install
cd ../php-5.3.6/
cd ext/mcrypt/
/usr/bin/phpize
MACOSX_DEPLOYMENT_TARGET=10.7 CFLAGS='-O3 -fno-common -arch i386 -arch x86_64' LDFLAGS='-O3 -arch i386 -arch x86_64' CXXFLAGS='-O3 -fno-common -arch i386 -arch x86_64' ./configure --with-php-config=/Developer/SDKs/MacOSX10.7.sdk/usr/bin/php-config
MACOSX_DEPLOYMENT_TARGET=10.7 CFLAGS='-O3 -fno-common -arch i386 -arch x86_64' LDFLAGS='-O3 -arch i386 -arch x86_64' CXXFLAGS='-O3 -fno-common -arch i386 -arch x86_64' ./configure --with-php-config=/usr/bin/php-config
make -j6
sudo make install
phpMyAdmin has just one little drawback : it asks for your password everytime you turn it on and then every 10 minutes. If you are the only one using your computer the best is to deactivate this.
Open /usr/local/share/phpmyadmin/config.inc.php and be sure you have these lines:
$cfg['Servers'][$i]['verbose'] = '';
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['port'] = '';
$cfg['Servers'][$i]['socket'] = '';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['extension'] = 'mysqli';
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = '';
$cfg['Servers'][$i]['AllowNoPassword'] = true;
$cfg['Servers'][$i]['AllowNoPasswordRoot'] = true;
You should be (almost) all set. Let's run everything now. For your website to run locally, you need to 1) start the apache server and 2) run a mysql server (if your website needs).
Apache can be started via Preferences Pane -> Sharing -> tick "web sharing", or via command line : sudo /usr/sbin/apachectl start (or restart or stop)
MySQL can be run with mysqld &
You can of course ask your system to fire them at start up time but your computer will be slightly slower to boot. If you want, "open /System/Library/LaunchDaemons/org.apache.httpd.plist" and throw this config in:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Disabled</key>
<true/>
<key>Label</key>
<string>org.apache.httpd</string>
<key>OnDemand</key>
<false/>
<key>ProgramArguments</key>
<array>
<string>/usr/sbin/httpd</string>
<string>-D</string>
<string>FOREGROUND</string>
<string<-D>/string>
<string<WEBSHARING_ON>/string>
</array>
<key>SHAuthorizationRight</key>
<string>system.preferences</string>
</dict>
</plist>
Watchout, mysqld fails to start when you didn't stop it before turning off your computer. You must open the activity monitor and quit it, or "ps | grep mysqld | grep -v 'grep' | cut -d" " -f3 | xargs kill {}; mysqld &" to kill and re-run it. Time to make an alias in your .bashrc !
Once this is all done, you should be able to access http://localhost/phpmyadmin/index.php and your websites !
If something is not working / I forgot a step, please don't hesitate to post a message here.
Thank you, you are welcome !
I advise Filezilla, it is a great free ftp client.
By the way, since the time I wrote this there is something slightly better for mac than the mysql command line. You can download something that gets installed in your pref pane (System preferences) to turn on and off the mysql server. http://dev.mysql.com/downloads/mysql/