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

CentOS 7 VPSにLEMP(Linux、Nginx、MariaDB、PHP-FPM)をインストールする方法

次の記事では、 LEMP(Linux、Nginx、MariaDB、PHP-FPM)のインストール方法の手順を説明します。 CentOS 7の1つで Linux仮想サーバー

代わりに、ランプの設定方法をお探しの場合 次に、 CentOS 7 VPSにLAMP(Linux Apache、MariaDB、PHP)をインストールする方法に関するガイドを参照してください。

LEMPとは何ですか?

LEMP スタックはLEMPの同義語です サーバーまたはLEMP Webサーバー。 Linuxを含むセットアップを指します 、 Nginx MariaDB(MySQL) およびPHP

システムを更新する

いつものように、SSH Linux VPSに対して、screenを開始します セッションを行い、 CentOS 7を確認してください 次のコマンドを実行することにより、完全に最新の状態になります。

## screen -U -S lemp-centos7
## yum update

MARIA DB(MYSQL)のインストール

MariaDB MySQLのドロップイン代替品です CentOS 7(RHEL7)で使用されるデフォルトのデータベースサーバーです。 。 yumを使用してインストールを続行します のように:

## yum install mariadb mariadb-server mysql

次に、/etc/my.cnf.d/server.cnfを開きます お気に入りのテキストエディタを使用して、bind-address = 127.0.0.1を追加します [mysqld]内 ブロック。例:

## vim /etc/my.cnf.d/server.cnf

[mysqld]
#log-bin=mysql-bin
#binlog_format=mixed
bind-address = 127.0.0.1

これにより、MariaDBがローカルホストでのみリッスンにバインドされます 、これは優れたセキュリティ慣行であると考えられています。 OK、MariaDBデータベースサーバーを再起動し、次を使用してシステムの起動時に起動できるようにします。

## systemctl restart mariadb
## systemctl status mariadb
## systemctl enable mariadb

オプションで、mysql_secure_installationを実行できます MariaDB(MySQL)のインストールセキュリティを向上させるインストール後のスクリプト 。例:

## mysql_secure_installation

Enter current password for root (enter for none): ENTER
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

NGINXHTTPサーバーのインストール

Nginx CentOS 7ではまだ利用できません この記事を書いている時点での公式リポジトリ。したがって、yumを使用して簡単にインストールおよび管理できます 、CentOS7用のNginxの最新の安定バージョンのリポジトリを使用できます。

例:

## rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
## yum install nginx

インストールしたら、次のコマンドを実行して、SSDVPSで使用可能なCPUの数を確認します。

## grep -c processor /proc/cpuinfo
2

この数は、nginxの数を表す必要があります /etc/nginx/nginx.confのNginxメイン構成ファイルに設定されているプロセス 。

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

次のコマンドを使用してシステムで実行されている場合は、Apacheを停止します。

## [[ $(pgrep httpd) ]] && ( systemctl stop httpd; systemctl disable httpd )

次のコマンドを使用して、Nginxをテスト、起動し、システムの起動に追加します。

## nginx -t
## systemctl restart nginx
## systemctl enable nginx

http:// server_ipに移動すると、次のようになります。

これは、Nginxが正常に稼働していることを意味します。

PHP-FPMのインストール

PHP-FPMを使用してPHPをFastCGIとして実行します 、yumを使用してPHPサポートをインストールします :

## yum install php-fpm php-mysql

また、他のPHP拡張機能をインストールすることもできます。 アプリケーションに必要です。リストは次のとおりです:

