やりたいこと
- LAMPのローカル開発環境を構築する。
- pythonもpipも動くようにする。
- 2020年12月時点の最新バージョンを使いたい。
前提
- CentOS8.2の最小構成インストールまで完了していること。
- rootでSSH接続できること。
筆者の環境は
Windows10 + VirtualBox + CentOS-8.2.2004-x86_64-dvd1.iso(最小限のインストール)
です。
手順
下記コマンドをrootで実行してください。
OS最小構成からの開始を前提としているので、インストール済みのものは飛ばしてOKです。
リポジトリ
yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
yum -y install https://rpms.remirepo.net/enterprise/remi-release-8.rpm
サーバの文字コード変更
localectl set-locale LANG=ja_JP.UTF-8
サーバのタイムゾーン変更
timedatectl set-timezone Asia/Tokyo
httpdのインストール
yum install httpd -y
systemctl start httpd.service
systemctl enable httpd.service
php7.4のインストール
dnf -y install dnf-utils
dnf -y module install php:remi-7.4
yum install -y php-cli php-devel php-common php-mbstring php-fpm php-gd php-opcache php-pdo php-xml php-intl php-zip php-pear php-bcmath php-mysql
PHPとhttpdのバージョン確認
[root@develop ~]# php -v
PHP 7.4.13 (cli) (built: Nov 24 2020 10:03:34) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.13, Copyright (c), by Zend Technologies
[root@develop ~]# httpd -v
Server version: Apache/2.4.37 (centos)
Server built: Sep 15 2020 15:41:16
PHPタイムゾーン設定
vim /etc/php.ini
date.timezone = "Asia/Tokyo"
各種ツールのインストール
yum -y install vim-enhanced
yum -y install git
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
dnf install -y unzip
MySQL8のインストール
dnf -y remove mariadb
dnf -y install @mysql:8.0
dnf -y install php-mysqlnd
MySQLバージョン確認
[root@develop ~]# mysql --version
mysql Ver 8.0.21 for Linux on x86_64 (Source distribution)
MySQLの起動
vi /etc/my.cnf
[client]
default-character-set = utf8
systemctl enable mysqld.service
systemctl start mysqld.service
MySQL8の設定
mysql_secure_installation
mysql -u root -p
SELinux無効化
setenforce 0
vi /etc/selinux/config
SELINUX=disabled
PHPとMySQLの接続確認
vi /var/www/html/index.php
<?phptry{$pdo=newPDO('mysql:host=localhost;dbname=mysql;charset=utf8','root','MySQLのパスワード',array(PDO::ATTR_EMULATE_PREPARES=>false));$result=$pdo->query('show tables');while($row=$result->fetch(PDO::FETCH_ASSOC)){print_r($row);}}catch(PDOException$e){exit('MySQL connect error!!! '.$e->getMessage());}?>
HTTPページ表示確認
firewall-cmd --add-port=80/tcp --zone=public --permanent
firewall-cmd --reload
systemctl restart httpd
にアクセスして下記が表示されたら接続成功。
Array ( [Tables_in_mysql] => columns_priv ) Array ( [Tables_in_mysql] => component ) Array ( [Tables_in_mysql] => db ) Array ( [Tables_in_mysql] => default_roles ) Array ( [Tables_in_mysql] => engine_cost ) Array ( [Tables_in_mysql] => func ) Array ( [Tables_in_mysql] => general_log ) Array ( [Tables_in_mysql] => global_grants ) Array ( [Tables_in_mysql] => gtid_executed ) Array ( [Tables_in_mysql] => help_category ) Array ( [Tables_in_mysql] => help_keyword ) Array ( [Tables_in_mysql] => help_relation ) Array ( [Tables_in_mysql] => help_topic ) Array ( [Tables_in_mysql] => innodb_index_stats ) Array ( [Tables_in_mysql] => innodb_table_stats ) Array ( [Tables_in_mysql] => password_history ) Array ( [Tables_in_mysql] => plugin ) Array ( [Tables_in_mysql] => procs_priv ) Array ( [Tables_in_mysql] => proxies_priv ) Array ( [Tables_in_mysql] => role_edges ) Array ( [Tables_in_mysql] => server_cost ) Array ( [Tables_in_mysql] => servers ) Array ( [Tables_in_mysql] => slave_master_info ) Array ( [Tables_in_mysql] => slave_relay_log_info ) Array ( [Tables_in_mysql] => slave_worker_info ) Array ( [Tables_in_mysql] => slow_log ) Array ( [Tables_in_mysql] => tables_priv ) Array ( [Tables_in_mysql] => time_zone ) Array ( [Tables_in_mysql] => time_zone_leap_second ) Array ( [Tables_in_mysql] => time_zone_name ) Array ( [Tables_in_mysql] => time_zone_transition ) Array ( [Tables_in_mysql] => time_zone_transition_type ) Array ( [Tables_in_mysql] => user )
CakePHP4
hoge は任意の名前に変更してください。
composer self-update && composer create-project --prefer-dist cakephp/app hoge
pythonのインストール
dnf install python38 -y
alternatives --config python
/usr/bin/python3.8
を選択してください。
python --version
Python 3.8.0
update-alternatives --install /usr/bin/pip pip /usr/bin/pip3.8 1
pip --version
pip 19.2.3 from /usr/lib/python3.8/site-packages/pip (python 3.8)