{"id":1598,"date":"2025-08-13T10:22:36","date_gmt":"2025-08-13T01:22:36","guid":{"rendered":"https:\/\/beeknowledge.co.jp\/?p=1598"},"modified":"2025-08-13T10:22:38","modified_gmt":"2025-08-13T01:22:38","slug":"almalinux%e3%81%a7laravel-mysql-nginx-php-fpm-%e7%92%b0%e5%a2%83%e6%a7%8b%e7%af%89%e6%89%8b%e9%a0%86%ef%bc%88%e8%87%aa%e5%88%86%e3%83%a1%e3%83%a2%ef%bc%89","status":"publish","type":"post","link":"https:\/\/beeknowledge.co.jp\/?p=1598","title":{"rendered":"AlmaLinux\u3067Laravel + MySQL + nginx + PHP-FPM \u74b0\u5883\u69cb\u7bc9\u624b\u9806\uff08\u81ea\u5206\u30e1\u30e2\uff09"},"content":{"rendered":"\n<!DOCTYPE html>\n<html lang=\"ja\">\n<head>\n<meta charset=\"UTF-8\">\n<title>AlmaLinux\u3067Laravel + MySQL + nginx + PHP-FPM \u74b0\u5883\u69cb\u7bc9\u624b\u9806\uff08\u5b8c\u5168\u7248\uff09<\/title>\n<style>\n\/* \u5168\u4f53 *\/\nbody { font-family: \"Hiragino Sans\", \"Segoe UI\", sans-serif; line-height: 1.8; margin: 40px; background: #f9f9f9; color:#222; }\nh1, h2, h3 { color: #333; }\nsection { margin-bottom: 40px; }\n\n\/* \u30a4\u30f3\u30e9\u30a4\u30f3\u30b3\u30fc\u30c9\uff08\u6587\u4e2d\u306e\u77ed\u3044\u30b3\u30fc\u30c9\uff09 *\/\np code, li code, h1 code, h2 code, h3 code {\n  background: #eee;\n  color: #111;\n  padding: 2px 6px;\n  border-radius: 4px;\n  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, \"Liberation Mono\", monospace;\n  font-size: 0.95em;\n}\n\n\/* \u30b3\u30fc\u30c9\u30d6\u30ed\u30c3\u30af\uff08\u30b3\u30de\u30f3\u30c9\u3084\u8a2d\u5b9a\uff09 *\/\npre {\n  background: #1e1e1e;     \/* \u8996\u8a8d\u6027\u306e\u9ad8\u3044\u30c0\u30fc\u30af *\/\n  color: #e5e5e5;          \/* \u6587\u5b57\u8272\u3092\u660e\u308b\u304f *\/\n  padding: 14px 16px;\n  border-radius: 6px;\n  overflow-x: auto;\n  line-height: 1.6;\n  box-shadow: 0 1px 2px rgba(0,0,0,.08) inset;\n  border: 1px solid #111;\n  margin: 14px 0;\n}\n\n\/* pre \u5185\u306e code \u306f\u80cc\u666f\u3092\u900f\u660e\u306b\uff06\u7d99\u627f *\/\npre code {\n  background: transparent !important;\n  color: inherit !important;\n  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, \"Liberation Mono\", monospace;\n  font-size: 0.95em;\n  white-space: pre;         \/* \u6298\u308a\u8fd4\u3057\u306a\u3057\uff08\u6a2a\u30b9\u30af\u30ed\u30fc\u30eb\uff09 *\/\n  display: block;\n}\n\n\/* \u30e2\u30d0\u30a4\u30eb\u3067\u306e\u5fae\u8abf\u6574 *\/\n@media (max-width: 600px) {\n  body { margin: 20px; }\n  pre { font-size: 0.92em; padding: 12px; }\n}\n<\/style>\n<\/head>\n<body>\n\n<p>\u672c\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u306f\u3001<strong>AlmaLinux\u306e\u521d\u671f\u72b6\u614b\u304b\u3089<\/strong>\u3001Laravel\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092MySQL\u306b\u63a5\u7d9a\u3057\u3001nginx + PHP-FPM\u3067\u52d5\u4f5c\u3055\u305b\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u30fb\u30ad\u30e3\u30c3\u30b7\u30e5\u30fb\u30bb\u30c3\u30b7\u30e7\u30f3\u3092\u5168\u3066\u6b63\u5e38\u5316\u3059\u308b\u624b\u9806\u3092\u307e\u3068\u3081\u305f\u3082\u306e\u3067\u3059\u3002<\/p>\n\n<hr>\n\n<section>\n<h2>1. AlmaLinux\u306e\u6e96\u5099<\/h2>\n<p>\u6700\u521d\u306b\u30b7\u30b9\u30c6\u30e0\u3092\u6700\u65b0\u5316\u3057\u307e\u3059\u3002<\/p>\n<pre><code>dnf clean all\ndnf -y update\nreboot\n<\/code><\/pre>\n<\/section>\n\n<section>\n<h2>2. \u57fa\u672c\u30c4\u30fc\u30eb\u306e\u5c0e\u5165<\/h2>\n<pre><code>dnf -y install epel-release\ndnf -y install wget curl unzip git vim policycoreutils-python-utils\n<\/code><\/pre>\n<\/section>\n\n<section>\n<h2>3. nginx \u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3068\u8a2d\u5b9a<\/h2>\n<h3>3.1 \u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h3>\n<pre><code>dnf -y install nginx\nsystemctl enable nginx\nsystemctl start nginx\nsystemctl status nginx -l --no-pager\n<\/code><\/pre>\n\n<h3>3.2 \u30d5\u30a1\u30a4\u30a2\u30a6\u30a9\u30fc\u30eb\u8a2d\u5b9a<\/h3>\n<pre><code>firewall-cmd --permanent --zone=public --add-service=http\nfirewall-cmd --permanent --zone=public --add-service=https\nfirewall-cmd --reload\n<\/code><\/pre>\n\n<h3>3.3 \u52d5\u4f5c\u78ba\u8a8d<\/h3>\n<p>\u30d6\u30e9\u30a6\u30b6\u3067 <code>http:\/\/\u30b5\u30fc\u30d0IP\/<\/code> \u306b\u30a2\u30af\u30bb\u30b9\u3057\u3066 nginx \u306e\u30c7\u30d5\u30a9\u30eb\u30c8\u30da\u30fc\u30b8\u304c\u8868\u793a\u3055\u308c\u308c\u3070OK\u3067\u3059\u3002<\/p>\n<\/section>\n\n<section>\n<h2>4. PHP-FPM 8.x \u306e\u5c0e\u5165<\/h2>\n<h3>4.1 PHP\u30ea\u30dd\u30b8\u30c8\u30ea\u8ffd\u52a0<\/h3>\n<pre><code>dnf -y install https:\/\/rpms.remirepo.net\/enterprise\/remi-release-9.rpm\ndnf module reset php -y\ndnf module enable php:remi-8.2 -y\n<\/code><\/pre>\n\n<h3>4.2 PHP\u3068\u5fc5\u8981\u30e2\u30b8\u30e5\u30fc\u30eb\u5c0e\u5165<\/h3>\n<pre><code>dnf -y install php php-cli php-fpm php-mysqlnd php-opcache php-gd php-xml php-mbstring php-curl php-zip php-bcmath php-pdo php-intl\n<\/code><\/pre>\n\n<h3>4.3 PHP-FPM\u8d77\u52d5<\/h3>\n<pre><code>systemctl enable php-fpm\nsystemctl start php-fpm\nsystemctl status php-fpm -l --no-pager\n<\/code><\/pre>\n\n<h3>4.4 nginx\u3068PHP-FPM\u9023\u643a\u8a2d\u5b9a\u4f8b<\/h3>\n<pre><code>vi \/etc\/nginx\/conf.d\/laravel.conf\n<\/code><\/pre>\n<pre><code>\nserver {\n    listen 80;\n    server_name _;\n    root \/var\/www\/api\/public;\n\n    index index.php index.html index.htm;\n\n    location \/ {\n        try_files $uri $uri\/ \/index.php?$query_string;\n    }\n\n    location ~ \\.php$ {\n        include fastcgi_params;\n        fastcgi_pass unix:\/run\/php-fpm\/www.sock;\n        fastcgi_index index.php;\n        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;\n    }\n\n    location ~ \/\\.ht {\n        deny all;\n    }\n}\n<\/code><\/pre>\n\n<pre><code>nginx -t\nsystemctl restart nginx\n<\/code><\/pre>\n<\/section>\n\n<section>\n<h2>5. MySQL 8.x \u306e\u5c0e\u5165\u3068\u8a2d\u5b9a<\/h2>\n<h3>5.1 \u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h3>\n<pre><code>dnf -y install @mysql\nsystemctl enable mysqld\nsystemctl start mysqld\nsystemctl status mysqld -l --no-pager\n<\/code><\/pre>\n\n<h3>5.2 \u521d\u671f\u8a2d\u5b9a<\/h3>\n<pre><code>mysql_secure_installation\n<\/code><\/pre>\n<p>root\u30d1\u30b9\u30ef\u30fc\u30c9\u8a2d\u5b9a\u3001\u533f\u540d\u30e6\u30fc\u30b6\u30fc\u524a\u9664\u3001\u30ea\u30e2\u30fc\u30c8root\u63a5\u7d9a\u7121\u52b9\u5316\u3001\u30c6\u30b9\u30c8DB\u524a\u9664\u3092\u884c\u3044\u307e\u3059\u3002<\/p>\n\n<h3>5.3 Laravel\u7528DB\u30fb\u30e6\u30fc\u30b6\u30fc\u4f5c\u6210<\/h3>\n<pre><code>mysql -u root -p\n\nCREATE DATABASE infiniteai_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;\nCREATE USER 'infiniteai_db_user'@'127.0.0.1' IDENTIFIED BY 'M6x$+.wr';\nGRANT ALL PRIVILEGES ON infiniteai_db.* TO 'infiniteai_db_user'@'127.0.0.1';\nFLUSH PRIVILEGES;\nEXIT;\n<\/code><\/pre>\n\n<h3>5.4 \u63a5\u7d9a\u78ba\u8a8d<\/h3>\n<pre><code>mysql -u infiniteai_db_user -p'M6x$+.wr' -h 127.0.0.1 infiniteai_db -e \"SELECT 1;\"\n<\/code><\/pre>\n<\/section>\n\n<section>\n<h2>6. Laravel\u306e\u8a2d\u7f6e\u3068\u8a2d\u5b9a<\/h2>\n<h3>6.1 Laravel\u914d\u7f6e<\/h3>\n<pre><code>cd \/var\/www\ngit clone https:\/\/github.com\/example\/api.git\ncd api\ncomposer install --no-dev --optimize-autoloader\ncp .env.example .env\n<\/code><\/pre>\n\n<h3>6.2 .env\u7de8\u96c6<\/h3>\n<pre><code>APP_NAME=Laravel\nAPP_ENV=local\nAPP_KEY=base64:xxxxxxxxxxxxxxxxxxx\nAPP_DEBUG=true\nAPP_URL=http:\/\/localhost\n\nDB_CONNECTION=mysql\nDB_HOST=127.0.0.1\nDB_PORT=3306\nDB_DATABASE=infiniteai_db\nDB_USERNAME=infiniteai_db_user\nDB_PASSWORD=M6x$+.wr\n\nSESSION_DRIVER=database\nCACHE_STORE=database\n<\/code><\/pre>\n\n<h3>6.3 \u6a29\u9650\u8a2d\u5b9a<\/h3>\n<pre><code>mkdir -p storage bootstrap\/cache\nchown -R nginx:nginx storage bootstrap\/cache\nchmod -R ug+rwX storage bootstrap\/cache\n<\/code><\/pre>\n\n<h3>6.4 SELinux\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u8a2d\u5b9a<\/h3>\n<pre><code>semanage fcontext -a -t httpd_sys_rw_content_t '\/var\/www\/api\/storage(\/.*)?'\nsemanage fcontext -a -t httpd_sys_rw_content_t '\/var\/www\/api\/bootstrap\/cache(\/.*)?'\nrestorecon -Rv \/var\/www\/api\/storage \/var\/www\/api\/bootstrap\/cache\n<\/code><\/pre>\n<\/section>\n\n<section>\n<h2>7. \u30ad\u30e3\u30c3\u30b7\u30e5\u30fb\u30bb\u30c3\u30b7\u30e7\u30f3\u30c6\u30fc\u30d6\u30eb\u6e96\u5099<\/h2>\n<h3>7.1 \u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u751f\u6210<\/h3>\n<pre><code>sudo -u nginx php artisan cache:table\nsudo -u nginx php artisan session:table\nsudo -u nginx php artisan queue:table\n<\/code><\/pre>\n\n<h3>7.2 \u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u5b9f\u884c<\/h3>\n<pre><code>sudo -u nginx php artisan migrate --force\n<\/code><\/pre>\n<\/section>\n\n<section>\n<h2>8. \u30ad\u30e3\u30c3\u30b7\u30e5\u985e\u306e\u30af\u30ea\u30a2<\/h2>\n<pre><code>sudo -u nginx php artisan cache:clear\nsudo -u nginx php artisan config:clear\nsudo -u nginx php artisan route:clear\nsudo -u nginx php artisan view:clear\n<\/code><\/pre>\n<\/section>\n\n<section>\n<h2>9. \u52d5\u4f5c\u78ba\u8a8d<\/h2>\n<h3>9.1 DB\u758e\u901a<\/h3>\n<pre><code>sudo -u nginx php artisan tinker --execute=\"DB::select('SELECT 1')\"\n<\/code><\/pre>\n\n<h3>9.2 \u8a2d\u5b9a\u78ba\u8a8d<\/h3>\n<pre><code>sudo -u nginx php artisan about | grep -E 'Database|Cache|Session'\n<\/code><\/pre>\n<p>\u7d50\u679c\u4f8b\uff1a<\/p>\n<pre><code>Cache ...................................................................... database\nDatabase ................................................................... mysql\nSession ................................................................... database\n<\/code><\/pre>\n<\/section>\n\n<section>\n<h2>10. \u904b\u7528\u4e0a\u306e\u6ce8\u610f<\/h2>\n<ul>\n<li>\u672c\u756a\u3067\u306f <code>APP_ENV=production<\/code> \u306b\u3057 <code>php artisan config:cache<\/code> \u3092\u5b9f\u884c<\/li>\n<li>MySQL\u30e6\u30fc\u30b6\u30fc\u6a29\u9650\u306f\u6700\u5c0f\u9650\u306b<\/li>\n<li>SELinux\u3092\u6709\u52b9\u306b\u4fdd\u3064\u5834\u5408\u306f\u5fc5\u305a\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u3092\u8a2d\u5b9a<\/li>\n<li>nginx + PHP-FPM \u306e\u30c1\u30e5\u30fc\u30cb\u30f3\u30b0\u3092\u884c\u3044\u6027\u80fd\u5411\u4e0a<\/li>\n<\/ul>\n<\/section>\n\n<hr>\n<p>\u4ee5\u4e0a\u3067\u3001AlmaLinux\u4e0a\u306b Laravel + MySQL + nginx + PHP-FPM \u74b0\u5883\u304c\u5b8c\u6210\u3057\u307e\u3059\u3002<\/p>\n\n<\/body>\n<\/html>\n\n","protected":false},"excerpt":{"rendered":"<p>AlmaLinux\u3067Laravel + MySQL + nginx + PHP-FPM \u74b0\u5883\u69cb\u7bc9\u624b\u9806\uff08\u5b8c\u5168\u7248\uff09 \u672c\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u306f\u3001AlmaLinux\u306e\u521d\u671f\u72b6\u614b\u304b\u3089\u3001Laravel\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092MySQL\u306b\u63a5\u7d9a\u3057\u3001ng [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"saved_in_kubio":false,"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"vkexunit_cta_each_option":"","footnotes":""},"categories":[6],"tags":[51,36],"class_list":["post-1598","post","type-post","status-publish","format-standard","hentry","category-programing","tag-51","tag-36"],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/beeknowledge.co.jp\/index.php?rest_route=\/wp\/v2\/posts\/1598","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/beeknowledge.co.jp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/beeknowledge.co.jp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/beeknowledge.co.jp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/beeknowledge.co.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1598"}],"version-history":[{"count":4,"href":"https:\/\/beeknowledge.co.jp\/index.php?rest_route=\/wp\/v2\/posts\/1598\/revisions"}],"predecessor-version":[{"id":1602,"href":"https:\/\/beeknowledge.co.jp\/index.php?rest_route=\/wp\/v2\/posts\/1598\/revisions\/1602"}],"wp:attachment":[{"href":"https:\/\/beeknowledge.co.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1598"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/beeknowledge.co.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1598"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/beeknowledge.co.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1598"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}