Home Backend Development PHP Tutorial Detailed explanation of the steps to build LNMP development environment under Mac OS

Detailed explanation of the steps to build LNMP development environment under Mac OS

Mar 13, 2017 pm 04:38 PM

This article mainlyintroduces the steps to build an LNMP development environment under Mac OS. The article introduces the step-by-step steps in very detail and has certain reference value for everyone. Friends who need it can follow Let’s take a look together.

1. Overview

Everyone should know that LNMP stands for: LinuxNginx+# under the system ##MySQL+PHP is a website server architecture. Linux is the collective name for a class of Unix computer operating systems and is currently the most popular free operating system. Representative versions include: debian, centos, ubuntu, fedora, gentoo, etc. Nginx is a high-performance HTTP and reverse proxy server, as well as an IMAP/POP3/SMTP proxy server. Mysql is a small relational database management system. PHP is a scripting language that is executed on the server side and embedded in HTML documents. These four kinds of software are all free and open source software. When combined together, they become a free, efficient, and scalable website service system. Let’s take a look at the details of this article.

2. Install Homebrew

An essential step for programmers using Mac is to install Homebrew, he is like The

yum command of centOS is the same as the apt-get command of ubuntu. Through the brew command, we can quickly install some software packages.

The command to install Homebrew using the command line is as follows:

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

Use

brew doctor to check if there is a conflict, and then use brew update && brew upgradeUpgrade brew.

3. Install nginx

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

brew install nginx
Copy after login

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
Copy after login

Then use the command to start the nginx service:

sudo nginx
Copy after login

Test whether nginx is installed successfully, because the default

configuration file The listening port is 8080, so make a request to port 8080 first:

curl -IL http://www.php.cn/:8080
Copy after login

The result should be similar to the following:

HTTP/1.1 200 OK
Server: nginx/1.9.1
Date: Fri, 29 May 2015 14:50:47 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Fri, 29 May 2015 14:40:47 GMT
Connection: keep-alive
ETag: "5444dea7-264"
Accept-Ranges: bytes
Copy after login

nginx related operations are as follows:

sudo nginx //启动nginx
sudo nginx -s reload|reopen|quit //重新加载|重启|退出
Copy after login

4. Install php-fpm

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

brew tap homebrew/dupes
brew tap homebrew/php
Copy after login

Then install php-fpm, enter the command:

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

The program will be installed automatically, wait for a few minutes to complete the installation.

After the installation is complete, you need to add php to

$PATH:

# 如果使用bash的话
vim ~/.bash_profile
export PATH="/usr/local/sbin:$PATH"
source ~/.bash_profile

# 如果使用ZSH的话
vim ~/.zshrc
export PATH="/usr/local/sbin:$PATH"
source ~/.zshrc
Copy after login

Then you can set php-fpm to start automatically at boot:

mkdir -p ~/Library/LaunchAgents
ln -sfv /usr/local/opt/php56/homebrew.mxcl.php56.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php56.plist
Copy after login

Use the following command to monitor whether php-fpm starts successfully:

lsof -Pni4 | grep LISTEN | grep php
Copy after login

If it starts successfully, there should be output similar to the following:

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)
Copy after login

5. Install MySQL

MySQL can also be installed directly using the brew command:

brew install mysql
Copy after login

Similarly, you can set MySQL to start automatically at boot:

ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
Copy after login

Then perform a safe installation of MySQL, Use the following command to change the root password, delete anonymous users, close remote connections, etc.:

mysql_secure_installation
Copy after login

Then the following content will be output:

> Enter current password for root (enter for none):  //默认没有密码,直接回车即可
> Change the root password? [Y/n]      //是否更改root密码,选择是,然后输入并确认密码
> Remove anonymous users? [Y/n]       //是否删除匿名用户,选择是
> Disallow root login remotely? [Y/n]     //是否禁止远程登录,选择是
> Remove test database and access to it? [Y/n]   //是否删除test数据库,选择是
> Reload privilege tables now? [Y/n]     //是否重载表格数据,选择是
Copy after login

Test whether the database is installed successfully:

mysql -u root -p
Copy after login

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

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> exit   //输入exit退出数据库
Copy after login

6. Configure nginx

First, for Our configuration file creates some folders. These are directories modeled after Ubuntu's nginx structure:

mkdir -p /usr/local/etc/nginx/logs
mkdir -p /usr/local/etc/nginx/sites-available
mkdir -p /usr/local/etc/nginx/sites-enabled
mkdir -p /usr/local/etc/nginx/conf.d
mkdir -p /usr/local/etc/nginx/ssl

sudo mkdir -p /var/www
sudo chown :staff /var/www
sudo chmod 775 /var/www
Copy after login

Then modify the nginx configuration file:

vim /usr/local/etc/nginx/nginx.conf
Copy after login

Replace the content with:

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/*;
}
Copy after login

Then create the php-fpm configuration file:

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

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;
}
Copy after login

Then add the site configuration file:

vim /usr/local/ect/nginx/sites-enabled/default
Copy after login

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;
}
Copy after login

Restart nginx. At this point, the configuration is completed. Write a test file under www and test it

Summary

The above is the detailed content of Detailed explanation of the steps to build LNMP development environment under Mac OS. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

No response when entering password on mac keyboard? No response when entering password on mac keyboard? Feb 20, 2024 pm 01:33 PM

Introduction: In this article, this website will introduce to you the relevant content about the Mac keyboard not responding when entering passwords. I hope it will be helpful to you, let’s take a look. How to solve the problem that the password cannot be entered on the Apple Mac system? You can also try to connect this keyboard to other computers to see if it works normally. If the same problem occurs on another computer, it's most likely a fault with the keyboard itself. You may consider replacing the keyboard or repairing it. The first time you log in to Alipay with your Mac computer, you will find the login interface and cannot enter your password. The password input field displays: "Please click here to install the control", so Alipay login requires the installation of security controls. Security controls can encrypt and protect the information you enter (amount, password, etc.) to improve account security. Tie

3 tips to easily customize your Mac computer name, host name and Bonjour name 3 tips to easily customize your Mac computer name, host name and Bonjour name Mar 06, 2024 pm 12:20 PM

Many Mac users tend to keep the default name of their device and may never consider changing it. Many people choose to stick with the name from the initial setup, such as "Johnny's MacBook Air" or simply "iMac." Learning how to change the name of your Mac is a very useful skill, especially when you have multiple devices, as it can help you quickly distinguish and manage them. Next, we will teach you step by step how to change the computer name, host name and Bonjour name (local host name) in macOS system. Why should you change your Mac name? Changing the name of your Mac can not only show your personality, but also help improve the user experience: Personalize your Mac: The default name may not be to your taste, change it to a name you like.

Forgot your mac installer password? Forgot your mac installer password? Feb 20, 2024 pm 01:00 PM

Introduction: In this article, this website will introduce to you the relevant content about forgetting the password of the Mac installation program. I hope it will be helpful to you, let’s take a look. What to do if you forget your password for Apple computer installation software. First, find iCloud in the phone settings and click to open it. Next, enter your account number and password. There is a line of small words below the login button that prompts you if you have forgotten your ID or password. Click this option. Normally, after you enter an incorrect password multiple times on the login interface, your MacBook Pro will prompt you to use your bound Apple ID to reset your password. You only need to follow the steps prompted by the system to complete the password reset. 3. First shut down your Mac, then restart it. While pressing the power button, immediately press and hold com on the keyboard.

pkg file to install on mac? pkg file to install on mac? Feb 20, 2024 pm 03:21 PM

Preface: Today, this site will share with you the relevant content about installing pkg files on Mac. If it can solve the problem you are facing now, don’t forget to follow this site and start now! The previous version of macos pkg cannot be installed to upgrade the operating system: If your laptop is using an older operating system version, it is recommended to upgrade to the latest operating system version. Because older versions may not support installation of the latest macOS system. Select "Erase" in Disk Utility, then select the Macos extension in the format, do not check the encryption option, and do not select the apfs format, and finally click the "Erase" button to solve the problem of being unable to complete the macOS installation. Drag the application's icon to the file starting with App

How to set up WeChat Mac to automatically convert voice messages into text - How to set up voice to text conversion How to set up WeChat Mac to automatically convert voice messages into text - How to set up voice to text conversion Mar 19, 2024 am 08:28 AM

Recently, some friends have consulted the editor about how to set up WeChat Mac to automatically convert voice messages into text. The following is a method for setting up WeChat Mac to automatically convert voice messages into text. Friends in need can come and learn more. Step 1: First, open the Mac version of WeChat. As shown in the picture: Step 2: Next, click "Settings". As shown in the picture: Step 3: Then, click "General". As shown in the picture: Step 4: Then check the option "Automatically convert voice messages in chat to text". As shown in the picture: Step 5: Finally, close the window. As shown in the picture:

Can Mac cut files to hard drive? Can Mac cut files to hard drive? Feb 20, 2024 pm 01:00 PM

Introduction: This article is here to introduce you to the relevant content of cutting files to the hard disk on Mac. I hope it will be helpful to you, let’s take a look. How to Export Photos to a Mobile Hard Drive on a Mac Computer You can use the Finder or Photos application to export photos to a mobile hard drive. When using Finder to export photos, first make sure the mobile hard drive is connected to the Mac and is successfully recognized by the Mac. The steps to transfer photos from Mac to hard drive are simple: first, connect the mobile hard drive to the computer, and then open the [Launcher] icon. Then, find and click the [Photos] icon in the pop-up window. In the opened [Photos] window, hold down the [Shift] key

Mac black apple boot method? Mac black apple boot method? Feb 20, 2024 pm 01:00 PM

Preface: This article is here to introduce you to the relevant content about the mac black apple boot method. I hope it will be helpful to you, let’s take a look. Black Apple OC boot quick configuration tutorial 1. After entering the loverconfigurator software interface, click on the "Boot Parameters" setting. The default boot volume name is set to the disk name that was erased when installing the Black Apple system. But Benjuannai? 0, then click Save in the lower right corner, restart the computer, and replace the lover boot interface with the Apple logo boot interface. Secure Boot effectively prevents unsigned bootloaders from booting from any internal disk or USB drive. However, Clover or OC boot does not support the secure boot function. To start

Mac configuration file does not take effect? Mac configuration file does not take effect? Feb 20, 2024 pm 02:00 PM

Introduction: This article will introduce to you the relevant content about the mac configuration file not taking effect. I hope it will be helpful to you, let's take a look. The solution to the problem that environment variables cannot take effect under Mac. After configuring environment variables in the Mac system, it is found that they are only effective in the current terminal and will become invalid once the terminal is switched. After inquiry, it was found that the Mac system is pre-installed with a tool called ultimate shell-zsh, and the reading of environment variables needs to be set in the .zshrc file. 2. In order for our configuration file to take effect, we can only add the above configuration in .zshrc. If you don’t make the above settings, you will find that it will only take effect every time you source ~/.bash_profile. Re-open z next time.

See all articles