Home>Article>Backend Development> Build Apache, PHP, MySQL5.6.22, phpMyAdmin development environment on MAC OSX10.10

Build Apache, PHP, MySQL5.6.22, phpMyAdmin development environment on MAC OSX10.10

PHP中文网
PHP中文网 Original
2017-05-23 14:44:18 2346browse

I am used to using an appserv or phpStudy compressed package on Windows, but I am not used to creating a PHP development environment on MAC. But there is still something to gain from setting up the environment yourself. As we all know, OSX comes with apache and php, so these two are relatively smooth. Installing the latest version of MySQL, version 5.6.22, is quite difficult, and this article records it in detail.

apache configuration

apache already comes with it, you only need the following three commands.
Start the apache servicesudo apachectl start
Stop the apache servicesudo apachectl stop
Restart the servicehttpd -v
After manually opening the apache service, enter localhost in the browser and you will see Go to the following:


The root directory of the program is under /Library/WebServer/Documents/. This It works is printed out by the info.php inside. The following describes how to change the default directory of apache to the user directory.Build Apache, PHP, MySQL5.6.22, phpMyAdmin development environment on MAC OSX10.101. Create a new Sites folder in your own user directory. My user directory is yanzi

2. Go to the cd /etc/apache2/users/ directory and sudo vim username.conf. The content is:

 AllowOverride AllOptions Indexes MultiViews FollowSymLinks Require all granted 

The yanzi in the first line above is the user directory. Then change the file permissions to 644:

sudo chmod 644 username.conf

3, go to the /etc/apache2/ directory, sudo vim httpd.conf and remove the comments of the following three sentences:
LoadModule authz_core_module libexec/apache2/ mod_authz_core.so

LoadModule authz_host_module libexec/apache2/mod_authz_host.so

LoadModule userdir_module libexec/apache2/mod_userdir.so
The first two sentences should be uncommented. Uncomment the third sentence.
Then find the Include /private/etc/apache2/extra/httpd-userdir.conf comment and release it.
PS: Just switch to command mode under vim and enter /"words you need find" to quickly find the words you need to find.

4. Go to the /etc/apache2/extra/ directory,
sudo vim httpd-userdir.conf

