Overview
Mac system is very friendly to PHP, we only need to make simple configuration can start to use, this article will step by step to explain the installation and configuration of Apache, PHP and MySQL, pave the way for the start of development
Apache launches 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
Note: Because sudo is a system management instruction, you need to enter the computer password (input characters will not be displayed, enter the complete hit Enter)
Enter the following command in the terminal to view the Apache service version
sudo apachectl -v
In this machine, the version information is as follows
Server version: Apache/2.4.18 (Unix)Server built: Feb 20 2016 20:03:19
In the browser, enter the following URL to check whether the Apache service started successfully
http://localhosthttp://127.0.0.1
If the Apache service starts successfully, the page will show it works!
Apache other configuration off 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
Note 1: The author uses sublime text software for PHP development, and the software can open the configuration file directly
NOTE 2: If the prompt text lock does not allow the modification, you can copy the file to another folder after the modification, paste it back to overwrite the original file
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
PHP boot only needs to be configured in Apache service for direct use
First, locate and open the httpd.conf file in the /private/etc/apache2 directory
Second, the search #LoadModule php5_module libexec/apache2/libphp5.so, will be in front of the # Delete
/** If the permissions problem can not be modified, drag it to the desktop to modify, and then delete the original, and then drag the desktop into the inside to ok***///
Again, restart the Apache service to
Finally, let's create a new info.php test program under the path and try the results.
<?php phpinfo(); ?>
Enter the following URL in the browser to view PHP information
http://localhost/info.php
MySQL installation 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 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
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
-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
Start and stop MySQL services on the command line by starting and stopping the MySQL service with the following commands
sudo /usr/local/mysql/support-files/mysql.server startsudo /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 phpMyAdmin
First, enter the following URL in the browser, download the file shown in the diagram
https://www.phpmyadmin.net/downloads/
Next, unzip the compressed file into the /repository/webserver/documents/ path and rename it to phpMyAdmin
Again, rename the config.sample.inc.php file in the folder to config.inc.php
Again, modify the following code in the config.inc.php file
// 修改前:$cfg[‘Servers‘][$i][‘host‘] = ‘localhost‘;// 修改后:$cfg[‘Servers‘][$i][‘host‘] = ‘127.0.0.1‘;
Finally, enter the following URL in the browser to login to directly to the MySQL visual management
http://localhost/phpmyadmin/
Note: The default user name is root
Configure the PHP Runtime environment under MAC system