GNU/Linux >> Linux の 問題 >  >> Cent OS

最大のパフォーマンスを得るために、CentOS 6 VPSでLEMP(Nginx、PHP-FPM + APC、およびMySQL)スタックを使用してWordPress+W3TotalCacheを実行します

Nginx は無料のオープンソースの高性能HTTPウェブサーバーです。 他の一部のウェブサーバーとは異なり、リクエストのスレッド処理に依存せず、代わりに、はるかにスケーラブルなイベント駆動型(非同期)を使用します。 )アーキテクチャ。

これは、高負荷の下で非常に少量で予測可能な量のメモリを使用します。 Nginx シンプルで非常に堅牢なPHP用FastCGIプロセスマネージャー( PHP-FPM )との組み合わせ )および世界で最も人気のあるデータベースサーバー MySQL 小さなメモリフットプリントを使用しながら、多くのパワーとパフォーマンスを提供できます。

次の記事は、 CentOS6VPSにLEMPスタックをインストールして構成する方法に関するものです。 とホストの燃えるような高速WordPress パワードWebアプリケーション。

記事は次のセクションに分かれています:

  • 初期設定
  • Nginxをインストールして構成する
  • MySQLのインストールと構成
  • PHP-FPMのインストールと構成
  • WordPressのインストールとセットアップ
  • 最高のパフォーマンスを得るためにキャッシュを設定する
インストールを続行する前に、次のコマンドを実行して画面セッションを起動します。
## screen -U -S lemp-stack

スクリーンセッションに入ったら、次のコマンドを実行して、CentOS6VPSが完全に最新であることを確認します。

## yum update

ApacheがVPSにインストールされている場合は、Apacheを停止し、次のコマンドを実行して削除します。

## /etc/init.d/httpd stop
## yum remove httpd
ステップ1)Nginxをインストールして構成する

次を実行してepelリポジトリを有効にします:

uname -m を実行して、VPSアーキテクチャを見つけます

– 32ビットVPS:

## wget -P /tmp http://mirror.pnl.gov/epel/6/i386/epel-release-6-8.noarch.rpm
## rpm -Uvh /tmp/epel-release-6-8.noarch.rpm
## rm -f /tmp/epel-release-6-8.noarch.rpm

– 64ビットVPS:

## wget -P /tmp http://mirror.itc.virginia.edu/fedora-epel/6/x86_64/epel-release-6-8.noarch.rpm
## rpm -Uvh /tmp/epel-release-6-8.noarch.rpm
## rm -f /tmp/epel-release-6-8.noarch.rpm

すべてが最新であることを確認します

## yum update

Nginxをインストールします 実行してyum経由:

## yum install nginx

/ etc / nginx /にあるNginxの設定ディレクトリに移動します nginx.confを編集します お気に入りの編集者と:

## cd /etc/nginx/
## vim nginx.conf
user              nginx;
worker_processes  2;

error_log  /var/log/nginx/error.log;
#error_log  /var/log/nginx/error.log  notice;
#error_log  /var/log/nginx/error.log  info;

pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       /etc/nginx/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  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  30;
    server_tokens off;

    gzip on;
    gzip_disable "MSIE [1-6]\.(?!.*SV1)";
    gzip_http_version 1.1;
    gzip_vary on;
    gzip_proxied any;
    gzip_comp_level 6;
    gzip_buffers 16 8k;
    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript text/x-js;

    # enabled sites
    include /etc/nginx/sites-enabled/*;

}
が含まれます

sites-enabledを作成します およびsites-available / etc / nginx内 ディレクトリ:

## mkdir -p /etc/nginx/sites-available /etc/nginx/sites-enabled

/etc/nginx/sites-available/default.conf に以下を追加して、デフォルトのNginx仮想ホストディレクティブを設定します

server {
    listen       80 default_server;
    server_name  _;
    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }
    error_page  404              /404.html;
    location = /404.html {
        root   /usr/share/nginx/html;
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}

/ etc / nginx / sites-enabled / にデフォルトのvhost構成へのシンボリックリンクを作成して、デフォルトのNginx仮想ホストディレクティブを有効にします

## cd /etc/nginx/sites-enabled
## ln -s /etc/nginx/sites-available/default.conf

Nginxの構成をテストし、システムスタートアップに追加して、最後に次の方法で起動します。

## nginx -t
## /etc/init.d/nginx restart
## chkconfig nginx on
ステップ2)MySQLをインストールして構成する

MySQLデータベースサーバーをインストールし、次のコマンドを実行して起動し、システムの起動に追加します。

## yum install mysql mysql-server
## service mysqld restart
## chkconfig mysqld on

次に、MySQLをセットアップするために以下のコマンドを実行します

## mysql_secure_installation
Enter current password for root (enter for none):
Set root password? [Y/n] y
Remove anonymous users? [Y/n] y
Disallow root login remotely? [Y/n] y
Remove test database and access to it? [Y/n] y
Reload privilege tables now? [Y/n] y

/etc/my.cnf に以下を追加して、MySQLがサーバーのパブリックIPでリッスンするように公開されていないことを確認します

## vim /etc/my.cnf

[mysqld]
bind-address = 127.0.0.1
...

データベースサーバーを再起動して、変更を有効にします。

## /etc/init.d/mysqld restart
ステップ3)PHP-FPMをインストールして構成します

PHP-FPMをインストールします 以下のコマンドを実行することによるいくつかの便利なPHP拡張機能:

## yum install php-fpm php-mysql php-gd php-mcrypt

/etc/php.iniを編集します 以下を変更/コメント解除します:

cgi.fix_pathinfo=0
date.timezone = America/New_York
memory_limit = 64M
expose_php = Off

次に、 /etc/php-fpm.confを編集します お気に入りの編集者と一緒に、次のコメントを外します:

emergency_restart_threshold = 10
emergency_restart_interval = 1m
process_control_timeout = 10

これらすべてが整ったら、 /etc/php-fpm.d/www.confにPHP-FPMプールを設定します。 :

## mv /etc/php-fpm.d/www.conf /root/
## vim /etc/php-fpm.d/www.conf
[wordpress]
;listen = 127.0.0.1:9001
listen = /var/run/php-wordpress.socket
user = nginx
group = nginx
request_slowlog_timeout = 5s
slowlog = /var/log/php-fpm/blogcms.log
listen.allowed_clients = 127.0.0.1
pm = dynamic
pm.max_children = 10
pm.start_servers = 3
pm.min_spare_servers = 2
pm.max_spare_servers = 4
pm.max_requests = 400
listen.backlog = -1
pm.status_path = /status
request_terminate_timeout = 120s
rlimit_files = 131072
rlimit_core = unlimited
catch_workers_output = yes
php_value[session.save_handler] = files
php_value[session.save_path] = /var/lib/php/session
php_admin_value[error_log] = /var/log/php-fpm/wordpress-error.log
php_admin_flag[log_errors] = on

PHP-FPMを再起動し、システムのスタートアップに追加します:

## /etc/init.d/php-fpm restart
## chkconfig php-fpm on

この時点で、 Nginxが必要です。 、 MySQL およびPHP-FPM サーバー上で稼働しています。 WordPressのvhostディレクティブの作成に進みます アプリケーション:

## vim /etc/nginx/sites-available/my-wordpress.tld.conf
server {
        listen 80;
        server_name my-wordpress.tld;
        rewrite ^(.*) http://www.my-wordpress.tld$1 permanent;
}

server {
        listen 80;
        server_name www.my-wordpress.tld;

        client_max_body_size 5m;
        client_body_timeout 60;

        access_log /var/log/nginx/my-wordpress.tld-access;
        error_log /var/log/nginx/my-wordpress.tld-error error;

        root /var/www/html/my-wordpress.tld/;
        index  index.html index.php;

        ### root directory ###
        location / {
                try_files $uri $uri/ /index.php?$args;
        }

        ### security ###
        error_page 403 =404;
        location ~ /\. { access_log off; log_not_found off; deny all; }
        location ~ ~$ { access_log off; log_not_found off; deny all; }
        location ~* wp-admin/includes { deny all; }
        location ~* wp-includes/theme-compat/ { deny all; }
        location ~* wp-includes/js/tinymce/langs/.*\.php { deny all; }
        location /wp-includes/ { internal; }
        #location ~* wp-config.php { deny all; }
        location ~* ^/wp-content/uploads/.*.(html|htm|shtml|php)$ {
                types { }
                default_type text/plain;
        }

        #  location ~* wp-admin {
        #      allow <YOUR_IP>;
        #      allow 127.0.0.1;
        #      deny all;
        #  }

        ### disable logging ###
        location = /robots.txt { access_log off; log_not_found off; }
        location = /favicon.ico { access_log off; log_not_found off; }

        ### caches ###
        location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)$ { access_log off; expires max; }
        location ~* \.(woff|svg)$ { access_log off; log_not_found off; expires 30d; }
        location ~* \.(js)$ { access_log off; log_not_found off; expires 7d; }

        ### php block ###
        location ~ \.php?$ {
                try_files $uri =404;
                include fastcgi_params;
                #fastcgi_pass 127.0.0.1:9001;
                fastcgi_pass unix:/var/run/php-wordpress.socket;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_intercept_errors on;
                fastcgi_split_path_info ^(.+\.php)(.*)$;
                #Prevent version info leakage
                fastcgi_hide_header X-Powered-By;
        }
}

次のコマンドを実行して、仮想ホストディレクティブを有効にし、nginxを再起動します。

## cd /etc/nginx/sites-enabled
## ln -s /etc/nginx/sites-available/my-wordpress.tld.conf
## nginx -t
## /etc/init.d/nginx restart

PHP info.php を作成して、PHP-FPMをテストします。 /var/www/html/my-wordpress.tld/のvhostドキュメントルートのスクリプト :

## mkdir -p /var/www/html/my-wordpress.tld/
## cd /var/www/html/my-wordpress.tld/
##  echo -e "<?php\n\tphpinfo();\n" > info.php

http://my-wordpress.tld/info.phpにアクセスします PHP-FPMをテストするには

ステップ4)WordPressをセットアップする

次のステップは、 /var/www/html/my-wordpress.tld/のvhostドキュメントルート内にWordPressをインストールすることです。 。 WordPressをインストールする前に、まず次のコマンドを実行してMySQLデータベースを作成しましょう。

## mysql -u root -p
mysql> create database wordpressDB;
mysql> grant all on wordpressDB.* to wpUser@localhost identified by 'YOUR_PASS';
mysql> quit
で識別されるwpUser@localhostに付与します。
## cd /var/www/html/my-wordpress.tld/
## wget http://wordpress.org/latest.zip
## unzip latest.zip
## mv wordpress/* .
## rm -rf latest.zip wordpress/

次に、WordPressのサンプル構成をコピーして、MySQLデータベース情報を設定します。

## cp wp-config-sample.php wp-config.php
## vim wp-config.php
define('DB_NAME', 'wordpressDB');
define('DB_USER', 'wpUser');
define('DB_PASSWORD', 'YOUR_PASS');
## chown nginx: -R /var/www/html/my-wordpress.tld/

http://my-wordpress.tldを開き、WordPressのインストールを完了します

ステップ5)最高のパフォーマンスを得るためにキャッシュを設定する

次のコマンドを実行して、PHP-APC(Alternative PHP Cache)をインストールします。

## yum install php-pecl-apc

APCをインストールしたら、以下を /etc/php.d/apc.iniに追加します。

## cat > /etc/php.d/apc.ini
extension = apc.so
apc.enabled=1
apc.shm_segments=1
apc.shm_size=128M
apc.num_files_hint=1024
apc.user_entries_hint=4096
apc.ttl=7200
apc.use_request_time=1
apc.user_ttl=7200
apc.gc_ttl=3600
apc.cache_by_default=1
apc.filters
apc.mmap_file_mask=/tmp/apc.XXXXXX
apc.file_update_protection=2
apc.enable_cli=0
apc.max_file_size=1M
apc.stat=1
apc.stat_ctime=0
apc.canonicalize=0
apc.write_lock=1
apc.report_autofilter=0
apc.rfc1867=0
apc.rfc1867_prefix =upload_
apc.rfc1867_name=APC_UPLOAD_PROGRESS
apc.rfc1867_freq=0
apc.rfc1867_ttl=3600
apc.include_once_override=0
apc.lazy_classes=0
apc.lazy_functions=0
apc.coredump_unmap=0
apc.file_md5=0
apc.preload_path

PHP-FPMを再起動します 変更を有効にするため。

## /etc/init.d/php-fpm restart

APCかどうかを確認します 実行すると読み込まれます:

## php -m | grep -w apc

または、 info.phpを開いて ドキュメントルートのスクリプト。

次に行うことは、WordPress管理にログインして、 W3TotalCacheプラグインをインストールすることです。 。 W3 Total Cacheプラグインを機能させるには、最初に Pretty URLsを有効にする必要があります。

設定->パーマリンク->カスタム構造

http://my-wordpress.tld/%postname%/

次に、 W3 Total Cacheのインストールに進みます。 。インストールしたら、

に移動します

パフォーマンス->一般設定

次のオプションを有効/無効にします。

Page cache: enabled
Page cache method: Disk: Enhaced

Minify: disabled

Database Cache: enabled
Database Cache Method: Opcode: Alternative PHP Cache (APC)

Object Cache: enbabled
Object Cache Method: Opcode: Alternative PHP Cache (APC)

Browser Cache: disabled

CDN: this is up to you.

すべての設定を保存をクリックします 変更を送信します。

/var/www/html/my-wordpress.tld/nginx.confに以下を追加します

## cat > /var/www/html/my-wordpress.tld/nginx.conf
# BEGIN W3TC Page Cache cache
location ~ /wp-content/cache/page_enhanced.*html$ {
    add_header Vary Cookie;
}
# END W3TC Page Cache cache
# BEGIN W3TC Page Cache core
set $w3tc_rewrite 1;
if ($request_method = POST) {
    set $w3tc_rewrite 0;
}
if ($query_string != "") {
    set $w3tc_rewrite 0;
}
if ($request_uri !~ \/$) {
    set $w3tc_rewrite 0;
}
if ($http_cookie ~* "(comment_author|wp\-postpass|w3tc_logged_out|wordpress_logged_in|wptouch_switch_toggle)") {
    set $w3tc_rewrite 0;
}
if (!-f "$document_root/wp-content/cache/page_enhanced/$http_host/$request_uri/_index.html") {
  set $w3tc_rewrite 0;
}
if ($w3tc_rewrite = 1) {
    rewrite .* "/wp-content/cache/page_enhanced/$http_host/$request_uri/_index.html" last;
}
# END W3TC Page Cache core

ドキュメントルートの所有権に問題がないことを確認してください:

## chown nginx: -R /var/www/html/my-wordpress.tld/

次のステップは、この構成ファイルを使用するようにNginxに指示することです。 /etc/nginx/sites-enabled/my-wordpress.tld.confを編集します 以下を追加/コメント解除します:

include /var/www/html/my-wordpress.tld/nginx.conf;
...
location ~* wp-config.php { deny all; }

Nginxの構成ファイルをテストし、次のコマンドを実行して変更を有効にするために再起動します。

## nginx -t
## /etc/init.d/nginx restart

WordPress構成ファイル/var/www/html/my-wordpress.tld/wp-config.phpを編集することもできます WordPressがデータベースにサイトのURLを照会する必要がないように、次のように定義します。

define('WP_HOME', 'http://my-wordpress.tld');
define('WP_SITEURL', 'http://my-wordpress.tld');

もちろん、Linux VPS Hostingをご利用の場合は、これを行う必要はありません。管理者に質問し、座ってリラックスしてください。管理者がすぐにこれを設定します。

PS。 この投稿が気に入った場合は、左側のボタンを使用してソーシャルネットワーク上の友達と共有するか、下に返信を残してください。ありがとう。


Cent OS
  1. NginxとPHP-FPMを使用してCentOS7VPSにFluxBBをインストールします

  2. NginxとPHP-FPMを使用してCentOS7VPSにeZPublishCommunityProjectをインストールします

  3. CentOS8にLEMPスタックを使用してWordPressをインストールする方法

  1. CentosVPSでNginxを使用してJoomlaを実行する

  2. Nginx、MariaDB、PHP-FPMを使用してCentOS7VPSにVarnishとphpMyAdminをインストールする方法

  3. Nginx、PHP-FPM、MySQLを使用してUbuntu14.04VPSにConcrete5をインストールします

  1. CentOS 7にLEMPスタック(Nginx、MySQL、PHP v7)をインストールする方法

  2. CentOS8にNginxとPHP7.3でNextcloudをインストールする方法

  3. CentOS 7 に LEMP スタックをインストールする方法