The OSX system is very friendly to PHP, we only need simple configuration to start using, this article will step by step to explain the installation and configuration of Apache, PHP and MySQL, paving the way for the start of development
Apache
Launch Apache Service
The Apache service is already installed on the MAC system and we just need to launch it directly using the following method
Enter the following command in the terminal to launch the Apache service
sudo apachectl start
Enter the following command in the terminal to view the Apache service version
sudo apachectl -v
In the browser, enter the following URL to check whether the Apache service started successfully
http://localhost http://127.0.0.1
If the Apache service starts successfully, the page will show it works!
Other configurations for Apache
Close Apache Service
Close the Apache service by entering the following command in the terminal
sudo apachectl stop
Restart Apache Service
Restart the Apache service by entering the following command in the terminal
sudo apachectl restart
Apache Service installation Path
Apache Service default installation path in /private/etc/apache2, belongs to the system Private directory, we do not find the path directly in the Finder
We can enter the path in two ways
Enter the OPEN/ETC command into the ETC folder in the terminal
Enter/etc in the go to folder from Finder, go to etc folder
Apache Service Deployment Path
Apache Service deployment path in /resource pool/webserver/documents/, our project needs to be placed under this path
If you want to modify the deployment path, you can find and open the httpd.conf file in the /private/etc/apache2 directory, search for documentroot , and modify the deployment path
Apache Service port number
The Apache service port number defaults to 80, if you want to modify the port number, you can find and open the httpd.conf file in the /private/etc/apache2 directory, search for Listen and modify the port number
Php
Before running our PHP, we need to change our PHP configuration file, open Finder, "Go to Folder ...", enter:
- /etc/apache2/
Then find our httpd.conf configuration file:
Using a text editor, cancel the following line of comments:
- LoadModule Php5_module libexec/apache2/libphp5.so
After the configuration file has been modified, we just need to restart our Apache service to let the changes take effect, in terminal input:
- sudo apachectl restart
Next we want to know the version of PHP on our Mac.
- Copy the Index.html.en file and rename it to info.php in the root directory of Apache.
- sudo cp/library/webserver/documents/index.html.en/library/webserver/documents/info.php
Open our info.php file and add it with a text editor after "It Works":
- <?php phpinfo ();?>
Then restart our Apache again. After rebooting, we enter in the browser URL bar:
- http://localhost/info.php
We can see:
Mysql
Install MySQL
First, enter the following URL in the browser, download the file shown in the diagram and install
http://dev.mysql.com/downloads/mysql/
Next, enter the following command in the terminal to view the MySQL version
mysql --version
In this machine, the version information is as follows
mysql Ver 14.14 Distrib 5.7.14, for osx10.11 (x86_64) using EditLine wrapper
If you are prompted to command not found, this is because the command accesses MySQLunder the /usr/local/bin/mysql path By default, so we can enter the following command at the terminal, Create a soft link to
sudo ln -fs /usr/local/mysql/bin/mysql /usr/local/bin/mysql
Once again, log in to the MySQL service with the user and password that was given when you installed MySQL, enter the following command in the terminal, enter the password after hitting enter
mysql -u root -p
Again, enter the following command in the terminal to exit the MySQL service
exit
Finally, enter the following command in the terminal to change the password to your own password
/usr/local/mysql/bin/mysqladmin -u USER -p password PASSWORD
Note: User is the username, default is root; Password for the new password, enter the original password can be
MySQL Start and stop
Start and stop the MySQL service by entering the following commands at the command line
sudo /usr/local/mysql/support-files/mysql.server start sudo /usr/local/mysql/support-files/mysql.server stop
Start and stop the MySQL service in System Preferences
There is a MySQL option in System Preferences, where we can manually start and stop the MySQL service
MySQL Visual management mode Navicat
I. Installing NAVICAT Premium https://www.navicat.com.cn/download/navicat-premium
Two. Open the folder to /Applications/Navicat\ Premium.app/Contents/MacOS/
replace the Navicat Premium file
Mac OS Navicat Premium 11.2.15 Simplified Chinese hack file http://download.csdn.net/detail/panshiqu/9671145
(phpMyAdmin configuration method does not elaborate, the web host on the MySQL database management tools, I personally more accustomed to Navicat interface)
Apache+php+mysql+navicat configuration under OSX system