Codeigniter 4 をインストール


Vagrant上に Codeigniter 4 をインストール

Windowsに以下のソフトウェアがインストールされていることが前提

- https://www.virtualbox.org/
- https://www.vagrantup.com/
- https://git-scm.com/downloads

Windowsでの作業

$ cd /c/iWork/01_vagrants/
$ mkdir ci4_test
$ cd ci4_test/
$ vagrant init centos/7
$ vi Vagrantfile
----------------------------
-# config.vm.network "private_network", ip: "192.168.33.10"
+config.vm.network "private_network", ip: "192.168.56.30" # 各自のPC環境による
----------------------------
$ vagrant up
$ vagrant ssh

VMにログインしての作業
$ sudo vi /etc/selinux/config
----------------------------
-SELINUX=enforcing
+SELINUX=disabled
----------------------------

Windowsでの作業
$ vagrant reload
$ vagrant ssh

VMにログインしての作業

PHP 7 のインストール
$ sudo yum install epel-release
$ sudo rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
$ sudo yum install --enablerepo=remi,remi-php74 php php-mbstring php-intl php-xml php-pdo php-mysqlnd php-fpm
$ php -v

Composer インストール
$ php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
$ php -r "if (hash_file('sha384', 'composer-setup.php') === 'e0012edf3e80b6978849f5eff0d4b4e4c79ff1609dd1e613307e16318854d24ae64f26d17af3ef0bf7cfb710ca74755a') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
$ php composer-setup.php
$ php -r "unlink('composer-setup.php');"
$ sudo mv composer.phar /usr/local/bin/composer
$ composer -V
$ sudo yum install unzip
$ composer self-update && composer create-project codeigniter4/appstarter project-example

tokenが聞かれた時の対処法
https://hacknote.jp/archives/14356/
トークンの発行
https://github.com/settings/tokens

Nginx インストール
$ sudo yum install nginx
$ sudo systemctl start nginx
$ sudo systemctl enable nginx
$ sudo vi /etc/nginx/conf.d/project-example.conf
---------------------------------------------
server {
listen 80;
server_name 192.168.56.30;
root /usr/share/nginx/html/project-example/public;
index index.php;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

location / {
try_files $uri $uri/ /index.php?$args;
}

location ~ \.php$ {
try_files $uri =404;
include fastcgi_params;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_intercept_errors on;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param CI_ENVIRONMENT development; # CI4でエラーログを表示するため
}
}
---------------------------------------------

php-fpm 設定変更
$ sudo vi /etc/php-fpm.d/www.conf
---------------------------------------------
-user = apache
-group = apache
+user = nginx
+group = nginx

-;listen = 127.0.0.1:9000
+listen = /var/run/php-fpm/php-fpm.sock

-;listen.owner = nginx
-;listen.group = nginx
-;listen.mode = 0660
+listen.owner = nginx
+listen.group = nginx
+listen.mode = 0660
---------------------------------------------

$ sudo systemctl start php-fpm
$ sudo systemctl enable php-fpm
$ sudo systemctl restart php-fpm && sudo systemctl restart nginx

$ sudo mv project-example /usr/share/nginx/html/
$ sudo vi /usr/share/nginx/html/project-example/app/Config/App.php
---------------------------------------------
-public $baseURL = 'http://localhost:8080/';
+public $baseURL = 'http://192.168.56.30/';
---------------------------------------------

ログディレクトリ等のパーミッション変更
$ sudo chmod -R 777 /usr/share/nginx/html/project-example/writable/

ブラウザで以下のURLにアクセス
http://192.168.56.30/
⇒OK


投稿日

カテゴリー:

投稿者:

タグ: