Because of the recent need to decorate mantis for bug tracking, the process is documented here.
Because the PHP Apache environment is self-bringing on Mac OS, there is no need to install another package, simply configure it.
First open the Terminal input command:
sudo vim/etc/apache2/httpd.conf
One of them is like this.
#LoadModule Php5_module libexec/apache2/libphp5.so
Remove the previous # number.
Then open the share in System Preferences, put the Web share on the hook, as
To restart Apache, the command is as follows:
sudo apachectl restart
This allows you to enter http://localhost/in the browser, if any
It works!
Description of the successful configuration of the PHP environment
Below to configure the MySQL environment.
Download the DMG installation package for MySQL first. In: http://dev.mysql.com/downloads/mysql/
Open the DMG file, there are three installation items, which I installed in three, Mysqlstartupitem.pkg after installation, MySQL will start with the system boot, Mysql.prefpane indicates that you can see the MySQL option in System Preferences, and one is the MySQL installation.
This will make the installation successful, turn on MySQL in System Preferences, and turn the service on. After installation, the default username is root and the password is empty. For security, we set a password.
Open the terminal, if you enter the MySQL prompt without this command, then you need to configure the MySQL Bin directory environment variables. The directory is,/usr/local/mysql/bin/, added to the path variable. Here I'll show you another way,
Enter in the terminal
sudo vim/etc/bashrc
And then join them in
#mysqlalias mysql= '/usr/local/mysql/bin/mysql ' Alias mysqladmin= '/usr/local/mysql/bin/mysqladmin '
In this way, in the terminal to enter MySQL has this command, in fact, it is similar to our macro definition in C + +, the role of alias substitution.
Then we change the root password, the command is as follows:
Mysqladmin-uroot Password 12345
This changes the root password to 12345.
To manage MySQL, if the command line is more troublesome, open source phpMyAdmin use C/s mode, easy to manage. Then we put on a phpmyadmin. It was developed by PHP and is: http://www.phpmyadmin.net/home_page/downloads.php
The downloaded decompression is placed in the/library/webserver/documents/directory, the complete directory is:/library/webserver/documents/phpmyadmin/, then the command line into this directory,
Re-enter the command:
Follow the changes below:
$cfg [' blowfish_secret '] = ';//for Cookie encryption, random long string $cfg[' Servers ' [$i] [' host '] = ' 127.0.0.1 ';//mysql daemon does IP binding
You can now enter url:http://localhost/phpmyadmin/in the browser
The service name is: root
Password for the password you set.
You can login to the MySQL admin interface.
just started to contact with PHP only to find MacOS or more powerful, MacBook is not only fashionable products are also very practical oh.
--------------the stone of his mountain--------------------------
http://dancewithnet.com/2010/05/09/run-apache-php-mysql-in-mac-os-x/#php
Launch Apache
There are two ways of doing this:
- Open Web share (Web sharing), System settings Preferences (Preferences), sharing (sharing). Note that Web sharing (Web sharing) is canceled from Mac OS x starting with 10.8.
- Open terminal (terminal), then (note that sudo requires a password that is the root account password of the system)
- Run "
sudo apachectl start
", then enter the account password so that Apache runs.
- Run "
sudo apachectl -v
" and you will see the Apache version information for Mac OS X, as in 10.8.1:Server version: Apache/2.2.22 (Unix)Server built: Jun 20 2012 13:57:09
So enter "http://localhost" in the browser, you can see a content of "It works!" Page, which is located under/library (Resource Library)/webserver/documents/, which is the default root directory for Apache.
Running PHP
- Run "" In the terminal
sudo vi /etc/apache2/httpd.conf
to open the Apache configuration file. (If you are not accustomed to operating terminal and VI, you can set up in the Finder to display all system hidden files, remember to restart the Finder after Setup, and then you can find the corresponding files, the arbitrary editing, you need to note that some of the file changes or need to open the root account, However, it is more secure to use it on the terminal as a whole or sudo
to obtain root privileges temporarily. )
- Find "
#LoadModule php5_module libexec/apache2/libphp5.so
", remove the previous #, save (enter at the command line :w
) and Exit VI (AT command line input :q
).
- Run "
sudo cp /etc/php.ini.default /etc/php.ini
" so that you can run sudo vi /etc/php.ini
to edit php.ini to configure various functions. Like what:;通过下面两项来调整PHP提交文件的最大值,如phpMyAdmin中导入数据的最大值upload_max_filesize = 2Mpost_max_size = 8M;通过display_errors来控制是否显示PHP程序的报错信息,这在调试PHP程序时非常有用display_errors = Off
- Run "
sudo apachectl restart
" and restart Apache so that PHP can be used.
- Run "
sudo cp /Library/WebServer/Documents/index.html.en /Library/WebServer/Documents/info.php
", that is, copy the Index.html.en file in the root directory of Apache and rename it to info.php.
- Run "" In the terminal
sudo vi /Library/WebServer/Document/info.php
so that you can edit the info.php file in VI. In "It s works!" Add " <?php phpinfo(); ?>
" to the back and save it. So you can see the information about PHP in the http://localhost/info.php, such as the 10.8 built-in PHP version number is 5.3.13.
- For those unfamiliar with VI's editor, it's really annoying. I decided to next eclipse. VI has two modes, command mode and text editing mode. The ESC key is back to command mode, colon: I is the insert mode. You can overwrite the document. : W is saved,: Q exits.
Install MySQL
Mac OS x does not have built-in MySQL, so it needs to be installed manually, and the most stable version of MySQL is now 5.5. MySQL provides installation instructions under Mac OS x.
- Download MySQL 5.5. Select the appropriate version, if MYSQL-5.5.27-OSX10.6-X86_64.DMG is selected here.
- Run DMG and you will find 4 files inside. First click Install Mysql-5.5.27-osx10.6-x86_64.pkg, this is the main MySQL installation package. In general, the installation file will automatically install MySQL under
/usr/local
the folder with the same name. If run " mysql-5.5.27-osx10.6-x86_64.dmg
" will install MySQL to " /usr/local/mysql-5.5.27-osx10.6-x86_64
", the default installation is complete. (Note that starting from 10.8, Mac OS x has more restrictive permissions, and a direct click will prompt "Mysql-5.5.27-osx10.6-x86_64.pkg can ' t be opened because it's from a unidentified deve Loper. Your security preferences allow installation for only apps from the Mac App Store and identified developers. " Block the installation, you can use the two-finger click on the installation file, in the pop-up menu select "With ... Turn on (open with), and then select Install (Installer) to proceed with the installation. )
- Installing the 2nd file Mysqlstartupitem.pkg,mysql automatically starts at boot time. (Note that the 10.8 installation method is the same as above.) )
- Install the 3rd file Mysql.prefpane, you will see "MySQL" icon in "System Preferences", it can control whether MySQL is turned on, and whether it will run automatically when booting. The basic installation of MySQL is complete here. (Note that in 10.8, click the installation file with two fingers and select "Use ..." in the popup menu. Turn on (open with), and then select System perference to install it. )
- by running
sudo vi/etc/bashrc
, add mysqlstart
, MySQL
, and in the bash configuration file Mysqladmin the alias of the
(note: You need to exit "terminal (Terminal)" After the modification is complete, these commands will not take effect): #mysqlalias mysqlstart= ' sudo/ library/startupitems/mysqlcom/mysqlcom Restart ' Alias mysql= '/usr/local/mysql/bin/mysql ' Alias mysqladmin= '/usr/ Local/mysql/bin/mysqladmin '
This makes it easier to perform the corresponding operation in the terminal by command. Start installing mysqlstartupitem.pkg to "/library/startupitems/mysqlcom/
" to control MySQL running, autorun, stop, shutdown, and so on. Running the MySQL
or mysqladmin
command directly when MySQL is not started prompts " Can ' t connect to local MySQL server through Socket '/tmp/mysql.sock ' (2)
", so we can start MySQL via the control Panel or run the mysqlstart
command directly, then run MySQL
Or the mysqladmin
command is OK. For example, after installation, the default password for MySQL root
is empty, if you want to set the password can be run in the terminal " mysqladmin-u root password" Mysqlpassword "
" to set, Where Mysqlpassword is the root password. For more information, see b.5.4.1. How to Reset the Root Password.
Note: Mac OS x Upgrades or other reasons may cause MySQL to start or boot automatically when the MySQL operator panel will prompt " Warning:The /usr/local/mysql/data directory is not owned by the ‘mysql‘ or ‘_mysql‘
", this should be caused in some cases /usr/local/mysql/data
the host has changed, only need to run " sudo chown -R mysql /usr/local/mysql/data
".
Also, using PHP to connect MySQL may error "can ' t connect to local MySQL server through socket '/var/mysql/mysql.sock '", or using localhost can not connect to MySQL and need 127.0.0.1, because PHP by default when connecting to find /var/mysql/mysql.sock
, but the Mac version of MySQL changed the file location, placed in/tmp. The approach is to modify php.ini as follows:
mysql.default_socket = /tmp/mysql.sock
Using phpMyAdmin
phpMyAdmin is a PHP-developed program for managing MySQL, which is very popular and practical. Being able to manage MySQL with phpMyAdmin is a very effective way to test the previous steps.
- Download phpMyAdmin. Select the appropriate version, for example, choose phpmyadmin-3.5.22-all-languages.tar.bz2 this version.
- Extract the phpmyadmin-3.5.22-all-languages.tar.bz2 file from download (downloads) to "
/Library/WebServer/Documents/
" and change the name to phpMyAdmin.sudo tar -xf ~/Downloads/phpMyAdmin-3.5.2.2-all-languages.tar.bz2 -C /Library/WebServer/Documents/sudo mv /Library/WebServer/Documents/phpMyAdmin-3.5.2.2-all-languages /Library/WebServer/Documents/phpmyadmin
- Copy the
/Library/WebServer/Documents/phpmyadmin/
config.sample.inc.php in "" and name it config.inc.php
- Edit the config.inc.php and modify the following:
用于Cookie加密,随意的长字符串$cfg[‘blowfish_secret‘] = ‘a8b7c6d‘;当phpMyAdmin中出现“#2002 无法登录 MySQL 服务器(#2002 Cannot log in to the MySQL server)”时,请把localhost改成127.0.0.1就ok了,这是因为MySQL守护程序做了IP绑定(bind-address =127.0.0.1)造成的$cfg[‘Servers‘][$i][‘host‘] = ‘localhost‘;把false改成true,这样就可以访问无密码的MySQL了,即使MySQL设置了密码也可以这样设置,然后登录phpMyAdmin时输入密码$cfg[‘Servers‘][$i][‘AllowNoPassword‘] = false;
- This will allow you to
http://localhost/phpmyadmin
access the phpMyAdmin. You will see a prompt "Unable to load the mcrypt extension, please check your PHP configuration." (The MCrypt extension is missing. Please check your PHP configuration.) ", this will involve installing the mcrypt extension in the next section.
- Login name: root password: (empty)
关于错误处理:
Resolve. #2002 cannot log on to the MySQL server
Copy the config.sample.inc.php into config.inc.php
This error indicates that no connection to the database has occurred. Modify the config.inc.php file,
Will $cfg[' Servers ' [$i] [' host '] = ' localhost ';
Instead of $cfg[' Servers ' [$i] [' host '] = ' 127.0.0.1 ';
--------------------------------------------------
or
Modify Php.ini:mysql.default_socket =/tmp/mysql.sock
#1045 cannot log on to the MySQL server . Access denied for user ' root ' @ ' localhost ' (using Password:yes)
Cause: This may be due to the previous setting of the MySQL password is not successful, so we use the set MySQL root password can not log on to the server.
Workaround: You can then attempt to log into the database using the empty password of the MySQL default root account.
If you log in with a blank password, it appears: empty password login is forbidden (see allow null password) error. To modify the/phpmyadmin/config.inc.php file, locate the following two lines
$cfg [' Servers '] [$i] [' nopassword '] = false;
$cfg [' Servers '] [$i] [' allownopassword '] = false;
Change two false to True and set $cfg [' Servers '] [$i] [' password '] = '; After setting up the configuration file, phpMyAdmin will allow a blank password to log into the MySQL database.
If you re-login to phpmyadmin with a blank password, you may still not be able to log in, please clear the cookie or close the original phpMyAdmin login window and re-login with a blank password.
If this time still shows the blank password login is forbidden, try to enter a few characters as a password to see if the landing is successful.
Log in to MySQL server and change the MySQL password in phpMyAdmin as soon as possible.
Toss a long time Macos+apache+php+phpmyadmin finally succeeded!