🐧

LAMP環境構築

2023/05/02に公開

はじめに

LAMP(Linux,Apache,MySQL,PHP)環境作成時によく使うコマンドを一覧で備忘録として残しておく。

OS(Linux)

> hostname -f                                    #ホスト名
> cat /etc/os-release                            #osのバージョン
> arch                                           #アーキテクチャ
> grep -i permitroot /etc/ssh/sshd_config        #SSH root ログイン
> cat /etc/logrotate.conf                        #システムログローテート
> cat /etc/sudoers                               #Sudo
> cat /etc/passwd                                #ユーザ
> grep -i password /etc/ssh/sshd_config          #パスワード
> df -h                                          #ディスク
> yum update                                                                           #更新
> free -m                                        #SWAP領域

Apache

> httpd -V                                       #バージョン
> ll /etc/httpd/conf/httpd.conf                  #設定ファイル
> ll /var/log/httpd                              #ログファイル
> cat /etc/logrotate.d/httpd                     #ログローテート
> grep -i apache /etc/httpd/conf/httpd.conf      #Apache実行ユーザ
> grep -ir directoryindex /etc/httpd/            #DirectoryIndex
> grep -ir keepalive /etc/httpd/                 #KeepAlive
> grep -ir maxc /etc/httpd/                      #MaxClients
> grep -ir allowover /etc/httpd/                 #AllowOverride
> grep -ir options /etc/httpd/                   #Options
> httpd -t                                       #Syntax
> rpm -qa | grep httpd                           #リポジトリ
> httpd -M                     #モジュール
> systemctl status httpd                         #ステータス

#VirtualHostの設定
> httpd -S                                       #VirtualHost
> cat /etc/httpd/conf/vhosts/~~~                 #設定ファイル

MySQL

> mysql -V                                       #バージョン
> ll /etc/my.cnf                                 #設定ファイル
> ll /var/log/mysql/mysqld.log                   #ログファイル
> cat /etc/my.cnf                                #文字コード、max_connections
> ll /var/lib/mysql/mysql-slow.log               #スローログ
> mysql -uroot -p                                #ログイン(EC2内のMySQL)
> mysql -u admin -p -h {mysqlのエンドポイント}    #ログイン(RDS)
> rpm -qa | grep -i mysql                        #リポジトリ

#DBの設定
> status;                                        #ステータス
> show grants;                                   #権限(ログインしているユーザ)
> show grants for 'ユーザー名';          #権限の確認
> select user, host from mysql.user;             #ユーザー一覧
> select user(), current_user();                 #現在のユーザー
> create user 'new_master_user' identified by 'パスワード'; # ユーザー作成
> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, PROCESS, 
REFERENCES, INDEX, ALTER, SHOW DATABASES, CREATE TEMPORARY TABLES, 
LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, 
CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, 
EVENT, TRIGGER ON *.* TO 'new_master_user'@'%' WITH GRANT OPTION;
#マスターユーザーで新規ユーザを作成しマスターと同等の権限を付与する

PHP

> php -v                                         #バージョン
> ll /etc/php.ini                                #設定ファイル
> rpm -qa | grep php                             #リポジトリ
> php -m                                         #モジュール
> which php                                      #コマンドパス

Postfix(おまけ)

> rpm -qa | grep postfix                         #バージョン
> ll /etc/postfix/main.cf                        #設定ファイル
> cat /etc/logrotate.d/syslog                    #ログ
> cat /etc/postfix/master.cf                     #設定ファイル

おわりに

色んなコマンドがあるが代表的なものについては覚えていきたい。

Discussion