28
29

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

■さくらのVPSにNginx、PHP-FPM、MariaDBな環境を構築

Posted at

▼Nginx
リポジトリを追加

vim /etc/yum.repos.d/nginx.repo

※設定は本家サイトを参考に
http://wiki.nginx.org/Install

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/6/$basearch/
gpgcheck=0
enabled=1

最新に更新

yum update

インストール

yum install nginx

Nginxを起動

service nginx start

Nginx自動起動設定

chkconfig nginx on

ディレクトリオーナーチェンジ

chown -R midasmn:midasmn /usr/share/nginx/html/

▼PHP
インストール

yum install php php-fpm php-devel php-mysql php-gd php-mbstring

▼PHP-FPMを設定
設定バックアップ

cp /etc/php-fpm.d/{www.conf,www.conf.back}

編集

vim /etc/php-fpm.d/www.conf

; RPM: apache Choosed to be able to access some dir as httpd
user = nginx # apacheから書き換える
; RPM: Keep a group allowed to write in log dir.
group = nginx # apacheから書き換える

listen = /var/run/php-fpm/php-fpm.sock ←UNIXソケットを利用

PHP-FPMを起動

sudo service php-fpm start

chkconfig php-fpm on

▼NginxでPHPを動かすための設定
設定バックアップ

cp /etc/nginx/conf.d/{default.conf,default.conf.back}

編集

vim /etc/nginx/conf.d/default.conf

server {
listen 80;
server_name localhost;

#charset koi8-r;
#access_log  /var/log/nginx/log/host.access.log  main;

location / {
    root   /usr/share/nginx/html;
    index  index.php index.html index.htm;
}

#error_page  404              /404.html;

# redirect server error pages to the static page /50x.html
#
error_page   500 502 503 504  /50x.html;
location = /50x.html {
    root   /usr/share/nginx/html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
#    proxy_pass   http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
    root           /usr/share/nginx/html;
    fastcgi_pass   unix:/var/run/php-fpm/php-fpm.sock;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    include        fastcgi_params;
}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
#    deny  all;
#}

}

※10行目のindexにindex.phpを追加。
※30行目からのPHPのセクションを編集。

▼MariaDBをyumでインストール
リポジトリを追加

vim /etc/yum.repos.d/MariaDB.repo

※設定は本家サイト参照
https://downloads.mariadb.org/mariadb/repositories/#mirror=yamagata-university&distro=CentOS&distro_release=centos6-amd64&version=10.0

MariaDB 10.0 CentOS repository list - created 2014-05-02 02:22 UTC

http://mariadb.org/mariadb/repositories/

[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.0/centos6-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

最新に更新

yum update

インストール

yum install MariaDB-devel MariaDB-client MariaDB-server

設定をバックアップ

cp /etc/my.cnf.d/{server.cnf,server.cnf.back}

編集

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

下記を追加
character_set_server=utf8
default-storage-engine=InnoDB
innodb_file_per_table
[mysql]
default-character-set=utf8
[mysqldump]
default-character-set=utf8

MariaDBを起動

service mysql start

MariaDB自動起動設定

chkconfig mysql on

rootパスワードを設定
$ mysqladmin -u root password '新しいパスワード'

MariaDBサーバに接続
$ mysql -u root -p
Enter password:
ストレージエンジン確認
MariaDB [(none)]> SHOW ENGINES;

ステータス確認
MariaDB [(none)]> STATUS;

28
29
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
28
29

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?