Configure PHP+MySql environment under Mac

Since the PHP apache environment is built-in on Mac OS, there is no need to download the installation package elsewhere, just a simple configuration.

First open the terminal and enter the command:

view plaincopy

sudo vim /etc/apache2/httpd.conf
There is a line like this

view plaincopy

#LoadModule php5_module libexec/apache2/libphp5.so
Remove the preceding # sign.

Then open the sharing in the system preferences, and check the web sharing, as shown in the figure below



Restart apache, the command is as follows:

view plaincopy

sudo apachectl restart
Then you can enter http://localhost/ in the browser, if it

works! It

means success Configure the php environment

Let 's configure the MySql environment.

First download the dmg installation package of MySql. The download address is: http://dev.mysql.com/downloads/mysql/

Open the dmg file, there are three installation items, I will install all three here, after MySQLStartupItem.pkg is installed, mysql will automatically start with the system startup , MySQL.prefPane means that you can see the mysql option in the system preferences, and the other is the mysql installation item.

In this way, the installation is successful, open mysql in the system preferences, and enable the service. After installation, the default user name is root and the password is blank. For security, we set a password.

Open the terminal, if you enter the mysql prompt without this command, then you need to configure the environment variables of the mysql bin directory. The directory is, /usr/local/mysql/bin/, add it to the PATH variable. Here I introduce another method,

enter

view plaincopy

sudo vim /etc/bashrc in the terminal
and then add

view plaincopy

#mysql
alias mysql='/usr/local/mysql/bin/mysql'
alias mysqladmin='/usr /local/mysql/bin/mysqladmin'
In this way, entering mysql in the terminal will have this command. In fact, it is similar to the macro definition in our C/C++, and the alias is used instead.

Sometimes when the MySQL program is installed, directly inputting the command mysql or mysqladmin will find that the prompt command does not exist. This is because the system will look for the command under /usr/bin by default. If the command is not in this directory, of course it will not be found. command, all we need to do is map a link to the /usr/bin directory, which is equivalent to creating a link file.

First of all, you need to know the full path of the mysql command or mysqladmin command. For example, the path of mysql is: /usr/local/mysql/bin/mysql, we can execute the command like this:

view plaincopy

ln -s /usr/local/mysql/bin/mysql /usr/bin


Then we modify the root password, the command is as follows:

view plaincopy

mysqladmin -uroot password 12345
This changes the root password to 12345.

To manage Mysql, if you use The command line is more troublesome. The open source phpMyAdmin adopts the C/S mode, which is convenient for management. Then we install a phpMyAdmin. It is developed by php, and the download address is: http://www.phpmyadmin.net/home_page/downloads.php

Put the downloaded decompression in the /Library/WebServer/Documents/ directory, The complete directory is: /Library/WebServer/Documents/phpmyadmin/, then enter this directory from the command line,

and then enter the command:

view plaincopy

cp config.sample.inc.php config.inc.php
vim config.inc.php
Follow the steps below Modification:

view plaincopy

$cfg['blowfish_secret'] = ”;//For cookie encryption, arbitrary long string
$cfg['Servers'][$i]['host'] = '127.0.0.1';/ /MySQL daemon does IP binding

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327048562&siteId=291194637