Xampp環境で開発したPHPをLAMP環境へ

/etc/apache2/sites-available/order_mvp_mvs.confの配置

# 1) ファイル作成(sudo で編集)
sudo nano /etc/apache2/sites-available/order_mvp_mvs.conf

# 中身の例
<VirtualHost *:80>
    ServerName localhost
    ServerAlias 127.0.0.1 192.168.1.50
    DocumentRoot /var/www/order_mvp_mvs

    <Directory /var/www/order_mvp_mvs>
        Options Indexes FollowSymLinks
        AllowOverride All           # .htaccess 使わないなら None
        Require all granted
    </Directory>

    ErrorLog  ${APACHE_LOG_DIR}/order_error.log
    CustomLog ${APACHE_LOG_DIR}/order_access.log combined
</VirtualHost>
有効化
sudo a2ensite order_mvp_mvs
sudo systemctl reload apache2

.htaccessの変更

output_buffering=Off
default_charset=UTF-8

PHP拡張

sudo apt update
sudo apt install -y php php-fpm php-mbstring php-xml php-mysql php-gd php-zip php-curl php-intl
sudo systemctl restart php8.3-fpm
sudo systemctl reload apache2

DB 接続(MariaDB/MySQL)

CREATE USER ‘orderapp’@’127.0.0.1’ IDENTIFIED BY ‘strong_password’;
GRANT ALL PRIVILEGES ON order_mvp.* TO ‘orderapp’@’127.0.0.1’;
FLUSH PRIVILEGES;

パス・大小文字・改行コード

Linux は大小文字区別。Windowsで通ってた Invoice.php → Linux では 404。改行コードは LF に。Git 経由なら autocrlf 設定に注意。

権限と所有者

sudo chown -R www-data:www-data /var/www/order_mvp_mvs
sudo find /var/www/order_mvp_mvs -type d -exec chmod 755 {} \;
sudo find /var/www/order_mvp_mvs -type f -exec chmod 644 {} \;

8) TCPDF のパス

すでに 複数候補を試行する実装にしてあります(Windows/XAMPP, Composer, /usr/share/php/tcpdf/tcpdf.php など)。

Ubuntu では sudo apt install php-tcpdf で /usr/share/php/tcpdf/tcpdf.php に入る系が多い。

よくある 404 / 500 の原因(Linuxで増えるやつ)

  • /orders で 404:.htaccess 無効のまま“キレイなURL”で開いている → /index.php/orders で開く。
  • POST が効かない:フォーム action の URL が /index.php/… になっていない、または CSRF エラー、または Method 不一致(GET/POST)
  • 500.htaccessphp_value を書いているが PHP-FPM 環境 → .user.ini へ移す。
  • DB 接続失敗localhost127.0.0.1 の違い、ユーザ権限、socket 認証、php-mysql 未導入。

運用コマンド & ネットワーク

# Apache
sudo systemctl status apache2
sudo systemctl reload apache2
sudo journalctl -u apache2 -f

# PHP-FPM
sudo systemctl status php8.3-fpm
sudo journalctl -u php8.3-fpm -f

# ファイアウォール(ローカル検証なら無効でもOK)
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp

サンプル:.user.ini(PHP-FPM向け) mod-phpなら不要

; /var/www/order_mvp_mvs/.user.ini
output_buffering=Off
default_charset=UTF-8

http://<サーバIP>/index.php/login で開く(まず index.php 明示)

ログイン → /index.php/orders

表示/編集/削除/請求書が /index.php/.../invoice.php で動くこと

phpinfo()Server API(Apache 2.0 Handler or FPM/FastCGI)を確認

エラー時は /var/log/apache2/*.log を必ず見る