Uncomment the sentence Include /private/etc/apache2/users/*.conf.


Then enter in the terminal: sudo apachectl restart to restart apache, enter in the browser: loacal/~yanzi/ and you will see the effect. (yanzi is the name of my user directory,
No need to add /Sites after it

)

After the above steps, apache is ready.PHP configuration

PHP configuration is very simple, just one thing, go to the /etc/apache2/ directory, edit httpd.conf, find LoadModule php5_module libexec/apache2/libphp5.so and uncomment it.

Then sudo apachectl restart to restart, create a new index.php in the Sites folder of the user directory, echo phpinfo() in it, and you can see the effect:


Install MySQL5.6.22Build Apache, PHP, MySQL5.6.22, phpMyAdmin development environment on MAC OSX10.10

This version is the latest MySQL, the installation method is slightly different from that of 5.5. Download mysql-5.6.22-osx10.9-x86_64.dmg from the official website. The following is the installation method:

1. When double-clicking to install, do not check the StartUp Item:


After the installation is completed, in the settings - --MySQL Manually start the MySQL service.
Build Apache, PHP, MySQL5.6.22, phpMyAdmin development environment on MAC OSX10.10
I have opened the MySQL service here. Next, set it to start automatically at boot.
Build Apache, PHP, MySQL5.6.22, phpMyAdmin development environment on MAC OSX10.102. By default, we must enter the full path every time we use the mysql command, such as sudo /usr/local/mysql/support-files/mysql.server start to start the mysql service, /usr/local/mysql/bin /mysql -v To view the mysql version, you must first add the bin directory to the environment variable. Switch to the user root directory, vim .bash_profile, enter:
export PATH="/usr/local/mysql/bin:$PATH"

After saving, source .bash_profile makes the environment variable effective. Then you can enter the mysql command directly in the terminal.

Finally, set the password for the mysql root user through mysqladmin -u root password ‘yourpasswordhere’. The content in single quotes is the password to be set.


Note: Sometimes the above command cannot modify the root password, and you need to use phpmyadmin to modify it. In fact, the default root password for this version of mysql is root.

3, fix the socket error problem. There is a socket file responsible for communication between the mysql server and client. This version of mysql places it in the /tmp directory, but OSX looks for the /var/mysql directory by default, so a soft link must be created. Create a new directory /var/mysql, then sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock and it will be ok.

4. Let mysql start automatically when booting.
sudo vim /Library/LaunchDaemons/com.mysql.mysql.plist, enter the content:



KeepAlive

Label
com.mysql.mysqld
ProgramArguments

/usr/local/mysql/bin/mysqld_safe
–user=mysql



After saving, modify permissions:
sudo chown root:wheel /Library/LaunchDaemons/com.mysql.mysql.plist
sudo chmod 644 /Library/LaunchDaemons/com.mysql.mysql.plist
sudo launchctl load -w /Library/LaunchDaemons/com.mysql.mysql.plist
This way mysql will be ok!

Installation of phpMyAdmin

Download from http://www.phpmyadmin.net/home_page/downloads.php. I downloaded the version phpMyAdmin-4.4.2-all-languages.zip and unzipped it. Then change the name of the outermost folder to phpmyadmin, go to the directory ~/Sites/phpmyadmin, create a new folder: mkdir config, modify the read and write permissions: chmod o+w config
Then enter the browser: http://localhost/~ yanzi/phpmyadmin/setup/ (Note that yanzi in the middle is replaced with your own user name)
Build Apache, PHP, MySQL5.6.22, phpMyAdmin development environment on MAC OSX10.10
Click "New Server", I have already created it above, and then enter the mysql root user password in this interface:
Build Apache, PHP, MySQL5.6.22, phpMyAdmin development environment on MAC OSX10.10
Password . Then click "Apply", remember to click the save button on the following interface so that config.inc.php is generated in the config folder, and copy the file to the root directory of phpmyadmin.
Build Apache, PHP, MySQL5.6.22, phpMyAdmin development environment on MAC OSX10.10
Then delete the entire config folder. Enter http://localhost/~yanzi/phpmyadmin/ to see the interface for logging in to phpmyadmin. So, phpMyAdmin does it.

Reading and writing permissions and grouping issues

The last remaining issue is reading and writing permissions and ownership. If you develop and test locally, this step can be ignored. If you want your mac to actually function as a server, then this needs to be set up. This step is equivalent to making everything in the public_html folder writable and belonging to www when uploading Alibaba Cloud code. Assume that there is a project of its own under the Sites folder: testsite
sudo chmod -R a+w ~/Sites/testsite Set that everyone can read and write

sudo chown -R _www ~/Sites/testsite Set that the testsite folder only belongs to _www group.

OK, this is the end of setting up PHP on MAC.

References:
1.http://coolestguidesontheplanet.com/get-apache-mysql-php-phpmyadmin-working-osx-10-10-yosemite/
2.http://blog.csdn.net/henry121212 /article/details/9210193 (Refer to this without success)

Attached is a link to set up a php virtual host:
http://coolestguidesontheplanet.com/set-virtual-hosts-apache-mac-osx-10-10-yosemite /#apacheuser

In addition, if you accidentally installed it wrong, you can refer to the following to delete mysql:
http://www.cnblogs.com/TsengYuen/archive/2011/12/06/2278574.html

I am used to using an appserv or phpStudy compressed package on Windows, but I am not used to creating a PHP development environment on MAC. But there is still something to gain from setting up the environment yourself. As we all know, OSX comes with apache and php, so these two are relatively smooth. Installing the latest version of MySQL, version 5.6.22, is quite difficult, and this article records it in detail.

apache configuration

apache already comes with it, you only need the following three commands.
Start the apache servicesudo apachectl start
Stop the apache servicesudo apachectl stop
Restart the servicehttpd -v
After manually opening the apache service, enter localhost in the browser and you will see Go to the following:


The root directory of the program is under /Library/WebServer/Documents/. This It works is printed out by the info.php inside. The following describes how to change the default directory of apache to the user directory.Build Apache, PHP, MySQL5.6.22, phpMyAdmin development environment on MAC OSX10.101. Create a new Sites folder in your own user directory. My user directory is yanzi

2. Go to the cd /etc/apache2/users/ directory and sudo vim username.conf. The content is:

 AllowOverride AllOptions Indexes MultiViews FollowSymLinks Require all granted 

The yanzi in the first line above is the user directory. Then change the file permissions to 644:

sudo chmod 644 username.conf

3, go to the /etc/apache2/ directory, sudo vim httpd.conf and remove the comments of the following three sentences:
LoadModule authz_core_module libexec/apache2/ mod_authz_core.so

LoadModule authz_host_module libexec/apache2/mod_authz_host.so

LoadModule userdir_module libexec/apache2/mod_userdir.so
The first two sentences should be uncommented. Uncomment the third sentence.
Then find the Include /private/etc/apache2/extra/httpd-userdir.conf comment and release it.
PS: Just switch to command mode under vim and enter /"words you need find" to quickly find the words you need to find.

4. Go to the /etc/apache2/extra/ directory,
sudo vim httpd-userdir.conf

Uncomment the sentence Include /private/etc/apache2/users/*.conf.


Then enter in the terminal: sudo apachectl restart to restart apache, enter in the browser: loacal/~yanzi/ and you will see the effect. (yanzi is the name of my user directory,
No need to add /Sites after it

)

After the above steps, apache is ready.PHP configuration

PHP configuration is very simple, just one thing, go to the /etc/apache2/ directory, edit httpd.conf, find LoadModule php5_module libexec/apache2/libphp5.so and uncomment it.

Then sudo apachectl restart to restart, create a new index.php in the Sites folder of the user directory, echo phpinfo() in it, and you can see the effect:


Install MySQL5.6.22Build Apache, PHP, MySQL5.6.22, phpMyAdmin development environment on MAC OSX10.10

This version is the latest MySQL, the installation method is slightly different from that of 5.5. Download mysql-5.6.22-osx10.9-x86_64.dmg from the official website. The following is the installation method:

1. When double-clicking to install, do not check the StartUp Item:


After the installation is completed, in the settings - --MySQL Manually start the MySQL service.
Build Apache, PHP, MySQL5.6.22, phpMyAdmin development environment on MAC OSX10.10
I have opened the MySQL service here. Next, set it to start automatically at boot.
Build Apache, PHP, MySQL5.6.22, phpMyAdmin development environment on MAC OSX10.102. By default, we must enter the full path every time we use the mysql command, such as sudo /usr/local/mysql/support-files/mysql.server start to start the mysql service, /usr/local/mysql/bin /mysql -v To view the mysql version, you must first add the bin directory to the environment variable. Switch to the user root directory, vim .bash_profile, enter:
export PATH="/usr/local/mysql/bin:$PATH"

After saving, source .bash_profile makes the environment variable effective. Then you can enter the mysql command directly in the terminal.

Finally, set the password for the mysql root user through mysqladmin -u root password ‘yourpasswordhere’. The content in single quotes is the password to be set.


Note: Sometimes the above command cannot modify the root password, and you need to use phpmyadmin to modify it. In fact, the default root password for this version of mysql is root.

3, fix the socket error problem. There is a socket file responsible for communication between the mysql server and client. This version of mysql places it in the /tmp directory, but OSX looks for the /var/mysql directory by default, so a soft link must be created. Create a new directory /var/mysql, then sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock and it will be ok.

4. Let mysql start automatically when booting.
sudo vim /Library/LaunchDaemons/com.mysql.mysql.plist, enter the content:



KeepAlive

Label
com.mysql.mysqld
ProgramArguments

/usr/local/mysql/bin/mysqld_safe
–user=mysql



After saving, modify permissions:
sudo chown root:wheel /Library/LaunchDaemons/com.mysql.mysql.plist
sudo chmod 644 /Library/LaunchDaemons/com.mysql.mysql.plist
sudo launchctl load -w /Library/LaunchDaemons/com.mysql.mysql.plist
This way mysql will be ok!

Installation of phpMyAdmin

Download from http://www.phpmyadmin.net/home_page/downloads.php. I downloaded the version phpMyAdmin-4.4.2-all-languages.zip and unzipped it. Then change the name of the outermost folder to phpmyadmin, go to the directory ~/Sites/phpmyadmin, create a new folder: mkdir config, modify the read and write permissions: chmod o+w config
Then enter the browser: http://localhost/~ yanzi/phpmyadmin/setup/ (Note that yanzi in the middle is replaced with your own user name)
Build Apache, PHP, MySQL5.6.22, phpMyAdmin development environment on MAC OSX10.10
Click "New Server", I have already created it above, and then enter the mysql root user password in this interface:
Build Apache, PHP, MySQL5.6.22, phpMyAdmin development environment on MAC OSX10.10
Password . Then click "Apply", remember to click the save button on the following interface so that config.inc.php is generated in the config folder, and copy the file to the root directory of phpmyadmin.
Build Apache, PHP, MySQL5.6.22, phpMyAdmin development environment on MAC OSX10.10
Then delete the entire config folder. Enter http://localhost/~yanzi/phpmyadmin/ to see the interface for logging in to phpmyadmin. So, phpMyAdmin does it.

Reading and writing permissions and grouping issues

The last remaining issue is reading and writing permissions and ownership. If you develop and test locally, this step can be ignored. If you want your mac to actually function as a server, then this needs to be set up. This step is equivalent to making everything in the public_html folder writable and belonging to www when uploading Alibaba Cloud code. Assume that there is a project of its own under the Sites folder: testsite
sudo chmod -R a+w ~/Sites/testsite Set that everyone can read and write

sudo chown -R _www ~/Sites/testsite Set that the testsite folder only belongs to _www group.

OK, this is the end of setting up PHP on MAC.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn