How to install LEMP on macOS Ventunra

LEMP stands for an open-source software bundle that consists of a Linux operating system, an Apache web server, a MySQL database system, and the PHP web programming language. It’s a powerful web development stack that you can use to create and deploy websites with dynamic webpages. You can use it to host your own website and to develop many other types of applications. In this tutorial, I will show you how to install LEMP on macOS Ventunra.

Part 1: Install Homebrew

1. Make sure your computer is powered on, then open the Terminal app.

2. Type the following command and press Enter:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

This will install Homebrew, a package manager for macOS.

3. After the installation finishes, type this command and press Enter to ensure all packages are up to date:

brew update

Part 2: Install Nginx

1. Install Nginx, the web server, by entering this command into the Terminal:

brew install nginx

2. Now start the Nginx service by typing this command:

sudo brew services start nginx

To reload nginx (restart nginx) on MacOs command:

sudo brew services reload nginx

3. You can now test that Nginx is working by entering this URL in your browser:

http://localhost

If you see an “Welcome to nginx!” page, then everything is working.

Part 3: Install MySQL

1. Install the MySQL database system using this command:

brew install mysql

2. After the installation finishes, type the following command to start the MySQL server:

sudo brew services start mysql

3. To secure the MySQL installation, type this command in the Terminal:

mysql_secure_installation

Part 4: Install PHP

1. To install PHP, enter this command in the Terminal:

brew install php

2. After the installation finishes, type this command to make sure the web server is aware of PHP:

sudo brew services restart nginx
sudo brew services start php

3. Now, you can test the php installation by creating a phpinfo page. Type the following command in the Terminal:

sudo echo "" > /usr/local/var/www/info.php

The current Php version in this post is php8.2

#MacOs Intel x86 Chipset
/usr/local/etc/php/8.2

#MacOs Apple Silicon M1 Chipset
/opt/homebrew/etc/php/8.2

4. Now open your browser and type this URL to view the phpinfo page:

http://localhost/info.php

If you can view the phpinfo page, then PHP is installed correctly.

5. Setup virtual host

server {
    listen 80;
    server_name  codezi.localhost;
    root "/Users/ngannv/_site/codezi.pro/public";
    index index.html index.htm index.php;
    error_log "/Volumes/Data/_logs/codezi.pro.error.log";
    proxy_busy_buffers_size   512k;
     proxy_buffers   4 512k;
     proxy_buffer_size   256k;
    client_max_body_size 30M;
     location / {
    	try_files $uri $uri/ /index.php?$query_string;
     }
     location ~ \.php$ {
        include        fastcgi.conf;
           fastcgi_pass   127.0.0.1:9000;
           fastcgi_index  index.php;
           include        fastcgi_params;
      }
    
    location ~ /\.ht {
        deny all;
    }
}

Congratulations! You have now successfully installed LEMP on macOS Ventunra.

Related posts:

  1. How to Install Composer on MacOS Ventura: 3 Different Ways
  2. How to install imagick extension on MacOs?
  3. How to install Yarn on MacOs?