Detailed steps for establishing LNMP development environment under MacOS

Source: Internet
Author: User
Tags imap install homebrew website server
This article mainly describes how to set up the LNMP development environment under MacOS. the steps described in this article are very detailed and have some reference value for everyone, let's take a look. This article mainly describes how to build the LNMP development environment under Mac OS. the steps described in this article are very detailed and have some reference value for everyone, let's take a look.

I. Overview

We should all know that LNMP represents the website server architecture of Nginx + MySQL + PHP in Linux. Linux is a general term for a type of Unix computer operating system and is currently the most popular free operating system. Representative versions include debian, centos, ubuntu, fedora, and gentoo. Nginx is a high-performance HTTP and reverse proxy server and an IMAP/POP3/SMTP proxy server. Mysql is a small relational database management system. PHP is a script language for embedding HTML documents on the server. These four types of software are free and open-source software combined to become a free, efficient, and scalable website service system. Let's take a look at the details of this article.

II. install Homebrew

A Mac programmer must install Homebrew, which is like a centOSyumCommand and ubuntuapt-getThe command is the samebrewCommand, we can quickly install some software packages.

Run the following command to install Homebrew:

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

Usebrew doctorCheck whether there is a conflict, and then usebrew update && brew upgradeUpgrade brew.

3. install nginx

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

brew install nginx

To use port 80, 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 run the following command to start the nginx service:

sudo nginx

Test whether nginx is successfully installed. because the default configuration file listens to port 8080, you must first initiate a request to port 8080:

curl -IL #:8080

The result should be similar to the following:

HTTP/1.1 200 OKServer: nginx/1.9.1Date: Fri, 29 May 2015 14:50:47 GMTContent-Type: text/htmlContent-Length: 612Last-Modified: Fri, 29 May 2015 14:40:47 GMTConnection: keep-aliveETag: "5444dea7-264"Accept-Ranges: bytes

The nginx operations are as follows:

Sudo nginx // start nginxsudo nginx-s reload | reopen | quit // reload | restart | exit

4. install php-fpm

Because brew does not have a php-fpm source, you must first add the source:

brew tap homebrew/dupesbrew tap homebrew/php

Then install php-fpm and enter the following command:

brew install php56 --whitout-apache --with-imap --with-tidy --with-debug --with-pgsql --with-mysql --with-fpm

The program will be automatically installed. wait a few minutes until the installation is completed.

After the installation is complete, you also need to add php$PATHMedium:

# If bash is used, vim ~ /. Bash_profileexport PATH = "/usr/local/sbin: $ PATH" source ~ /. Bash_profile # vim ~ if ZSH is used ~ /. Zshrcexport PATH = "/usr/local/sbin: $ PATH" source ~ /. Zshrc

Then you can set the php-fpm to start automatically:

mkdir -p ~/Library/LaunchAgentsln -sfv /usr/local/opt/php56/homebrew.mxcl.php56.plist ~/Library/LaunchAgents/launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php56.plist

Run the following command to check whether php-fpm is successfully started:

lsof -Pni4 | grep LISTEN | grep php

If the startup is successful, 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 0xf29f8b26c08fc27  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. install MySQL

MySQL can also be directly installed using the brew command:

brew install mysql

Similarly, you can set the MySQL auto-start upon startup:

ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgentslaunchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

Then, run the following command to install MySQL securely. you can change the root password, delete anonymous users, and disable remote connections:

mysql_secure_installation

The following content is output:

> Enter current password for root (enter for none): // no password by default. press Enter to Change the root password? [Y/n] // do you want to change the root password? select yes and enter and confirm the password.> Remove anonymous users? [Y/n] // do you want to delete anonymous users? Select "Disallow root login remotely? [Y/n] // do you want to disable remote logon? choose> Remove test database and access to it? [Y/n] // do you want to delete the test database? select yes> Reload privilege tables now? [Y/n] // whether to overload table data. select yes

Test whether the database is successfully installed:

mysql -u root -p

Enter the root password you just set and the following content 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

6. Configure nginx

First, create some folders for our configuration files. these are directories created following 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:

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 65; 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 content:

location ~ \.php$ { try_files  $uri = 404; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param script_FILENAME $document_root$fastcgi_script_name; include  fastcgi_params;}

Then add the site configuration file:

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

Enter the following content:

server { listen  80; 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. now the configuration is complete. write a test file under www and perform the test.

Summary

The above is the detailed description of the steps for setting up the LNMP development environment in Mac OS. For more information, see other related articles in the first PHP community!

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.