LNMP配置

编译安装LNMP,并安装wordpress

  1. 安装mariadb和php-fpm
    yum install mariadb-server php-fpm php-mysql -y

  2. 配置mariadb

        systemctl start mariadb
        mysql_secure_installation
        mysql -p123 -e "CREATE DATABASE wpdb;GRANT ALL ON wpdb.* TO 'wpdb'@'%' IDENTIFIED BY '123';"
    
  3. 下载并编译nginx源码1.16版

        # 安装编译环境
        yum install gcc pcre-devel openssl-devel zlib-devel -y
        # 解包
        tar -zxvf nginx-1.16.1.tar.gz
        # 增加nginx用户
        useradd -r -s /sbin/nologin nginx
        # 开始编译
        ./configure --prefix=/opt/nginx \
            --user=nginx \
            --group=nginx \
            --with-http_ssl_module \
            --with-http_v2_module \
            --with-http_dav_module \
            --with-http_stub_status_module \
            --with-threads \
            --with-file-aio \
            --with-http_realip_module \
            --with-http_gzip_static_module \
            --with-pcre \
            --with-stream \
            --with-stream_ssl_module \
            --with-stream_realip_module\
            --conf-path=/etc/nginx/nginx.conf \
            --error-log-path=/var/log/nginx/error.log \
            --http-log-path=/var/log/nginx/access.log \
            --pid-path=/var/run/nginx.pid \
            --lock-path=/var/run/nginx.lock
        make && make install
    
  4. 配置php-fpm
    更改/etc/php-fpm.d/www.conf

        user = nginx
        group = nginx
    

    systemctl start php-fpm

  5. 安装wordpress
    tar -zxvf wordpress-4.9.13.tar.gz -C /
    复制/wordpress/wp-config-sample.php到/wordpress/wp-config.php并更改内容

        /** The name of the database for WordPress */
        define('DB_NAME', 'wpdb');
        
        /** MySQL database username */
        define('DB_USER', 'wpdb');
        
        /** MySQL database password */
        define('DB_PASSWORD', '123');
        
        /** MySQL hostname */
        define('DB_HOST', 'localhost');
    

    setfacl -R -m u:nginx:rwx /wordpress

  6. 配置nginx
    ln -s /opt/nginx/sbin/nginx /usr/sbin/
    vim /etc/nginx/nginx.conf在server中

        listen 80;
        server_name www.chaoyi.com;
        location ~* \.php$ {
            root /wordpress;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
        } 
    

配置虚拟主机,www.chao.com域名实现首页访问,admin.chao.com域名实现wordpress的后台访问

在上一个配置基础上于http{}中加入

    server { 
        listen      80; 
        server_name admin.chaoyi.com;
        index wp-login.php;
        location ~* \.php$ {
            root /wordpress;
            fastcgi_pass 127.0.0.1:9000;                                      
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
        }
    }
posted @ 2020-03-14 12:54  stars_wisper  阅读(162)  评论(0编辑  收藏  举报