Set up a WordPress blog with Nginx

CentOS7 配置Nginx域名HTTPS

Here is the revised guideline for setting up a WordPress blog with Nginx:

Step 1: Install Nginx, MySQL, and PHP (LEMP Stack)

  1. Install Nginx:

    bash 复制代码
    sudo yum install nginx
    sudo systemctl start nginx
    sudo systemctl enable nginx
  2. Install MySQL:

    bash 复制代码
    sudo yum install mariadb-server mariadb
    sudo systemctl start mariadb
    sudo systemctl enable mariadb
    sudo mysql_secure_installation
  3. Install PHP and PHP-FPM:

    bash 复制代码
    sudo yum install epel-release
    sudo yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
    sudo yum install yum-utils
    sudo yum-config-manager --enable remi-php74

sudo yum install php php-fpm php-mysql php-common php-cli php-json php-zip php-gd php-mbstring php-curl php-xml php-xmlrpc php-soap php-intl

php -v

sudo systemctl start php-fpm

sudo systemctl enable php-fpm

复制代码
### Step 2: Create a MySQL Database and User

1. **Log in to MySQL:**
```bash
sudo mysql -u root -p
  1. Create a database for WordPress:

    sql 复制代码
    CREATE DATABASE wordpress;
  2. Create a new MySQL user:

    sql 复制代码
    CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'password';
  3. Grant privileges to the new user:

    sql 复制代码
    GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';
    FLUSH PRIVILEGES;
    EXIT;

Step 3: Download and Configure WordPress

  1. Download the latest WordPress:

    bash 复制代码
    cd /usr/share/nginx/html
    sudo wget https://wordpress.org/latest.tar.gz
    sudo tar -xzf latest.tar.gz
    sudo mv wordpress/* .
    sudo rmdir wordpress
    sudo rm -f latest.tar.gz
  2. Set the correct permissions:

    bash 复制代码
    sudo chown -R nginx:nginx /usr/share/nginx/html
    sudo chmod -R 755 /usr/share/nginx/html
  3. Configure WordPress:

    bash 复制代码
    sudo cp wp-config-sample.php wp-config.php
    sudo nano wp-config.php

    Edit the following lines to include your database information:

    php 复制代码
    define('DB_NAME', 'wordpress');
    define('DB_USER', 'wpuser');
    define('DB_PASSWORD', 'password');
    define('DB_HOST', 'localhost');

Step 4: Configure Nginx for WordPress

  1. Create a new Nginx configuration file for your site:

    bash 复制代码
    sudo nano /etc/nginx/conf.d/wordpress.conf
  2. Add the following configuration:

    nginx 复制代码
    server {
        listen 80;
        server_name www.xxx.xyz;
        root /usr/share/nginx/html;
    
        index index.php index.html index.htm;
    
        location / {
            try_files $uri $uri/ /index.php?$args;
        }
    
        location ~ \.php$ {
            include /etc/nginx/fastcgi_params;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        }
    
        location ~ /\.ht {
            deny all;
        }
    }
  3. Test the Nginx configuration:

    bash 复制代码
    sudo nginx -t
  4. Restart Nginx:

    bash 复制代码
    sudo systemctl restart nginx

Step 5: Complete the WordPress Installation

  1. Open your browser and go to:

    复制代码
    http://www.xxx.xyz
  2. Follow the on-screen instructions to complete the installation:

    • Choose your language
    • Fill in the site title, username, password, and email
    • Click "Install WordPress"

Step 6: Configure Google AdSense

  1. Sign up for Google AdSense:

  2. Add your site to AdSense:

    • Enter your website URL
    • Follow the instructions to verify your site
  3. Get the AdSense code:

    • After your site is verified, get the AdSense code from your AdSense account
  4. Add AdSense code to WordPress:

    • Install a plugin like "Ad Inserter" or "Insert Headers and Footers" in WordPress
    • Go to the plugin settings and paste the AdSense code in the appropriate section
  5. Configure ad placements:

    • Use the plugin to choose where you want ads to appear on your site

Step 7: Write and Publish Your Blog Posts

  1. Log in to WordPress Admin:

    复制代码
    http://www.xxx.xyz/wp-admin
  2. Create a new post:

    • Go to Posts -> Add New
    • Write your content and publish
  3. Customize your site:

    • Go to Appearance -> Themes to choose a theme
    • Use the Customizer to adjust the look and feel of your site

By following these steps, you will have a WordPress blog up and running on your domain with Google AdSense configured to help generate passive income.

相关推荐
努力也学不会java2 小时前
【网络原理】 网络编程套接字
java·开发语言·网络·网络协议·tcp/ip·php
小余吃大鱼13 小时前
OpenStack私有云详细介绍
开发语言·php·openstack
我最厉害。,。18 小时前
PHP 反序列化&原生类 TIPS&字符串逃逸&CVE 绕过漏洞&属性类型特征
android·开发语言·php
2401_890665861 天前
免费送源码:Java+ssm+HTML 三分糖——甜品店网站设计与实现 计算机毕业设计原创定制
java·python·微信小程序·html·php·课程设计·android-studio
大G哥1 天前
PHP标签+注释+html混写+变量
android·开发语言·前端·html·php
傻啦嘿哟1 天前
HTTP代理基础:网络新手的入门指南
开发语言·php
BXCQ_xuan2 天前
Typecho博客网站头部SEO优化完整指南
运维·服务器·数据库·php·web
人类群星闪耀时2 天前
5G赋能远程医疗:从愿景到现实的技术变革
开发语言·5g·php
onejason2 天前
利用 PHP 爬虫按关键字搜索 1688 商品详情:实战指南
前端·php
foryoufeng2 天前
Laravel代码生成器,快速构建项目代码,统一团队编码风格
php·laravel