Friday 1 March 2013

MacPorts - PHP, Apache & MySQL

Hi,

These some tutorials how to install lamp server using MarPorts:
  1. Install MacPorts:
    1. Install Xcode
    2. Launch Xcode > Preferences > Downloads > Install 'Command Line Tools'
    3. Go to MacPorts website and follow their structure to install MacPorts: http://www.macports.org/install.php
  2. Install PHP & Apache:
    1. sudo port install php5 +apache2 +mcrypt +curl +tidy +pear
    2. sudo port load apache2
    3. cd /opt/local/apache2/modules
    4. sudo /opt/local/apache2/bin/apxs -a -e -n "php5" libphp5.so
    5. sudo cp /opt/local/etc/php5/php.ini-development /opt/local/etc/php5/php.ini
    6. sudo nano /opt/local/apache2/conf/httpd.conf
      1. Go to line 119 (In Nano: CTRL+w then CTRL+t and write 119), and enter the following lines:
        • AddType application/x-httpd-php .php
        • AddType application/x-httpd-php-source .phps
    7. Now, change DocumentRoot from:
      1. From: DocumentRoot "/opt/local/apache2/htdocs"
      2. To: DocumentRoot "/Users/Shin/sites"
    8. Since we just change the documentRoot folder, we need to adjust some more settings
      1. From: <Directory “/opt/local/apache2/htdocs”>
      2. To: <Directory “/Users/Shin/Sites”>
    9. Now all we have left to do is setting the User and Group. Exchange the following:
      1. From:
        • User www
        • Group www
      2. To:
        • User Shin
        • Group staff
    10. sudo /opt/local/apache2/bin/apachectl restart
  3. Install MySQL:
    1. sudo port install mysql5 +server
    2. sudo -u mysql mysql_install_db5
    3. sudo chown -R mysql:mysql /opt/local/var/db/mysql5/
    4. sudo chown -R mysql:mysql /opt/local/var/run/mysql5/
    5. sudo chown -R mysql:mysql /opt/local/var/log/mysql5/
      • If that doesn’t work try this:
        • sudo mysql_install_db5 sudo chown -R mysql:mysql /opt/local/var/db/mysql5/
        • sudo chown -R mysql:mysql /opt/local/var/run/mysql5/
    6. sudo port load mysql5-server
    7. sudo ln -s /opt/local/bin/mysql5 /opt/local/bin/mysql
    8. sudo ln -s /opt/local/bin/mysqladmin5 /opt/local/bin/mysqladmin
    9. Change new root password:
      • mysqladmin5 -u root password 'new-password'
  4. Some small bugs:
    1. httpd: Could not reliably determine the server's fully qualified domain name, using <Computer-Name>.local for ServerName
      1. sudo vim /opt/local/apache2/conf/httpd.conf
        • ServerName localhost:80
    2. If you would like to be able to access web pages in the Sites directory of your home directory
      1. sudo vim /opt/local/apache2/conf/httpd.conf
        • Include conf/extra/httpd-userdir.conf
    3. ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
      1. sudo vim /opt/local/etc/mysql5/my.cnf
        • [mysqld_safe]
        • socket = /tmp/mysql.sock
        • [client]
        • socket = /tmp/mysql.sock
      2. sudo vim /opt/local/etc/php5/php.ini 
        • mysqli.default_socket = "/tmp/mysql.sock"
Good luck!

No comments:

Post a Comment