php-bcmath          : A module for PHP applications for using the bcmath library
php-cli             : Command-line interface for PHP
php-common          : Common files for PHP
php-dba             : A database abstraction layer module for PHP applications
php-devel           : Files needed for building PHP extensions
php-embedded        : PHP library for embedding in applications
php-enchant         : Enchant spelling extension for PHP applications
php-fpm             : PHP FastCGI Process Manager
php-gd              : A module for PHP applications for using the gd graphics library
php-intl            : Internationalization extension for PHP applications
php-ldap            : A module for PHP applications that use LDAP
php-mbstring        : A module for PHP applications which need multi-byte string handling
php-mysql           : A module for PHP applications that use MySQL databases
php-mysqlnd         : A module for PHP applications that use MySQL databases
php-odbc            : A module for PHP applications that use ODBC databases
php-pdo             : A database access abstraction module for PHP applications
php-pear.noarch     : PHP Extension and Application Repository framework
php-pecl-memcache   : Extension to work with the Memcached caching daemon
php-pgsql           : A PostgreSQL database module for PHP
php-process         : Modules for PHP script using system process interfaces
php-pspell          : A module for PHP applications for using pspell interfaces
php-recode          : A module for PHP applications for using the recode library
php-snmp            : A module for PHP applications that query SNMP-managed devices
php-soap            : A module for PHP applications that use the SOAP protocol
php-xml             : A module for PHP applications which use XML
php-xmlrpc          : A module for PHP applications which use the XML-RPC protocol

/etc/php.iniのPHPメイン構成ファイルを編集します 次のように設定します:

## vim /etc/php.ini

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

また、/etc/php-fpm.d/www.confを編集します ユーザーを変更し、fpmプールを実行するグ​​ループをnginxに変更します :

## vim +/^user /etc/php-fpm.d/www.conf

user = nginx
group = nginx

ログディレクトリの所有権を設定する:

## chown nginx:root -R /var/log/php-fpm/

systemctlを使用して、PHPサーバーを起動し、システムの起動に追加します。

## systemctl restart php-fpm
## systemctl enable php-fpm

NGINXVHOSTのセットアップ

ドメインmydomain.comがあるとします。 そして、それを使用して、/srv/www/mydomain.com.comでPHPベースのWebアプリケーションをホストしたいとします。 WordPress、Joomla、Laravelなど。Nginxを設定するには、mydomain.comのリクエストを処理します。 、および/srv/www/mydomain.com.comでPHPスクリプトを提供します /etc/nginx/conf.d/mydomain.com.confにサーバーブロックを作成する必要があります これは次のようになります:

## vim /etc/nginx/conf.d/mydomain.com.conf

server {
    server_name mydomain.com;
    listen 80;
    root /srv/www/mydomain.com;
    access_log /var/log/nginx/mydomain.com-access.log;
    error_log /var/log/nginx/mydomain.com-error.log;
    index index.php;

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

    location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)$ {
        access_log off;
        expires max;
    }
    location ~ /\.ht {
        deny  all;
    }
    location ~ \.php {
        try_files $uri = 404;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        include /etc/nginx/fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
}

以下を使用してNginxをテストして再起動します:

## nginx -t
## systemctl restart nginx

必要に応じて、テストinfo.phpを作成します 次のコマンドを使用したスクリプト:

## mkdir -p /srv/www/mydomain.com
## echo -e "<?php\n\tphpinfo();" > /srv/www/mydomain.com/info.php
## chown nginx: -R /srv/www/

http://mydomain.com/info.php

のブラウザでアクセスしてみてください

もちろん、Linux VPSホスティングサービスのいずれかを使用している場合は、これを行う必要はありません。その場合は、専門のLinux管理者にLEMPのインストールを依頼するだけです。 。彼らは24時間年中無休で利用可能であり、あなたの要求をすぐに処理します。また、Debian 8 VPSにLEMP(Linux、Nginx、MySQL、PHP-FPM)をインストールする方法に関するガイドを読むこともできます。

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


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

  2. CentOS 7 VPSにLEMP(Linux、Nginx、MariaDB、PHP-FPM)をインストールする方法

  3. Debian 8 VPSにLEMP(Linux、Nginx、MySQL、PHP-FPM)をインストールする方法

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

  2. CentOS8LinuxにPHP8をインストールする方法

  3. CentOS6にLinuxDashをインストールする方法

  1. Fedora 30サーバーにLEMP(Linux、Nginx、MariaDB、PHP)をインストールする方法

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

  3. CentOS 7にPHPとMySQL(LEMPスタック)を使用してNginxをインストールする方法