wordpress using nginx php mysql on macos

 

🧰 Prerequisites (via Homebrew)

Open Terminal and install the essentials:

bash
brew install nginx mysql php unzip

Start services:

bash
brew services start nginx brew services start mysql brew services start php

Optional: You can check versions with nginx -v, mysql --version, php -v.


🗃️ Create a MySQL Database for WordPress

bash
mysql -u root

Then inside MySQL shell:

sql
CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci; CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'wppassword'; GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost'; FLUSH PRIVILEGES; EXIT;

📥 Download and Place WordPress

bash
cd /usr/local/var/www curl -O https://wordpress.org/latest.zip unzip latest.zip mv wordpress wordpress.local rm latest.zip

You now have the site files in:
/usr/local/var/www/wordpress.local


🔧 Configure Nginx

Nginx config lives at:

swift
/opt/homebrew/etc/nginx/nginx.conf

To avoid cluttering the main file, add a new server config in:

swift
/opt/homebrew/etc/nginx/servers/wordpress.local.conf

If servers directory doesn't exist yet:

bash
mkdir -p /opt/homebrew/etc/nginx/servers

Then create the config file:

bash
nano /opt/homebrew/etc/nginx/servers/wordpress.local.conf

Paste this:

nginx
server { listen 80; server_name wordpress.local; root /usr/local/var/www/wordpress.local; index index.php index.html; location / { try_files $uri $uri/ /index.php?$args; } location ~ \.php$ { include fastcgi_params; fastcgi_pass 127.0.0.1:9000; # default for php-fpm fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } location ~ /\.ht { deny all; } }

Then include this directory in your nginx.conf:

Edit /opt/homebrew/etc/nginx/nginx.conf, and inside the http {} block, make sure this is there:

nginx
include servers/*;

🧠 Map Domain to Localhost

Edit /etc/hosts:

bash
sudo nano /etc/hosts

Add:

lua
127.0.0.1 wordpress.local

🔁 Restart Nginx

bash
brew services restart nginx

🚀 Final Step: Visit in Browser

Go to:
http://wordpress.local

You’ll see the WordPress installation screen. Use:

  • DB Name: wordpress

  • Username: wpuser

  • Password: wppassword

  • DB Host: localhost

And that’s it! WordPress will finish installing and you’ll be ready to develop locally.

Comments

Popular posts from this blog

wordpress setup