Setup Apache, PHP, MySQL and WordPress on Mac OS X 10.8.3

来源:互联网 发布:windows oxc0000428 编辑:程序博客网 时间:2024/05/23 18:33

Part I : Launch Apache

case 1:  'System Preferences' –> 'Sharing' –> 'Web Sharing';

case 2: launch terminal

  1.  run 'sudo apachectl start',input root password;
  2.  run 'sudo apachectl -v',check Apache version info on Mac.

then, input 'http://localhost' or 'http://127.0.0.1' in Safari, 'It works!' will display on the Page, which can be located in '/Library/WebServer/Documents/', it is the root Directory of Apache.

Part II : Launch PHP

1. run 'sudo vi /etc/apache2/httpd.conf', then unconment '#LoadModule php5_module libexec/apache2/libphp5.so';

2. run 'sudo cp /etc/php.ini.default /etc/php.ini', the you can edit file 'pho.ini', for example:

*************************************

upload_max_filesize = 2M

post_max_size = 8M 

display_errors = Off

*************************************

3. run 'sudo apachectl restart',restart Apache,PHP will be OK;

4. run 'sudo cp /Library/WebServer/Documents/index.html.en /Library/WebServer/Documents/info.php',and run 'sudo vi /Library/WebServer/Document/info.php',edit info.php with '<?php phpinfo(); ?>',then you can check it from 'http://localhost/info.php' in Safari.

Part III : Install Mysql

1. download 'mysql-5.5.3-osx10.6-x86_64.dmg'; 

2. set up 'mysql-5.5.3-osx10.6-x86_64.pkg',  it will be located at '/usr/local';

3. set up 'MySQLStartupItem.pkg';

4. set up 'MySQL.prefPane', you can check it from 'System Preferences';

5. run 'sudo vi /etc/bashrc',add alias name for mysqlstart, mysql and mysqladmin in 'bashrc', you need restart Terminal.

*************************************

#mysql

alias mysqlstart='sudo /Library/StartupItems/MySQLCOM/MySQLCOM restart'

alias mysql='/usr/local/mysql/bin/mysql'

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

*************************************

6. run 'mysqladmin -u root password 'password''; run 'mysql -u root -p', and input your password; run 'create database yourdb;'; run 'grant all privileges on yourdb.* to yourusername@localhost;'; run 'use yourdb;'; run 'SET PASSWORD FOR 'yourusername'@'localhost' = PASSWROD('pw');'; 

7. run 'sudo mkdir /var/mysql'; run 'sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock';

8. import your own mysql database: run 'mysql -u yourusername -p;'; run 'use yourdb;'; run 'source all.sql;';

Note: in file 'all.sql', you can edit like below,

*************************************

source first.sql;

source second.sql;

……

*************************************

Part IV : Install WordPress

1. run 'mkdir ~yourusername/Sites'; copy your wordpress directory into '~yourusername/Sites/'; run 'sudo vi /etc/apache2/users/yourusername.conf', input like below:

*************************************

<Directory "/Users/yourusername/Sites/">
    Options Indexes MultiViews
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

*************************************

2. run 'sudo apachectl restart'; 

3. Solve WordPress "Error establishing a database connection", check file 'wp-config.php' like below:

/** MySQL database username */

define('DB_USER', 'yourusername');

/** MySQL database password */
define('DB_PASSWORD', 'pw');

/** MySQL hostname */
define('DB_HOST', 'localhost');

/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');

/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', '');

4.  Change your Server address:

~download all the files from old Server;

~export all the databases with phpmyadmin;

~upload all the files to new Server;

~create new database, and import all your databases;

~update wp-config.php;

~'mysql -u yourusername -p'; 'UPDATE wp_options SET option_value = replace( option_value, 'http://oldadress', 'http://newadress') WHERE option_name = 'home' OR option_name ='siteurl';'

~'UPDATE wp_posts SET post_content = replace(post_content, 'http://oldadress', 'http://newadress');UPDATE wp_posts SET guid = replace( guid, 'http://oldadress' , 'http://newadress' ) ;'