CentOS7 で Nginx と PHP7-FPM を使用して Nextcloud をインストールする方法
前提条件
64 ビット centos 7
サーバー上の root 権限
ステップ 1 - centos 7 に nginx と php7-fpm をインストールする
nginx と php7-fpm のインストールを開始する前に、リポジトリ ソースも追加する必要がありますepel パッケージ用。次のコマンドを使用します:
yum -y install epel-release
次に、epel リポジトリから nginx のインストールを開始します:
yum -y install nginx
次に、php7-fpm 用の別のリポジトリを追加する必要もあります。インターネット上には php 7 シリーズのパッケージを提供するリモート リポジトリが多数ありますが、ここでは webtatic を使用します。
php7-fpm Webtatic リポジトリを追加します:
rpm -uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
次に、php7-fpm と nextcloud に必要ないくつかのパッケージをインストールします。
コードをコピーします コードは次のとおりです:
yum -y install php70w-fpm php70w-cli php70w-gd php70w-mcrypt php70w-mysql php70w-pear php70w-xml php70w-mbstring php70w- pdo php70w- json php70w-pecl-apcu php70w-pecl-apcu-devel
最後に、サーバーターミナルからphpのバージョン番号を確認し、phpが正しくインストールされているかどうかを確認します。
php -v
ステップ 2 - php7-fpm の構成
このステップでは、nginx と一緒に実行されるように php-fpm を構成します。 php7-fpm はユーザー nginx
として実行され、ポート 9000
でリッスンします。
vim を使用して、デフォルトの php7-fpm 構成ファイルを編集します。
vim /etc/php-fpm.d/www.conf
8 行目と 10 行目では、user
と group
に値 nginx
が割り当てられます。
user = nginx group = nginx
22 行目で、指定されたポートで php-fpm が実行されていることを確認します。
listen = 127.0.0.1:9000
366~370行目のコメントを外し、php-fpmのシステム環境変数を有効にします。
env[hostname] = $hostname env[path] = /usr/local/bin:/usr/bin:/bin env[tmp] = /tmp env[tmpdir] = /tmp env[temp] = /tmp
ファイルを保存し、vim エディタを終了します。
次のステップでは、 /var/lib/
ディレクトリに新しいフォルダー session
を作成し、その所有者を nginx
user に変更します。
mkdir -p /var/lib/php/session chown nginx:nginx -r /var/lib/php/session/
次に、php-fpmとnginxを起動し、起動時に起動するサービスとして設定します。
sudo systemctl start php-fpm sudo systemctl start nginx sudo systemctl enable php-fpm sudo systemctl enable nginx
php7-fpm 設定完了
ステップ 3 - mariadb のインストールと設定
nextcloud のデータベースとして mariadb を使用します。 yum
コマンドを直接使用して、centos のデフォルトのリモート リポジトリから mariadb-server
パッケージをインストールできます。
yum -y install mariadb mariadb-server
mariadb を起動し、システムで開始されたサービスに追加します。
systemctl start mariadb systemctl enable mariadb
次に、mariadb の root ユーザー パスワードの構成を開始します。
mysql_secure_installation
「y
」と入力し、mariadb の root パスワードを設定します。
set root password? [y/n] y new password: re-enter new password: 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
これでパスワードが設定されました。mysql シェルにログインし、nextcloud の新しいデータベースとユーザーを作成します。ここでは、nextcloud_db
という名前のデータベースと nextclouduser
という名前のユーザーを作成します。ユーザーのパスワードは nextclouduser@
です。もちろん、独自のシステムにはより安全なパスワードを選択してください。
mysql -u root -p
mariadb の root パスワードを入力して、mysql シェルにログインします。
次の mysql クエリ ステートメントを入力して、新しいデータベースとユーザーを作成します。
create database nextcloud_db; create user nextclouduser@localhost identified by 'nextclouduser@'; grant all privileges on nextcloud_db.* to nextclouduser@localhost identified by 'nextclouduser@'; flush privileges;
nextcloud_db
データベースと nextclouduser
データベース ユーザーの作成が完了しました
ステップ 4 - nextcloud の自己署名 SSL 証明書を生成します
このチュートリアルでは、クライアントに https 接続を使用して nextcloud を実行させます。 Let's encrypt などの無料の SSL 証明書を使用することも、自己署名 SSL 証明書を自分で作成することもできます。ここでは、openssl を使用して独自の自己署名 SSL 証明書を作成します。
SSL ファイル用の新しいディレクトリを作成します:
mkdir -p /etc/nginx/cert/
次のように、openssl を使用して新しい ssl 証明書を生成します。
コードをコピーします。コードは次のとおりです。
openssl req -new -x509 -days 365 -nodes -out /etc/nginx/cert/nextcloud.crt -keyout /etc /nginx/cert/nextcloud.key
最後に chmod コマンドを使用して、すべての証明書ファイルのアクセス許可を 600 に設定します。
chmod 700 /etc/nginx/cert chmod 600 /etc/nginx/cert/*
ステップ 5 - nextcloud をダウンロードしてインストールする
wget
コマンドを直接使用して nextcloud をサーバーにダウンロードします。最初に wget
をインストールする必要があります。また、解凍するには unzip
をインストールする必要があります。 yum
コマンドを使用して、これら 2 つのプログラムをインストールします。
yum -y install wget unzip
まず、 /tmp
ディレクトリに入り、wget
を使用して、公式 Web サイトから最新の nextcloud 10 をダウンロードします。
cd /tmp wget https://download.nextcloud.com/server/releases/nextcloud-10.0.2.zip
nextcloud を解凍し、/usr/share/nginx/html/
ディレクトリに移動します。
unzip nextcloud-10.0.2.zip mv nextcloud/ /usr/share/nginx/html/
次のステップでは、nginx の Web ルート ディレクトリに移動し、nextcloud の data
フォルダーを作成します。
cd /usr/share/nginx/html/ mkdir -p nextcloud/data/
Change nextcloud
ディレクトリの所有者は nginx
ユーザーおよびグループです。
chown nginx:nginx -r nextcloud/
ステップ 6 - nginx
在步骤 5 我们已经下载好了 nextcloud 源码,并配置好了让它运行于 nginx 服务器中,但我们还需要为它配置一个虚拟主机。在 nginx 的 conf.d
目录下创建一个新的虚拟主机配置文件 nextcloud.conf
。
cd /etc/nginx/conf.d/ vim nextcloud.conf
将以下内容粘贴到虚拟主机配置文件中:
upstream php-handler { server 127.0.0.1:9000; #server unix:/var/run/php5-fpm.sock; } server { listen 80; server_name cloud.nextcloud.co; # enforce https return 301 https://$server_name$request_uri; } server { listen 443 ssl; server_name cloud.nextcloud.co; ssl_certificate /etc/nginx/cert/nextcloud.crt; ssl_certificate_key /etc/nginx/cert/nextcloud.key; # add headers to serve security related headers # before enabling strict-transport-security headers please read into this # topic first. add_header strict-transport-security "max-age=15768000; includesubdomains; preload;"; add_header x-content-type-options nosniff; add_header x-frame-options "sameorigin"; add_header x-xss-protection "1; mode=block"; add_header x-robots-tag none; add_header x-download-options noopen; add_header x-permitted-cross-domain-policies none; # path to the root of your installation root /usr/share/nginx/html/nextcloud/; location = /robots.txt { allow all; log_not_found off; access_log off; } # the following 2 rules are only needed for the user_webfinger app. # uncomment it if you're planning to use this app. #rewrite ^/.well-known/host-meta /public.php?service=host-meta last; #rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json # last; location = /.well-known/carddav { return 301 $scheme://$host/remote.php/dav; } location = /.well-known/caldav { return 301 $scheme://$host/remote.php/dav; } # set max upload size client_max_body_size 512m; fastcgi_buffers 64 4k; # disable gzip to avoid the removal of the etag header gzip off; # uncomment if your server is build with the ngx_pagespeed module # this module is currently not supported. #pagespeed off; error_page 403 /core/templates/403.php; error_page 404 /core/templates/404.php; location / { rewrite ^ /index.php$uri; } location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)/ { deny all; } location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) { deny all; } location ~ ^/(?:index|remote|public|cron|core/ajax/update|status|ocs/v[12]|updater/.+|ocs-provider/.+|core/templates/40[34])\.php(?:$|/) { include fastcgi_params; fastcgi_split_path_info ^(.+\.php)(/.*)$; fastcgi_param script_filename $document_root$fastcgi_script_name; fastcgi_param path_info $fastcgi_path_info; fastcgi_param https on; #avoid sending the security headers twice fastcgi_param modheadersavailable true; fastcgi_param front_controller_active true; fastcgi_pass php-handler; fastcgi_intercept_errors on; fastcgi_request_buffering off; } location ~ ^/(?:updater|ocs-provider)(?:$|/) { try_files $uri/ =404; index index.php; } # adding the cache control header for js and css files # make sure it is below the php block location ~* \.(?:css|js)$ { try_files $uri /index.php$uri$is_args$args; add_header cache-control "public, max-age=7200"; # add headers to serve security related headers (it is intended to # have those duplicated to the ones above) # before enabling strict-transport-security headers please read into # this topic first. add_header strict-transport-security "max-age=15768000; includesubdomains; preload;"; add_header x-content-type-options nosniff; add_header x-frame-options "sameorigin"; add_header x-xss-protection "1; mode=block"; add_header x-robots-tag none; add_header x-download-options noopen; add_header x-permitted-cross-domain-policies none; # optional: don't log access to assets access_log off; } location ~* \.(?:svg|gif|png|html|ttf|woff|ico|jpg|jpeg)$ { try_files $uri /index.php$uri$is_args$args; # optional: don't log access to other assets access_log off; } }
保存文件并退出 vim。
下载测试以下该 nginx 配置文件是否有错误,没有的话就可以重启服务了。
nginx -t systemctl restart nginx
步骤 7 - 为 nextcloud 配置 selinux 和 firewalld 规则
本教程中,我们将以强制模式运行 selinux,因此需要一个 selinux 管理工具来为 nextcloud 配置 selinux。
使用以下命令安装 selinux 管理工具。
yum -y install policycoreutils-python
然后以 root 用户来运行以下命令,以便让 nextcloud 运行于 selinux 环境之下。如果你是用的其他名称的目录,记得将 nextcloud
替换掉。
semanage fcontext -a -t httpd_sys_rw_content_t '/usr/share/nginx/html/nextcloud/data(/.*)?' semanage fcontext -a -t httpd_sys_rw_content_t '/usr/share/nginx/html/nextcloud/config(/.*)?' semanage fcontext -a -t httpd_sys_rw_content_t '/usr/share/nginx/html/nextcloud/apps(/.*)?' semanage fcontext -a -t httpd_sys_rw_content_t '/usr/share/nginx/html/nextcloud/assets(/.*)?' semanage fcontext -a -t httpd_sys_rw_content_t '/usr/share/nginx/html/nextcloud/.htaccess' semanage fcontext -a -t httpd_sys_rw_content_t '/usr/share/nginx/html/nextcloud/.user.ini' restorecon -rv '/usr/share/nginx/html/nextcloud/'
接下来,我们要启用 firewalld 服务,同时为 nextcloud 开启 http 和 https 端口。
启动 firewalld 并设置随系统启动。
systemctl start firewalld systemctl enable firewalld
现在使用 firewall-cmd 命令来开启 http 和 https 端口,然后重新加载防火墙。
firewall-cmd --permanent --add-service=http firewall-cmd --permanent --add-service=https firewall-cmd --reload
至此,服务器配置完成。
步骤 8 - nextcloud 安装
打开你的 web 浏览器,输入你为 nextcloud 设置的域名,我这里设置为 cloud.nextcloud.co,然后会重定向到安全性更好的 https 连接。
设置你的管理员用户名和密码,然后输入数据验证信息,点击 '完成安装 (finish setup)'。
以上がCentOS7 で Nginx と PHP7-FPM を使用して Nextcloud をインストールする方法の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

AI Hentai Generator
AIヘンタイを無料で生成します。

人気の記事

ホットツール

メモ帳++7.3.1
使いやすく無料のコードエディター

SublimeText3 中国語版
中国語版、とても使いやすい

ゼンドスタジオ 13.0.1
強力な PHP 統合開発環境

ドリームウィーバー CS6
ビジュアル Web 開発ツール

SublimeText3 Mac版
神レベルのコード編集ソフト(SublimeText3)

ホットトピック









PHPはMySQLIおよびPDO拡張機能を使用して、データベース操作とサーバー側のロジック処理で対話し、セッション管理などの関数を介してサーバー側のロジックを処理します。 1)MySQLIまたはPDOを使用してデータベースに接続し、SQLクエリを実行します。 2)セッション管理およびその他の機能を通じて、HTTPリクエストとユーザーステータスを処理します。 3)トランザクションを使用して、データベース操作の原子性を確保します。 4)SQLインジェクションを防ぎ、例外処理とデバッグの閉鎖接続を使用します。 5)インデックスとキャッシュを通じてパフォーマンスを最適化し、読みやすいコードを書き、エラー処理を実行します。

nginxが開始されるかどうかを確認する方法:1。コマンドラインを使用します:SystemCTLステータスnginx(Linux/unix)、netstat -ano | FindStr 80(Windows); 2。ポート80が開いているかどうかを確認します。 3.システムログのnginx起動メッセージを確認します。 4. Nagios、Zabbix、Icingaなどのサードパーティツールを使用します。

PHPは動的なWebサイトを構築するために使用され、そのコア関数には次のものが含まれます。1。データベースに接続することにより、動的コンテンツを生成し、リアルタイムでWebページを生成します。 2。ユーザーのインタラクションを処理し、提出をフォームし、入力を確認し、操作に応答します。 3.セッションとユーザー認証を管理して、パーソナライズされたエクスペリエンスを提供します。 4.パフォーマンスを最適化し、ベストプラクティスに従って、ウェブサイトの効率とセキュリティを改善します。

Windowsでnginxを構成する方法は? nginxをインストールし、仮想ホスト構成を作成します。メイン構成ファイルを変更し、仮想ホスト構成を含めます。 nginxを起動またはリロードします。構成をテストし、Webサイトを表示します。 SSLを選択的に有効にし、SSL証明書を構成します。ファイアウォールを選択的に設定して、ポート80および443のトラフィックを許可します。

PHPとPythonには独自の利点と短所があり、選択はプロジェクトのニーズと個人的な好みに依存します。 1.PHPは、大規模なWebアプリケーションの迅速な開発とメンテナンスに適しています。 2。Pythonは、データサイエンスと機械学習の分野を支配しています。

Linuxでは、次のコマンドを使用して、nginxが起動されるかどうかを確認します。SystemCTLステータスNGINXコマンド出力に基づいて、「アクティブ:アクティブ(実行)」が表示された場合、NGINXが開始されます。 「アクティブ:非アクティブ(dead)」が表示されると、nginxが停止します。

Linuxでnginxを開始する手順:nginxがインストールされているかどうかを確認します。 systemctlを使用して、nginxを開始してnginxサービスを開始します。 SystemCTLを使用して、NGINXがシステムスタートアップでNGINXの自動起動を有効にすることができます。 SystemCTLステータスNGINXを使用して、スタートアップが成功していることを確認します。 Webブラウザのhttp:// localhostにアクセスして、デフォルトのウェルカムページを表示します。

nginxの実行ステータスを表示する方法は次のとおりです。PSコマンドを使用してプロセスステータスを表示します。 nginx configuration file /etc/nginx/nginx.confを表示します。 NGINXステータスモジュールを使用して、ステータスエンドポイントを有効にします。 Prometheus、Zabbix、Nagiosなどの監視ツールを使用します。
