0
0

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 3 years have passed since last update.

CentOS8.2+PHP7.4+CakePHP4+MySQL8+Python3.8環境構築手順

Last updated at Posted at 2020-11-28

やりたいこと

  • LAMPのローカル開発環境を構築する。
  • pythonもpipも動くようにする。
  • 2020年12月時点の最新バージョンを使いたい。

前提

  • CentOS8.2の最小構成インストールまで完了していること。
  • rootでSSH接続できること。

筆者の環境は
Windows10 + VirtualBox + CentOS-8.2.2004-x86_64-dvd1.iso(最小限のインストール)
です。

image.png

手順

下記コマンドを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タイムゾーン設定

yum -y install vim-enhanced
vim /etc/php.ini
date.timezone = "Asia/Tokyo"

各種ツールのインストール

sysctl -w net.ipv6.conf.all.disable_ipv6=1
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
<?php
try {
  $pdo = new PDO('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)

FTP

FTP接続用ユーザを追加する。

useradd ftp-user
passwd ftp-user

FTP接続用ディレクトリを作成する。

mkdir -p /var/www/ftp_dir
chown ftp-user /var/www/ftp_dir
chmod 755 /var/www/ftp_dir

FTPDをインストールする。

yum -y install vsftpd

コンフィグを設定する。

vi /etc/vsftpd/vsftpd.conf

下記を追記する。

userlist_enable=YES
tcp_wrappers=NO
pasv_enable=YES
pasv_min_port=60001
pasv_max_port=60010
force_dot_files=YES
use_localtime=YES
user_config_dir=/etc/vsftpd/user_conf
chroot_local_user=NO
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd/chroot_list

リストにユーザを追加する。

vi /etc/vsftpd/chroot_lis
ftp-user

ユーザディレクトリを設定する。

mkdir /etc/vsftpd/user_conf
vi /etc/vsftpd/user_conf/ftp-user
local_root=/var/www/ftp_dir

FTPDを起動する。

systemctl start vsftpd

FTPクライアントにて接続できることを確認する。
たとえばWinSCPで接続してみる。
https://forest.watch.impress.co.jp/library/software/winscp/

プロトコルはSFTPで、ホスト名はサーバのIPアドレスを入力。
ユーザは ftp-user

image.png

0
0
1

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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?