LNMP development environment in the Mac OS to build the steps of the detailed

Source: Internet
Author: User
Tags imap install homebrew
This article mainly introduces the steps of setting up the LNMP development environment under Mac OS, through the step by step steps introduced in very detailed, for everyone has a certain reference value, the need for friends below to see it together.

I. Overview

Everyone should know that LNMP stands for: Linux system nginx+mysql+php this site server architecture. Linux is a class of UNIX computer operating system, is currently the most popular free operating system. The representative versions are: Debian, CentOS, Ubuntu, Fedora, Gentoo, etc. Nginx is a high-performance HTTP and reverse proxy server, also a IMAP/POP3/SMTP proxy server. MySQL is a small-scale relational database management system. PHP is a scripting language for embedded HTML documents that are executed on the server side. These four kinds of software are free open-source software, combined to become a free, efficient, scalable Web services system. Let's take a look at the details of this article.

Second, installation homebrew

An essential step for a programmer using a Mac is to install homebrew, which is like a CentOS command and an Ubuntu command, and yum apt-get brew We can quickly install some packages by command.

The commands to install homebrew using the command line are as follows:

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

Use brew doctor to check for conflicts and then brew update && brew upgrade upgrade with Brew.

Third, install Nginx

Nginx can be installed directly in Mac OS using the BREW command:

Brew Install Nginx

If you need to use port 80, you need to add nginx to the root group:

sudo cp-v/usr/local/opt/nginx/*.plist/library/launchdaemons/sudo chown root:wheel/library/launchdaemons/ Homebrew.mxcl.nginx.plist

Then use the command to start the Nginx service:

sudo nginx

Test that the Nginx installation was successful because the default profile listens on port 8080, so the request is initiated on port 8080:

Curl-il http://www.php.cn/:8080

The result should resemble the following:

http/1.1 Okserver:nginx/1.9.1date:fri, 14:50:47 gmtcontent-type:text/htmlcontent-length:612last-modif Ied:fri, 14:40:47 gmtconnection:keep-aliveetag: "5444dea7-264" accept-ranges:bytes

Nginx's related operations are as follows:

sudo nginx//start Nginxsudo nginx-s reload|reopen|quit//reload | restart | exit

Iv. installation of PHP-FPM

Because Brew does not have a source of php-fpm, you first add the source:

Brew Tap Homebrew/dupesbrew Tap homebrew/php

Then install PHP-FPM and enter the command:

Brew Install php56--whitout-apache--with-imap--with-tidy--with-debug--with-pgsql--with-mysql--with-fpm

The program installs automatically and waits a few minutes for the installation to complete.

After the installation is complete, you will also need to include PHP $PATH :

# If using bash, vim ~/.bash_profileexport path= "/usr/local/sbin: $PATH" source ~/.bash_profile# if using zsh, Vim ~/. Zshrcexport path= "/usr/local/sbin: $PATH" source ~/.ZSHRC

The PHP-FPM can then be set to boot from:

Mkdir-p ~/library/launchagentsln-sfv/usr/local/opt/php56/homebrew.mxcl.php56.plist ~/Library/LaunchAgents/ Launchctl load-w ~/library/launchagents/homebrew.mxcl.php56.plist

Use the following command to monitor whether the PHP-FPM started successfully:

Lsof-pni4 | grep LISTEN | grep php

If the startup succeeds, the following output should be similar:

PHP-FPM 27578 Wenzhiquan 9u IPv4 0xf29f8b26c08fc27  0t0 TCP 127.0.0.1:9000 (LISTEN) php-fpm 27628 Wenzhiquan 0u IPv4 0xf 29F8B26C08FC27  0t0 TCP 127.0.0.1:9000 (LISTEN) php-fpm 27629 Wenzhiquan 0u IPv4 0xf29f8b26c08fc27  0t0 TCP 127.0.0.1:9000 (LISTEN) php-fpm 27630 Wenzhiquan 0u IPv4 0xf29f8b26c08fc27  0t0 TCP 127.0.0.1:9000 (LISTEN)

V. Installation of MySQL

MySQL can also be installed directly using the BREW command:

Brew Install MySQL

Similarly, you can set up MySQL startup self-boot:

Ln-sfv/usr/local/opt/mysql/*.plist ~/library/launchagentslaunchctl Load ~/library/launchagents/ Homebrew.mxcl.mysql.plist

Then, for a secure installation of MySQL, you can change the root password, delete anonymous users, turn off remote connections, and so on using the following commands:

Mysql_secure_installation

It then outputs the following:

> enter current password to root (enter for none):  //default no password, direct carriage return > change the root password? [y/n]      Do you want to change the root password, select Yes, and then enter and confirm the password > Remove anonymous users? [y/n]       Do you want to delete the anonymous user, select Yes > Disallow root login remotely? [y/n]     Do you want to disable Telnet, select Yes > Remove Test database and access to it? [y/n]   Do you want to delete the test database and select Yes > Reload privilege tables now? [y/n]     Whether to reload the tabular data, select Yes

To test whether the database was successfully installed:

Mysql-u root-p

Then enter the root password you just set, and the following will be output:

Type ' help ', ' or ' \h ' for help. Type ' \c ' to clear the current input statement.mysql> exit   //Enter Exit to exit the database

Six, configuration Nginx

First, create some folders for our profile, these are directories modeled after the nginx structure of Ubuntu:

Mkdir-p/usr/local/etc/nginx/logsmkdir-p/usr/local/etc/nginx/sites-availablemkdir-p/usr/local/etc/nginx/ Sites-enabledmkdir-p/usr/local/etc/nginx/conf.dmkdir-p/usr/local/etc/nginx/sslsudo mkdir-p/var/wwwsudo chown: Staff/var/wwwsudo chmod 775/var/www

Then modify the Nginx configuration file:

Vim/usr/local/etc/nginx/nginx.conf

Replace the content with the following:

Worker_processes 1;error_log/usr/local/etc/nginx/logs/error.log debug;events {worker_connections 1024;} 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/etc/nginx/logs/access.log main; Sendfile on   ; keepalive_timeout; index index.html index.php; include/usr/local/etc/nginx/sites-enabled/*;}

Then create the PHP-FPM configuration file:

vim/usr/local/ect/nginx/conf.d/php-fpm

Enter the following:

Location ~ \.php$ {try_files  $uri = 404; fastcgi_pass 127.0.0.1:9000; Fastcgi_index index.php; Fastcgi_param Script_F Ilename $document _root$fastcgi_script_name; Include  Fastcgi_params;}

Then join the site configuration file:

Vim/usr/local/ect/nginx/sites-enabled/default

Enter the following:

server {listen;  server_name localhost; root  /var/www/; access_log/usr/local/etc/nginx/logs/ Default.access.log main; Location/{  include/usr/local/etc/nginx/conf.d/php-fpm;} location =/info {Allow  127.0.0.1;  Deny all;  Rewrite (. *)/.info.php; } error_page 404  /404.html; error_page 403  /403.html;}

Restart Nginx, at this point, the configuration is complete, write a test file under WWW, test can be

Summarize

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.