Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use brew to build PHP Development Environment under Mac system

2025-02-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces "how to use brew to build the PHP development environment under the Mac system". In the daily operation, I believe that many people have doubts about how to use brew to build the PHP development environment under the Mac system. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "how to use brew to build the PHP development environment under the Mac system". Next, please follow the editor to study!

It is easy to build a lamp development environment under Mac. There is a ready-made integrated environment for xampp and mamp. However, the integrated environment will be very troublesome for developers who often need to customize some configurations, and Mac itself has its own apache and php, which is very easy to build manually with the help of brew and is highly controllable.

Brew

Brew to mac is like apt-get to ubuntu, a good helper to install software, can't be more convenient.

Brew is installed as follows:

The copy code is as follows:

Ruby-e "$(curl-fsSL https://raw.github.com/mxcl/homebrew/go/install)"

Common options for brew

The copy code is as follows:

Brew install xxx

Brew uninstall xxx

Brew list

Brew update xxx

Apache | | Nginx

Apache

For Apache, it is enough to use the basic features of mac. My system is 10.9. You can use the following command to control Apache.

The copy code is as follows:

Sudo apachectl start

Sudo apachectl restart

Sudo apachectl stop

The only thing to change is the home directory. Mac has a sites (site) directory under home by default, and the access path is

The copy code is as follows:

Http://localhost/~user_name

This is not suitable for development, modify / etc/apache2/httpd.conf content

The copy code is as follows:

DocumentRoot "/ Users/username/Sites"

Options Indexes MultiViews

AllowOverride All

Order allow,deny

Allow from all

In this way, the sites directory is the root directory of the website, and the code is thrown under it.

Nginx

To use Nginx is also more convenient, first install

The copy code is as follows:

Brew install nginx

The command to start and shut down Nginx is as follows (if you want to listen on port 80, you must run it as an administrator)

The copy code is as follows:

# Open nginx

Sudo nginx

# reload configuration | restart | stop | exit nginx

Nginx-s reload | reopen | stop | quit

# Test whether the configuration has syntax errors

Nginx-t

Configure Nginx

The copy code is as follows:

Cd / usr/local/etc/nginx/

Mkdir conf.d

Modify Nginx configuration file

The copy code is as follows:

Vim nginx.conf

The main modification position is the last include.

The copy code is as follows:

Worker_processes 1

Error_log / usr/local/var/log/nginx/error.log warn

Pid / usr/local/var/run/nginx.pid

Events {

Worker_connections 256

}

Http {

Include mime.types

Default_type application/octet-stream

Log_format main'$remote_addr-$remote_user [$time_local] "$request"'

'$status $body_bytes_sent "$http_referer"'

'"$http_user_agent"$http_x_forwarded_for"'

Access_log / usr/local/var/log/nginx/access.log main

Port_in_redirect off

Sendfile on

Keepalive_timeout 65

Include / usr/local/etc/nginx/conf.d/*.conf

}

Modify customization Fil

The copy code is as follows:

Vim. / conf.d/default.conf

Add a listening port

The copy code is as follows:

Server {

Listen 80

Server_name localhost

Root / Users/username/Sites/; # this item needs to be modified to prepare the path for you to store the relevant web pages.

Location / {

Index index.php

Autoindex on

}

# proxy the php scripts to php-fpm

Location ~\ .php$ {

Include / usr/local/etc/nginx/fastcgi.conf

Fastcgi_intercept_errors on

Fastcgi_pass 127.0.0.1:9000

}

}

The php site cannot be accessed at this time because php-fpm is not enabled yet.

Although mac 10.9 comes with php-fpm, because we use the latest PHP,PHP with built-in php-fpm, using php-fpm in PHP ensures version consistency.

The command here is executed after the next step of php is installed.

The copy code is as follows:

Sudo nginx

Sudo php-fpm-D

PHP

PHP is installed by default under mac, but it is difficult to control the version. Using brew, you can install the latest version or even multiple versions under mac. I installed php5.5.

The copy code is as follows:

Brew update

Brew tap homebrew/dupes

Brew tap josegonzalez/homebrew-php

# brew install php55-- with-fpm # Nginx

Brew install php55 # Apache

Then modify the cli path of php and the php module used by apache. Add the following to .bashrc or .zshrc

The copy code is as follows:

# export PATH= "$(brew-- prefix josegonzalez/php/php55) / bin:$PATH"

Export PATH= "/ usr/local/bin:/usr/local/sbin:$PATH"

Replace the php version of the system's default cli with the php you just installed. Then add under / etc/apache2/httpd.conf

The copy code is as follows:

LoadModule php5_module / usr/local/Cellar/php55/5.5.8/libexec/apache2/libphp5.so

This modifies the version of php used by apache.

Mongo and mysql will be used later, so you can install the php module directly using the following command, and other modules are similar

The copy code is as follows:

Brew install php55-mysql

Brew install php55-mongo

MySQL

Mac does not come with mysql. It needs to be reinstalled here, and the method is still very simple.

The copy code is as follows:

Brew install mysql

Unset TMPDIR

Mysql_install_db-verbose-user= `whoami`-basedir= "$(brew-prefix mysql)"-datadir=/usr/local/var/mysql-tmpdir=/tmp

Sudo chown-R your_user / usr/local/var/mysql/

The first sentence is installation, and the second is to ensure normal use. And then the start command.

The copy code is as follows:

Mysql.server start

It is best to give mysql a password as follows

The copy code is as follows:

Mysqladmin-u root password 'xxx'

If you want to modify the configuration of mysql, create a my.cnf under / usr/local/etc, such as adding log

The copy code is as follows:

[mysqld]

General-log

General_log_file = / usr/local/var/log/mysqld.log

MongoDB

MongoDB can be said to be the easiest one to execute directly

The copy code is as follows:

Brew install mongodb

Startup method

The copy code is as follows:

Mongod-fork

PHPMyAdmin

Phpmyadmin is almost the easiest web app to manage mysql, and I install it every time.

1. Go to the official website to download the latest version

two。 Decompress to ~ / Sites/phpmyadmin

3. Create a writable config directory under the phpmyadmin directory

4. Open http://localhost/phpmyadmin/setup, install a service, and save it finally (all you need to do here is enter the account password)

5. Move the config.inc.php generated under config to the phpmyadmin root directory

6. Delete config

This is installed, although it may be a little complicated, but once you get used to it.

You are likely to encounter a 2002 error here, but you can't find mysql.sock. Use the following methods to solve the problem

The copy code is as follows:

Sudo mkdir / var/mysql

Sudo ln-s / tmp/mysql.sock / var/mysql/mysql.sock

RockMongo

RockMongo is an easy-to-use web application for MongoDB and easy to install

1. Go to the official website to download the latest version

two。 Decompress to ~ / Sites/rockmongo

3. Just run http://localhost/rockmongo.

Complete

In this way, a php development environment is configured under mac, enjoy it!

At this point, the study on "how to use brew to build a PHP development environment under the Mac system" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report