Hello, Ubuntu!


■Ubuntuセットアップ手順メモ

-- Update kokaki@skynew:~$ sudo apt update -y -- Upgrade kokaki@skynew:~$ sudo apt upgrade -y -- ユーザー追加 kokaki@skynew:~$ sudo adduser 新しいユーザー名 kokaki@skynew:~$ sudo gpasswd -a 新しいユーザー名 sudo ■OSバージョン確認方法 kokaki@skynew:~$ cat /etc/issue Ubuntu 22.04.3 LTS \n \l -- kokaki@skynew:~$ cat /etc/os-release PRETTY_NAME="Ubuntu 22.04.3 LTS" NAME="Ubuntu" VERSION_ID="22.04" VERSION="22.04.3 LTS (Jammy Jellyfish)" VERSION_CODENAME=jammy ID=ubuntu ID_LIKE=debian HOME_URL="https://www.ubuntu.com/" SUPPORT_URL="https://help.ubuntu.com/" BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/" PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy" UBUNTU_CODENAME=jammy -- kokaki@skynew:~$ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 22.04.3 LTS Release: 22.04 Codename: jammy ■Apache2 インストール kokaki@skynew:~$ sudo apt install -y apache2 ■Apache2 ドキュメント・ルート変更 kokaki@skynew:~$ mkdir -p www/html kokaki@skynew:~$ sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/000-default.conf.org kokaki@skynew:~$ sudo vi /etc/apache2/sites-available/000-default.conf 「 <VirtualHost *:80> ServerName localhost ServerAdmin webmaster@localhost DocumentRoot /home/kokaki/www/html ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost> # vim: syntax=apache ts=4 sw=4 sts=4 sr noet 」 -- kokaki@skynew:~$ vi www/html/index.html 「 <!doctype html> <html lang="ja"> <head> <meta charset="utf-8"> <title>Hello!, Ubuntu On WSL</title> </head> <body> <h1>Hello, Ubuntu!</h1> </body> </html> 」 -- kokaki@skynew:~$ sudo cp /etc/apache2/apache2.conf /etc/apache2/apache2.conf.org kokaki@skynew:~$ sudo vi /etc/apache2/apache2.conf 「 <Directory /home/kokaki/www/> Options Indexes FollowSymLinks AllowOverride None Require all granted </Directory> 」 -- kokaki@skynew:~$ chmod 755 /home/kokaki/ -- kokaki@skynew:~$ sudo systemctl restart apache2 -- http://localhost/ 「 Hello, Ubuntu! 」 ■Apache2 SSL設定 kokaki@skynew:~$ sudo cp /etc/apache2/sites-available/default-ssl.conf /etc/apache2/sites-available/default-ssl.conf.org kokaki@skynew:~$ sudo vi /etc/apache2/sites-available/default-ssl.conf 「 <IfModule mod_ssl.c> <VirtualHost _default_:443> ServerName localhost ServerAdmin kokaki@localhost DocumentRoot /home/kokaki/www/html ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined SSLEngine on SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key <FilesMatch "\.(cgi|shtml|phtml|php)$"> SSLOptions +StdEnvVars </FilesMatch> <Directory /usr/lib/cgi-bin> SSLOptions +StdEnvVars </Directory </VirtualHost> </IfModule> 」 kokaki@skynew:~$ sudo a2ensite default-ssl Enabling site default-ssl. To activate the new configuration, you need to run: systemctl reload apache2 kokaki@skynew:~$ sudo a2mod ssl Considering dependency setenvif for ssl: Module setenvif already enabled Considering dependency mime for ssl: Module mime already enabled Considering dependency socache_shmcb for ssl: Enabling module socache_shmcb. Enabling module ssl. See /usr/share/doc/apache2/README.Debian.gz on how to configure SSL and create self-signed certificates. To activate the new configuration, you need to run: systemctl restart apache2 kokaki@skynew:~$ sudo systemctl restart apache2 https://localhost/ 「 Hello, Ubuntu! 」 ■php インストール kokaki@skynew:~$ sudo apt install -y php -- kokaki@skynew:~$ vi /home/kokaki/www/html/phpinfo.php 「 <?php phpinfo(); ?> 」 http://localhost/phpinfo.php 「 PHP Version 8.1.2-1ubuntu2.14 」 ■MySQL インストール kokaki@skynew:~$ sudo apt install -y mysql-server mysql-client kokaki@skynew:~$ mysql --version mysql Ver 8.0.35-0ubuntu0.22.04.1 for Linux on x86_64 ((Ubuntu)) kokaki@skynew:~$ sudo service mysql status ● mysql.service - MySQL Community Server Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled) Active: active (running) since Thu 2024-01-25 15:49:16 JST; 2min 11s ago Process: 11010 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS) Main PID: 11018 (mysqld) Status: "Server is operational" Tasks: 37 (limit: 9455) Memory: 373.1M CGroup: /system.slice/mysql.service └─11018 /usr/sbin/mysqld Jan 25 15:49:15 skynew systemd[1]: Starting MySQL Community Server... Jan 25 15:49:16 skynew systemd[1]: Started MySQL Community Server. ■MySQL ユーザー追加 kokaki@skynew:~$ sudo mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 9 Server version: 8.0.35-0ubuntu0.22.04.1 (Ubuntu) Copyright (c) 2000, 2023, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> CREATE USER 'dev'@'localhost' IDENTIFIED BY 'dev'; Query OK, 0 rows affected (0.02 sec) mysql> GRANT all on *.* to 'dev'@'localhost'; Query OK, 0 rows affected (0.01 sec) mysql> CREATE DATABASE dev; Query OK, 1 row affected (0.01 sec) mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.01 sec) mysql> quit Bye ■phpmyadminインストール  ※MySQLセキュリティを一時的に無効にしてインストールが〇 kokaki@skynew:~$ sudo apt install -y phpmyadmin http://localhost/phpmyadmin ■MySQL セキュリティ kokaki@skynew:~$ sudo mysql_secure_installation Securing the MySQL server deployment. Connecting to MySQL using a blank password. VALIDATE PASSWORD COMPONENT can be used to test passwords and improve security. It checks the strength of password and allows the users to set only those passwords which are secure enough. Would you like to setup VALIDATE PASSWORD component? Press y|Y for Yes, any other key for No: y There are three levels of password validation policy: LOW Length >= 8 MEDIUM Length >= 8, numeric, mixed case, and special characters STRONG Length >= 8, numeric, mixed case, special characters and dictionary file Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0 Skipping password set for root as authentication with auth_socket is used by default. If you would like to use password authentication instead, this can be done with the "ALTER_USER" command. See https://dev.mysql.com/doc/refman/8.0/en/alter-user.html#alter-user-password-management for more information. By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? (Press y|Y for Yes, any other key for No) : y Success. Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y Success. By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y - Dropping test database... Success. - Removing privileges on test database... Success. Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y Success. All done! -- 無効化/有効化 mysql> UNINSTALL COMPONENT 'file://component_validate_password'; Query OK, 0 rows affected (0.02 sec) mysql> SHOW VARIABLES LIKE 'validate_password%'; Empty set (0.00 sec) mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.01 sec) mysql> INSTALL COMPONENT 'file://component_validate_password'; Query OK, 0 rows affected (0.01 sec) mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.01 sec) ■MySQL テーブル作成 kokaki@skynew:~$ mysql -udev -p dev Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 13 Server version: 8.0.35-0ubuntu0.22.04.1 (Ubuntu) Copyright (c) 2000, 2023, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> CREATE TABLE students(id int,name varchar(20)); Query OK, 0 rows affected (0.05 sec) mysql> INSERT INTO students (id, name) values (1, 'Taro'), (2, 'Hanako'); Query OK, 2 rows affected (0.02 sec) Records: 2 Duplicates: 0 Warnings: 0 mysql> commit; Query OK, 0 rows affected (0.00 sec) mysql> show tables; +---------------+ | Tables_in_dev | +---------------+ | students | +---------------+ 1 row in set (0.00 sec) mysql> quit Bye ■php MySQLアクセス kokaki@skynew:~$ sudo apt install -y php-mysqli ■php SQLiteアクセス kokaki@skynew:~$ sudo apt install -y php-sqlite3 kokaki@skynew:~$ sudo systemctl restart apache2 http://localhost/phpmysqltest.php ■自治体コード一覧 kokaki@skynew:~$ sudo apt install -y zip unzip kokaki@skynew:~$ sudo mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 28 Server version: 8.0.35-0ubuntu0.22.04.1 (Ubuntu) Copyright (c) 2000, 2023, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> set persist local_infile=1; Query OK, 0 rows affected (0.00 sec) mysql> select @@local_infile; +----------------+ | @@local_infile | +----------------+ | 1 | +----------------+ 1 row in set (0.00 sec) mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec) mysql> quit Bye -- kokaki@skynew:~$ mysql -udev -p dev Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 13 Server version: 8.0.35-0ubuntu0.22.04.1 (Ubuntu) Copyright (c) 2000, 2023, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. CREATE TABLE M_zip_code ( jis_code varchar(5) NOT NULL, zip_code_old varchar(5) NOT NULL, zip_code varchar(7) NOT NULL, todofuken_kana varchar(100) NOT NULL, shikuchoson_kana varchar(500) NOT NULL, choiki_kana varchar(500) NOT NULL, todofuken varchar(8) NOT NULL, shikuchoson varchar(200) NOT NULL, choiki varchar(200) NOT NULL, tmp1 varchar(1) NOT NULL, tmp2 varchar(1) NOT NULL, tmp3 varchar(1) NOT NULL, tmp4 varchar(1) NOT NULL, tmp5 varchar(1) NOT NULL, tmp6 varchar(1) NOT NULL, PRIMARY KEY (jis_code, zip_code, todofuken) ); CREATE INDEX M_zip_code_IDX1 ON M_zip_code (jis_code); CREATE INDEX M_zip_code_IDX2 ON M_zip_code (zip_code); CREATE INDEX M_zip_code_IDX3 ON M_zip_code (todofuken); ■メール(とりあえずスキップする。。。) UbuntuでPostfixを使ってGmailへメールを送信する手順 https://taiyakisun.hatenablog.com/entry/2021/01/23/212423 kokaki@skynew:~$ sudo apt install mailutils kokaki@skynew:~$ sudo apt install postfix bsd-mailx libsasl2-modules kokaki@skynew:~$ sudo cp -p /etc/postfix/main.cf.proto /etc/postfix/main.cf 「 transport_maps=hash:/etc/postfix/transport relayhost = [smtp.gmail.com]:587 smtp_use_tls = yes smtp_sasl_auth_enable = yes smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd smtp_sasl_security_options = noanonymous 」 「 myhostname = <自ホスト名> mydomain = kokaki.jp inet_interfaces = all mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain mynetworks = 127.0.0.0/8, 192.168.2.0/24 sendmail_path = /usr/sbin/sendmail newaliases_path = /usr/bin/newaliases mailq_path = /usr/bin/mailq setgid_group = postdrop html_directory = no manpage_directory = /usr/share/man sample_directory = /etc/postfix readme_directory = /usr/share/doc/postfix 」 kokaki@skynew:~$ sudo newaliases kokaki@skynew:~$ sudo vi /etc/postfix/transport 「 gmail.com smtp:[smtp.gmail.com]:587 * : 」 kokaki@skynew:~$ sudo postmap /etc/postfix/transport kokaki@skynew:~$ sudo vi /etc/postfix/sasl_passwd 「 [smtp.gmail.com]:587 @gmail.com:<password> 」 kokaki@skynew:~$ sudo chmod 600 /etc/postfix/sasl_passwd kokaki@skynew:~$ sudo postmap /etc/postfix/sasl_passwd kokaki@skynew:~$ sudo systemctl restart postfix echo "test from myserver" | mail -s "test mail" kokaki@kokaki.jp /var/log/mail.log /var/log/mail.err kokaki@skynew:~$ mail Cannot create mailbox: Requested item not found sudo touch /var/mail/kokaki sudo chown kokaki:mail /var/mail/kokaki sudo chmod o-r /var/mail/kokaki sudo chmod g+rw /var/mail/kokaki ■自治体コードダウンロード kokaki@skynew:~$ cd zipcode/ kokaki@skynew:~/zipcode$ sh zip_code_import_script.sh --2024-02-07 18:12:56-- https://www.post.japanpost.jp/zipcode/dl/kogaki/zip/ken_all.zip Resolving www.post.japanpost.jp (www.post.japanpost.jp)... 43.253.48.144 Connecting to www.post.japanpost.jp (www.post.japanpost.jp)|43.253.48.144|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 1692617 (1.6M) [application/zip] Saving to: ‘ken_all.zip’ ken_all.zip 100%[=================================================>] 1.61M 8.55MB/s in 0.2s 2024-02-07 18:12:56 (8.55 MB/s) - ‘ken_all.zip’ saved [1692617/1692617] Archive: ken_all.zip inflating: KEN_ALL.CSV zip_code_import_script.sh: 59: mail: not found kokaki@skynew:~/zipcode$ cd kokaki@skynew:~$ ■Java17 インストール kokaki@skynew:~$ sudo apt install -y openjdk-17-jdk kokaki@skynew:~$ java -version openjdk version "17.0.9" 2023-10-17 OpenJDK Runtime Environment (build 17.0.9+9-Ubuntu-122.04) OpenJDK 64-Bit Server VM (build 17.0.9+9-Ubuntu-122.04, mixed mode, sharing) ■Tomcat10 インストール kokaki@skynew:~$ curl -O https://dlcdn.apache.org/tomcat/tomcat-10/v10.1.18/bin/apache-tomcat-10.1.18.tar.gz % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 11.9M 100 11.9M 0 0 9317k 0 0:00:01 0:00:01 --:--:-- 9321k kokaki@skynew:~$ tar zxvf apache-tomcat-10.1.18.tar.gz kokaki@skynew:~$ sudo mv apache-tomcat-10.1.18 /usr/libexec/tomcat10 kokaki@skynew:~$ sudo useradd -M -d /usr/libexec/tomcat10 tomcat kokaki@skynew:~$ sudo chown -R tomcat. /usr/libexec/tomcat10 kokaki@skynew:~$ sudo vi /usr/lib/systemd/system/tomcat10.service 「 [Unit] Description=Apache Tomcat 10 After=network.target [Service] Type=oneshot ExecStart=/usr/libexec/tomcat10/bin/startup.sh ExecStop=/usr/libexec/tomcat10/bin/shutdown.sh RemainAfterExit=yes User=tomcat Group=tomcat [Install] WantedBy=multi-user.target 」 kokaki@skynew:~$ sudo systemctl enable --now tomcat10 Created symlink /etc/systemd/system/multi-user.target.wants/tomcat10.service → /lib/systemd/system/tomcat10.service. http://localhost:8080/ kokaki@skynew:~$ sudo vi /usr/libexec/tomcat10/conf/tomcat-users.xml 「 <role rolename="admin-gui"/> <role rolename="manager-gui"/> <user username="tomcat" password="password" roles="admin-gui,manager-gui"/> 」 -- localhost以外の場合 kokaki@skynew:~$ sudo vi /usr/libexec/tomcat10/webapps/manager/META-INF/context.xml 「 <Context antiResourceLocking="false" privileged="true" > <CookieProcessor className="org.apache.tomcat.util.http.Rfc6265CookieProcessor" sameSiteCookies="strict" /> <!--Valve className="org.apache.catalina.valves.RemoteAddrValve" ★無効化 allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" /--> ★ 〃 <Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/> </Context> 」 kokaki@skynew:~$ sudo systemctl restart tomcat10 http://localhost:8080/manager/html Tomcat Webアプリケーションマネージャでアプリケーションを配備  ※アプリ用テーブルおよびデータの作成 -- kokaki@skynew:~$ mysql -udev -p dev Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 13 Server version: 8.0.35-0ubuntu0.22.04.1 (Ubuntu) Copyright (c) 2000, 2023, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. create table if not exists memo_data ( memo_id INT(11) auto_increment not null comment 'ID', category INT(11) comment 'カテゴリ', title VARCHAR(64) comment 'タイトル', memo TEXT comment 'メモ', create_date DATETIME comment '作成日', modified_date DATETIME comment '更新日', primary key (memo_id) ); -- CREATE TABLE `dev`.`user` ( `id` BIGINT NOT NULL AUTO_INCREMENT, `name` VARCHAR(100) NOT NULL, `address` VARCHAR(255) NULL, `phone` VARCHAR(50) NULL, `update_date` DATETIME NOT NULL, `create_date` DATETIME NOT NULL, `delete_date` DATETIME NULL, PRIMARY KEY (`id`)); INSERT INTO `dev`.`user` (`id`, `name`, `address`, `phone`, `update_date`, `create_date`) VALUES ('1', 'テスト太郎', '東京都品川区1-1', '090-0000-0000', '2021/06/30', '2021/06/30'); INSERT INTO `dev`.`user` (`id`, `name`, `address`, `phone`, `update_date`, `create_date`) VALUES ('2', 'テスト次郎', '東京都渋谷区1-1', '080-0000-0000', '2021/06/30', '2021/06/30'); -- CREATE TABLE `dev`.`userinfo` ( `id` BIGINT NOT NULL AUTO_INCREMENT, `name` VARCHAR(100) NOT NULL, `address` VARCHAR(255) NULL, `phone` VARCHAR(50) NULL, `update_date` DATETIME NOT NULL, `create_date` DATETIME NOT NULL, `delete_date` DATETIME NULL, PRIMARY KEY (`id`)); INSERT INTO `dev`.`userinfo` (`id`, `name`, `address`, `phone`, `update_date`, `create_date`) VALUES ('1', 'テスト太郎', '東京都品川区1-1', '090-0000-0000', '2021/06/30', '2021/06/30'); INSERT INTO `dev`.`userinfo` (`id`, `name`, `address`, `phone`, `update_date`, `create_date`) VALUES ('2', 'テスト次郎', '東京都渋谷区1-1', '080-0000-0000', '2021/06/30', '2021/06/30'); ■Apache2,Tomcat10連携 kokaki@skynew:~$ sudo a2enmod proxy Enabling module proxy. To activate the new configuration, you need to run: systemctl restart apache2 kokaki@skynew:~$ sudo a2enmod proxy_ajp Considering dependency proxy for proxy_ajp: Module proxy already enabled Enabling module proxy_ajp. To activate the new configuration, you need to run: systemctl restart apache2 kokaki@skynew:~$ sudo vi /usr/libexec/tomcat10/conf/server.xml 「 <Connector protocol="AJP/1.3" address="0.0.0.0" port="8009" redirectPort="8443" secretRequired="false" /> 」 kokaki@skynew:~$ sudo vi /etc/apache2/sites-available/tomcat.conf 「 ProxyPass /manager ajp://localhost:8009/manager ProxyPassReverse /manager ajp://localhost:8009/manager ProxyPass /springMyBatis ajp://localhost:8009/springMyBatis ProxyPassReverse /springMyBatis ajp://localhost:8009/springMyBatis ProxyPass /springJpa ajp://localhost:8009/springJpa ProxyPassReverse /springJpa ajp://localhost:8009/springJpa ProxyPass /memoapp ajp://localhost:8009/memoapp ProxyPassReverse /memoapp ajp://localhost:8009/memoapp 」 kokaki@skynew:~$ sudo a2ensite tomcat kokaki@skynew:~$ sudo systemctl restart apache2 kokaki@skynew:~$ sudo systemctl restart tomcat10 ■zip,unzip,tree,sqlite3インストール kokaki@skynew:~$ sudo apt install -y zip unzip tree sqlite3 ■WSL -- wsl一覧表示 PS C:\Users\pc> wsl -l -v NAME STATE VERSION * Ubuntu Stopped 2 Ubuntu-22.04 Stopped 2 --スナップショットの作成 PS C:\Users\pc> mkdir wsl_snapshot PS C:\Users\pc> wsl --export Ubuntu-22.04 wsl_snapshot/ubuntu-22.04_20240126.tar エクスポートが進行中です。これには数分かかる場合があります。 この操作を正しく終了しました。 -- スナップショットの活用 PS C:\Users\pc> mkdir wsl_vhdx PS C:\Users\pc> wsl --import ubuntu001 wsl_vhdx/ubuntu001 wsl_snapshot/ubuntu-22.04_20240126.tar PS C:\Users\pc> wsl -l -v NAME STATE VERSION * Ubuntu Stopped 2 Ubuntu-22.04 Stopped 2 ubuntu001 Running 2 -- wslの起動 PS C:\Users\pc> wsl --distribution ubuntu001 --user kokaki -- wslの登録解除 PS C:\Users\pc> wsl --unregister ubuntu001 ------------------------------------------------------------------ 以下のステップは、参考程度。Redmineのセットアップを行う。 ■Ubuntuで「Ruby on Railsチュートリアル」の実行環境を作る https://qiita.com/EeetaEngineer/items/e4adb395249386f883c3 -- 必要なツールをダウンロード sudo apt update -y sudo apt upgrade -y sudo apt install build-essential -y sudo apt install -y libssl-dev libreadline-dev zlib1g-dev sudo apt install libyaml-dev sudo apt install libssl-dev -- Ruby、Railsをインストール git clone https://github.com/sstephenson/rbenv.git ~/.rbenv echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc echo 'eval "$(rbenv init -)"' >> ~/.bashrc exec $SHELL -l git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build #Ruby on Railsチュートリアルにバージョンを合わせます rbenv install 3.1.2 rbenv global 3.1.2 -- Railsをインストール gem install rails -v "7.0.4" #動作確認 rails -v -- bundlerをインストール gem install bundler -v 2.3.14 --SQliteをインストール sudo apt install libsqlite3-dev ■Rails をはじめよう https://railsguides.jp/getting_started.html Gemfile gem 'passenger' ■Passenger Redmine 5.0 をUbuntu 22.04 LTSにインストールする手順 https://blog.redmine.jp/articles/5_0/install/ubuntu/ sudo apt update sudo apt install -y build-essential zlib1g-dev libssl-dev libreadline-dev libyaml-dev libcurl4-openssl-dev libffi-dev sudo apt install -y apache2 apache2-dev sudo apt install -y imagemagick fonts-takao-pgothic gem install passenger -N passenger-install-apache2-module --auto --languages ruby passenger-install-apache2-module --snippet LoadModule passenger_module /home/kokaki/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/passenger-6.0.20/buildout/apache2/mod_passenger.so <IfModule mod_passenger.c> PassengerRoot /home/kokaki/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/passenger-6.0.20 PassengerDefaultRuby /home/kokaki/.rbenv/versions/3.1.2/bin/ruby </IfModule> ・/etc/apache2/sites-available/rails.conf 「 LoadModule passenger_module /home/kokaki/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/passenger-6.0.20/buildout/apache2/mod_passenger.so <IfModule mod_passenger.c> PassengerRoot /home/kokaki/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/passenger-6.0.20 PassengerDefaultRuby /home/kokaki/.rbenv/versions/3.1.2/bin/ruby </IfModule> PassengerMaxPoolSize 20 PassengerMaxInstancesPerApp 4 PassengerPoolIdleTime 864000 PassengerStatThrottleRate 10 #<Directory /home/kokaki/www/rails/blog/public> # Allow from all # Options -MultiViews # Require all granted #</Directory> Alias /blog /home/kokaki/www/rails/blog/public <Location /blog> PassengerBaseURI /blog PassengerAppRoot /home/kokaki/www/rails/blog </Location> Alias /books /home/kokaki/www/rails/books/public <Location /books> PassengerBaseURI /books PassengerAppRoot /home/kokaki/www/rails/books </Location> 」 ・/var/log/apache2/error.log [Sat Jan 27 20:21:01.792120 2024] [mpm_prefork:notice] [pid 489] AH00171: Graceful restart requested, doing restart [ N 2024-01-27 20:21:01.8959 19031/T1 age/Wat/WatchdogMain.cpp:1377 ]: Starting Passenger watchdog... [ N 2024-01-27 20:21:01.9107 19041/T1 age/Cor/CoreMain.cpp:1340 ]: Starting Passenger core... [ N 2024-01-27 20:21:01.9109 19041/T1 age/Cor/CoreMain.cpp:256 ]: Passenger core running in multi-application mode. [ W 2024-01-27 20:21:01.9787 19041/T1 age/Cor/CoreMain.cpp:1007 ]: WARNING: potential privilege escalation vulnerability detected. Phusion Passenger(R) is running as root, and part(s) of the Passenger root path (/home/kokaki/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/passenger-6.0.20) can be changed by non-root user(s): - /home/kokaki/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/passenger-6.0.20 is not secure: it can be modified by user kokaki - /home/kokaki/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems is not secure: it can be modified by user kokaki - /home/kokaki/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0 is not secure: it can be modified by user kokaki - /home/kokaki/.rbenv/versions/3.1.2/lib/ruby/gems is not secure: it can be modified by user kokaki - /home/kokaki/.rbenv/versions/3.1.2/lib/ruby is not secure: it can be modified by user kokaki - /home/kokaki/.rbenv/versions/3.1.2/lib is not secure: it can be modified by user kokaki - /home/kokaki/.rbenv/versions/3.1.2 is not secure: it can be modified by user kokaki - /home/kokaki/.rbenv/versions is not secure: it can be modified by user kokaki - /home/kokaki/.rbenv is not secure: it can be modified by user kokaki - /home/kokaki is not secure: it can be modified by user kokaki Please either fix up the permissions for the insecure paths, or install Passenger in a different location that can only be modified by root. [ N 2024-01-27 20:21:01.9787 19041/T1 age/Cor/CoreMain.cpp:1015 ]: Passenger core online, PID 19041 [Sat Jan 27 20:21:01.980065 2024] [mpm_prefork:notice] [pid 489] AH00163: Apache/2.4.52 (Ubuntu) mod_wsgi/4.9.0 Python/3.10 Phusion_Passenger/6.0.20 configured -- resuming normal operations [Sat Jan 27 20:21:01.980107 2024] [core:notice] [pid 489] AH00094: Command line: '/usr/sbin/apache2' [ N 2024-01-27 20:21:05.2055 19041/T5 age/Cor/SecurityUpdateChecker.h:519 ]: Security update check: no update found (next check in 24 hours) ・/etc/apache2/sites-available/rails.conf 「 LoadModule passenger_module /home/kokaki/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/passenger-6.0.20/buildout/apache2/mod_passenger.so <IfModule mod_passenger.c> PassengerRoot /home/kokaki/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/passenger-6.0.20 PassengerDefaultRuby /home/kokaki/.rbenv/versions/3.1.2/bin/ruby </IfModule> PassengerMaxPoolSize 20 PassengerMaxInstancesPerApp 4 PassengerPoolIdleTime 864000 PassengerStatThrottleRate 10 PassengerUserSwitching off ★ PassengerDefaultUser kokaki ★ #<Directory /home/kokaki/www/rails/blog/public> # Allow from all # Options -MultiViews # Require all granted #</Directory> Alias /blog /home/kokaki/www/rails/blog/public <Location /blog> PassengerBaseURI /blog PassengerAppRoot /home/kokaki/www/rails/blog </Location> Alias /books /home/kokaki/www/rails/books/public <Location /books> PassengerBaseURI /books PassengerAppRoot /home/kokaki/www/rails/books </Location> 」 ・/var/log/apache2/error.log [Sat Jan 27 21:24:23.443367 2024] [mpm_prefork:notice] [pid 489] AH00171: Graceful restart requested, doing restart [ N 2024-01-27 21:24:23.4622 21303/T8 age/Cor/CoreMain.cpp:670 ]: Signal received. Gracefully shutting down... (send signal 2 more time(s) to force shutdown) [ N 2024-01-27 21:24:23.4623 21303/T1 age/Cor/CoreMain.cpp:1245 ]: Received command to shutdown gracefully. Waiting until all clients have disconnected... [ N 2024-01-27 21:24:23.4624 21303/T8 Ser/Server.h:901 ]: [ServerThr.1] Freed 0 spare client objects [ N 2024-01-27 21:24:23.4624 21303/Ta Ser/Server.h:901 ]: [ServerThr.2] Freed 0 spare client objects [ N 2024-01-27 21:24:23.4624 21303/Te Ser/Server.h:901 ]: [ServerThr.4] Freed 0 spare client objects [ N 2024-01-27 21:24:23.4624 21303/Ta Ser/Server.h:558 ]: [ServerThr.2] Shutdown finished [ N 2024-01-27 21:24:23.4625 21303/Te Ser/Server.h:558 ]: [ServerThr.4] Shutdown finished [ N 2024-01-27 21:24:23.4625 21303/Tm Ser/Server.h:901 ]: [ServerThr.8] Freed 0 spare client objects [ N 2024-01-27 21:24:23.4625 21303/Tk Ser/Server.h:901 ]: [ServerThr.7] Freed 0 spare client objects [ N 2024-01-27 21:24:23.4625 21303/Tg Ser/Server.h:901 ]: [ServerThr.5] Freed 0 spare client objects [ N 2024-01-27 21:24:23.4625 21303/Tm Ser/Server.h:558 ]: [ServerThr.8] Shutdown finished [ N 2024-01-27 21:24:23.4625 21303/Tk Ser/Server.h:558 ]: [ServerThr.7] Shutdown finished [ N 2024-01-27 21:24:23.4625 21303/Tg Ser/Server.h:558 ]: [ServerThr.5] Shutdown finished [ N 2024-01-27 21:24:23.4624 21303/Tc Ser/Server.h:901 ]: [ServerThr.3] Freed 0 spare client objects [ N 2024-01-27 21:24:23.4626 21303/Tc Ser/Server.h:558 ]: [ServerThr.3] Shutdown finished [ N 2024-01-27 21:24:23.4624 21303/T8 Ser/Server.h:558 ]: [ServerThr.1] Shutdown finished [ N 2024-01-27 21:24:23.4626 21303/Ti Ser/Server.h:901 ]: [ServerThr.6] Freed 0 spare client objects [ N 2024-01-27 21:24:23.4626 21303/Ti Ser/Server.h:558 ]: [ServerThr.6] Shutdown finished [ N 2024-01-27 21:24:23.4707 21303/To Ser/Server.h:901 ]: [ApiServer] Freed 0 spare client objects [ N 2024-01-27 21:24:23.4708 21303/To Ser/Server.h:558 ]: [ApiServer] Shutdown finished [ N 2024-01-27 21:24:23.5648 21368/T1 age/Wat/WatchdogMain.cpp:1377 ]: Starting Passenger watchdog... [ N 2024-01-27 21:24:23.5809 21378/T1 age/Cor/CoreMain.cpp:1340 ]: Starting Passenger core... [ N 2024-01-27 21:24:23.5810 21378/T1 age/Cor/CoreMain.cpp:256 ]: Passenger core running in multi-application mode. [ N 2024-01-27 21:24:23.6881 21378/T1 age/Cor/CoreMain.cpp:1015 ]: Passenger core online, PID 21378 [Sat Jan 27 21:24:23.689284 2024] [mpm_prefork:notice] [pid 489] AH00163: Apache/2.4.52 (Ubuntu) mod_wsgi/4.9.0 Python/3.10 Phusion_Passenger/6.0.20 configured -- resuming normal operations [Sat Jan 27 21:24:23.689315 2024] [core:notice] [pid 489] AH00094: Command line: '/usr/sbin/apache2' [ N 2024-01-27 21:24:24.7133 21303/T1 age/Cor/CoreMain.cpp:1325 ]: Passenger core shutdown finished [ N 2024-01-27 21:24:26.8003 21378/T5 age/Cor/SecurityUpdateChecker.h:519 ]: Security update check: no update found (next check in 24 hours) ・vi log/production.log F, [2024-01-27T21:40:56.510790 #22102] FATAL -- : [ef97ebb2-99c0-4935-b9cb-68c27f720d4a] [ef97ebb2-99c0-4935-b9cb-68c27f720d4a] ActionView::Template::Error (SQLite3::SQLException: no such table: articles): [ef97ebb2-99c0-4935-b9cb-68c27f720d4a] 1: <h1>Articles</h1> [ef97ebb2-99c0-4935-b9cb-68c27f720d4a] 2: [ef97ebb2-99c0-4935-b9cb-68c27f720d4a] 3: <ul> [ef97ebb2-99c0-4935-b9cb-68c27f720d4a] 4: <% @articles.each do |article| %> [ef97ebb2-99c0-4935-b9cb-68c27f720d4a] 5: <li> [ef97ebb2-99c0-4935-b9cb-68c27f720d4a] 6: <%= link_to article.title, article %> [ef97ebb2-99c0-4935-b9cb-68c27f720d4a] 7: </li> [ef97ebb2-99c0-4935-b9cb-68c27f720d4a] [ef97ebb2-99c0-4935-b9cb-68c27f720d4a] app/views/articles/index.html.erb:4 kokaki@skynew:~/www/rails/blog$ rake db:create RAILS_ENV=production kokaki@skynew:~/www/rails/blog$ rake db:migrate RAILS_ENV=production ・vi log/production.log F, [2024-01-27T21:58:22.790468 #22652] FATAL -- : [07498640-c14e-4fab-876f-6bc0f460658c] [07498640-c14e-4fab-876f-6bc0f460658c] ActionView::Template::Error (The asset "application.css" is not present in the asset pipeline.): [07498640-c14e-4fab-876f-6bc0f460658c] 6: <%= csrf_meta_tags %> [07498640-c14e-4fab-876f-6bc0f460658c] 7: <%= csp_meta_tag %> [07498640-c14e-4fab-876f-6bc0f460658c] 8: [07498640-c14e-4fab-876f-6bc0f460658c] 9: <%= stylesheet_link_tag "application", "data-turbo-track": "reload" %> [07498640-c14e-4fab-876f-6bc0f460658c] 10: <%= javascript_importmap_tags %> [07498640-c14e-4fab-876f-6bc0f460658c] 11: </head> [07498640-c14e-4fab-876f-6bc0f460658c] 12: [07498640-c14e-4fab-876f-6bc0f460658c] [07498640-c14e-4fab-876f-6bc0f460658c] app/views/layouts/application.html.erb:9 ・Gemfile kokaki@skynew:~/www/rails/blog$ vi Gemfile gem "sassc-rails" ★コメントをはずし有効化 kokaki@skynew:~/www/rails/books$ rails assets:precompile RAILS_ENV=production rails aborted! ExecJS::RuntimeUnavailable: Could not find a JavaScript runtime. See https://github.com/rails/execjs for a list of available runtimes. /home/kokaki/www/rails/books/config/application.rb:7:in `
' /home/kokaki/www/rails/books/Rakefile:4:in `require_relative' /home/kokaki/www/rails/books/Rakefile:4:in `
' bin/rails:4:in `
' (See full trace by running task with --trace) kokaki@skynew:~/www/rails/books$ sudo apt install nodejs ★nodejsをインストールすれば回避! kokaki@skynew:~/www/rails/books$ rails assets:precompile RAILS_ENV=production kokaki@skynew:~/www/rails/blog$ vi config/environments/production.rb config.assets.css_compressor = :sass ★コメントをはずし有効化 kokaki@skynew:~$ sudo vi /etc/apache2/sites-available/rails2.conf 「 LoadModule passenger_module /home/kokaki/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/passenger-6.0.20/buildout/apache2/mod_passenger.so <IfModule mod_passenger.c> PassengerRoot /home/kokaki/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/passenger-6.0.20 PassengerDefaultRuby /home/kokaki/.rbenv/versions/3.1.2/bin/ruby PassengerMaxPoolSize 20 PassengerMaxInstancesPerApp 4 PassengerPoolIdleTime 864000 PassengerStatThrottleRate 10 PassengerUserSwitching off PassengerDefaultUser kokaki </IfModule> #<VirtualHost *:80> # ServerName rails.localhost # <Directory /home/kokaki/www/rails/blog/public> # Allow from all # Options -MultiViews # Require all granted # </Directory> Alias /blog /home/kokaki/www/rails/blog/public <Location /blog> PassengerBaseURI /blog PassengerAppRoot /home/kokaki/www/rails/blog </Location> Alias /books /home/kokaki/www/rails/books/public <Location /books> PassengerBaseURI /books PassengerAppRoot /home/kokaki/www/rails/books </Location> #</VirtualHost> 」 kokaki@skynew:~$ sudo a2ensite rails kokaki@skynew:~$ sudo systemctl restart apache2 ※railsプロジェクトで、bundle updateを実行 ■コンパイルでメモリ不足が発生したら、スワップを定義 c++: fatal error: Killed signal terminated program cc1plus 「 When compiling C++ in the Linux system, the following error occurs, causing the compilation to abort: Problem description Solution - swap partition [Solution - Swap partition] After checking the relevant information, it is believed that the virtual machine memory is insufficient. This problem was solved by creating a swap partition, and the compilation was successful. The following summarizes the creation and activation of swap partitions: 1. sudo mkdir -p /var/cache/swap/ 2. sudo dd if=/dev/zero of=/var/cache/swap/swap0 bs=64M count=64 3. sudo chmod 0600 /var/cache/swap/swap0 4. sudo mkswap /var/cache/swap/swap0 5. sudo swapon /var/cache/swap/swap0 6. sudo swapon -s Note: The path of the swap0 file is under /var/cache/swap/. After compiling, if you don't want the swap partition, you can delete it. Command to delete swap partition: 」

■開発関連のリンク

ApacheのPHPからMySQLアクセス
UbuntuにMySQLをインストールして、ApacheのPHPからアクセスするまで
--
SpringBootでToDoアプリ
SpringBootでToDoアプリを作ってみよう【誰でも作れます・初心者向け】
--
SpringBootで読書管理アプリ
【Spring Boot超入門】Eclipseを使って書籍管理Webアプリを開発する【全7回】
--
SpringBootでユーザー登録
Spring Boot + Thymeleafで一覧画面を作成する
Spring Boot + Thymeleafで新規登録画面を作成する
Spring Boot + Thymeleafで詳細画面を作成する
Spring Boot + Thymeleafで編集画面を作成する
Spring Boot + JPAでデータを物理削除する
EclipseでSpring Bootの環境構築 | 分かりやすく図解で説明
Spring Boot+Thymeleafで”Hello World”を作成する
Spring Boot+JPAでデータベースに接続する方法
Spring Boot+MyBatisでデータベースに接続する
MyBatis + SpringでWebアプリ(CRUD)を作成する
--
Webアプリ初心者のFlaskチュートリアル
--
Python Flask + SQLAlchemy:[todo]
PythonのFlaskでデータベースを利用する方法(Flask-SQLAlchemy)
--
【Python Flask & SQLAlchemy】:[testapp]
【Python Flask】初心者プログラマーのWebアプリ#1 簡単なページ作成
【Python Flask】初心者プログラマーのWebアプリ#2 HTMLテンプレート表示
【Python Flask】初心者プログラマーのWebアプリ#3 【Javascript導入】【画像表示】【CSS適用】
【Python Flask】初心者プログラマーのWebアプリ#4 フォーム POST/GET送信・受け取り
【Python Flask & SQLAlchemy】初心者プログラマーのWebアプリ#5 DB登録/取得/編集/削除【CRUD】
--
Rails をはじめよう
【Ruby on Rails】ToDoアプリを簡単に作ってみる ~ その1. index new create ~
【Ruby on Rails】ToDoアプリを簡単に作ってみる ~ その2. show, edit, update, destroy ~
Ruby - Ruby on Rails - apache との連動
--
Why is Spring Boot 3 WAR not running in Tomcat 10 or 11?
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.0.4</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>