LoginSignup
30
44

More than 5 years have passed since last update.

CentOS7 に LAMP環境を作りました。

Last updated at Posted at 2015-11-08

CentOS7に開発用のLAMP環境を作りました。CentOS6との比較する感じで書いています。結果としてPHP5.6 Apache2.4 MySQL5.6の環境になりました。作業環境はMacのVagrantになります。 

CentOSのバージョンを確認します。

CentOSのバージョンを確認
cat /etc/redhat-release
CentOS Linux release 7.1.1503 (Core) 

yumをupdateしておきます。

yumをupdate
sudo yum update

リポジトリを追加

そのままyum installをするとPHP5.4がインストールされそうなのでリポジトリを更新します。

リポジトリを追加
sudo yum install epel-release
sudo rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

PHPをインストール

PHPを追加
sudo yum install --enablerepo=remi,remi-php56 php php-common php-opcache php-devel php-mbstring php-mcrypt php-mysqlnd php-phpunit-PHPUnit php-pecl-xdebug php-pecl-xhprof

sudo yum install --enablerepo=remi,remi-php56 -y php-intl

PHPのバージョンを確認

PHPのバージョンを確認します。

PHPのバージョンを確認
php --version
PHP 5.6.15 (cli) (built: Oct 29 2015 14:18:11) 
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies
    with Xdebug v2.3.3, Copyright (c) 2002-2015, by Derick Rethans

PHP5.6がインストールされています。

Httpdをインストール

HTTPDを追加
sudo yum install --enablerepo=remi,remi-php56 -y httpd

Httpdを起動

Httpdを起動します。

httpdを起動
sudo systemctl start httpd

CentOS7からhttpdを起動するときのコマンドがsystemctlに変わっています。

Httpdのバージョンを確認

バージョンを確認
httpd -v
Server version: Apache/2.4.6 (CentOS)
Server built:   Aug 24 2015 18:11:25

MySQLをインストール

CentOS7でMySQLを入れようとするとMariaDBが入ります。なのでMySQLを入れたい場合はリポジトリを追加する必要があるようです。今回はMySQLを使用するのでMySQLを入れます。

MySQLをインストール
sudo yum install http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
MySQLをインストール
wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
sudo rpm -Uvh mysql-community-release-el7-5.noarch.rpm
MySQLをインストール
sudo yum --enablerepo=mysql56-community install mysql-community-server

MySQLがインストールできました。

絵文字対策でutf8mb4に

my.cnfを編集します。

sudo vi /etc/my.cnf

[client]
default-character-set=utf8mb4

[mysqld]
character-set-server=utf8mb4

MySQLを起動

sudo systemctl start mysqld
mysql -u root -p

ログインできました。

Firewalldを停止

iptalbesの名前がfirewalldに変わったそうです。

sudo systemctl stop firewalld

SELINUXの確認

Seilnuxの確認
getenforce
Disabled

起動してないのでスルーします。

CentOS7起動時に何が起動するかを確認

CentOS6以前のchkconfig --listにあたるコマンドで調べます。

サービス一覧の表示
sudo systemctl list-unit-files -t service

・・・
htcacheclean.service                        static  
httpd.service                               enabled 
initrd-cleanup.service                      static  
initrd-parse-etc.service                    static  
initrd-switch-root.service                  static  
initrd-udevadm-cleanup-db.service           static  
iprdump.service                             disabled
iprinit.service                             disabled
以下略

enabledは起動するもので、disabledは起動しないようです。

httpdを起動にして、firewalldは起動しないようにします。

sudo systemctl enable httpd
sudo systemctl disable firewalld

OSを再起動して確認

一旦ログアウトしてOSを再起動して確認します。

exit

vagrant reload

どうやらhttpdが起動していることがわかりました。(たまに起動しない?httpdのDocumentRootでエラーがでると起動しませんでした。)
PHPファイルを置いてみたところ表示もできました(☝ ՞ਊ ՞)

参考

https://blog.apar.jp/linux/194/
http://qiita.com/daskepon/items/b6bb736b6f5fd5b817e0
http://www.slideshare.net/enakai/linux-27872553

30
44
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
30
44