Compilare un ambiente LAMP da sorgente su Linux (RHEL e Debian/Ubuntu)

Lamp Console Linux

Questa guida descrive come compilare e installare un ambiente LAMP (Apache, MariaDB, PHP) da sorgente su Linux, in modalità non root e portabile: tutti i componenti vengono installati in una directory dedicata, senza toccare i pacchetti di sistema.

La procedura è divisa in due sezioni:

  • RHEL-based: Oracle Linux 10, AlmaLinux 10, Rocky Linux 10
  • Debian/Ubuntu: Debian 13, Ubuntu 26

Le versioni di riferimento sono:

ComponenteVersione
Apache2.4.65
PHP8.4.12
MariaDB12.1.1

Sezione 1 — RHEL-based (Oracle Linux 10, AlmaLinux 10, Rocky Linux 10)

Variabili di configurazione

export LAMP_ROOT="/mnt/local1tb/Alma10/lamp"
export SITIWEB_ROOT="/mnt/local1tb/Alma10/sitiweb"
export TEMP_BUILD="/mnt/local2tb/temp"
export APACHE_PORT="8080"
export MARIADB_PORT="3307"
export APACHE_VERSION="2.4.65"
export PHP_VERSION="8.4.12"
export MARIADB_VERSION="12.1.1"
export USER_LAMP=$(whoami)

Dipendenze di sistema

# Creazione directory
mkdir -p $LAMP_ROOT $SITIWEB_ROOT $TEMP_BUILD
mkdir -p $LAMP_ROOT/apache-$APACHE_VERSION \
         $LAMP_ROOT/php-$PHP_VERSION \
         $LAMP_ROOT/mariadb-$MARIADB_VERSION

# Installazione dipendenze
sudo dnf groupinstall "Development Tools"
sudo dnf install wget cmake pcre2-devel expat-devel openssl-devel \
    libxml2-devel sqlite-devel oniguruma-devel libcurl-devel \
    libjpeg-devel libpng-devel freetype-devel gmp-devel \
    libzip-devel readline-devel ncurses-devel boost-devel \
    bison flex re2c libxslt-devel perl \
    gnutls-devel gnutls-c++ gnutls-dane gnutls-utils

Apache

cd $TEMP_BUILD

# Download Apache, APR e APR-util
wget https://archive.apache.org/dist/httpd/httpd-$APACHE_VERSION.tar.gz
wget https://archive.apache.org/dist/apr/apr-1.7.5.tar.gz
wget https://archive.apache.org/dist/apr/apr-util-1.6.3.tar.gz

# Estrazione
tar xzf httpd-$APACHE_VERSION.tar.gz
tar xzf apr-1.7.5.tar.gz
tar xzf apr-util-1.6.3.tar.gz

# Copia APR nelle directory di Apache (compilazione integrata)
cp -r apr-1.7.5 httpd-$APACHE_VERSION/srclib/apr
cp -r apr-util-1.6.3 httpd-$APACHE_VERSION/srclib/apr-util

cd httpd-$APACHE_VERSION

./configure \
    --prefix=$LAMP_ROOT/apache-$APACHE_VERSION \
    --enable-rewrite \
    --enable-ssl \
    --enable-deflate \
    --enable-headers \
    --enable-expires \
    --enable-mime-magic \
    --enable-info \
    --enable-status \
    --enable-userdir \
    --enable-vhost-alias \
    --enable-dir \
    --enable-alias \
    --enable-so \
    --enable-proxy \
    --enable-proxy-fcgi \
    --enable-shared=max \
    --with-included-apr

make -j$(nproc)
make install

Individua il percorso di apxs, che servirà per la compilazione di PHP:

find $LAMP_ROOT/apache-$APACHE_VERSION -name "apxs" -type f

PHP

cd $TEMP_BUILD

wget https://www.php.net/distributions/php-$PHP_VERSION.tar.gz
tar xzf php-$PHP_VERSION.tar.gz
cd php-$PHP_VERSION

./configure \
    --prefix=$LAMP_ROOT/php-$PHP_VERSION \
    --with-apxs2=$LAMP_ROOT/apache-$APACHE_VERSION/bin/apxs \
    --enable-fpm \
    --with-fpm-user=$USER_LAMP \
    --with-fpm-group=$USER_LAMP \
    --with-config-file-path=$LAMP_ROOT/php-$PHP_VERSION/lib \
    --enable-mbstring \
    --enable-bcmath \
    --enable-pcntl \
    --enable-ftp \
    --enable-exif \
    --enable-calendar \
    --enable-opcache \
    --enable-pdo \
    --enable-mysqlnd \
    --with-mysqli=mysqlnd \
    --with-pdo-mysql=mysqlnd \
    --with-curl \
    --with-libxml \
    --with-gmp \
    --with-zlib \
    --with-bz2=shared \
    --with-jpeg \
    --with-freetype \
    --enable-gd \
    --with-openssl \
    --with-gettext \
    --with-xsl \
    --enable-soap \
    --enable-intl \
    --with-readline \
    --enable-sockets \
    --enable-zip

make -j$(nproc)
make install

cp php.ini-development $LAMP_ROOT/php-$PHP_VERSION/lib/php.ini

MariaDB

cd $TEMP_BUILD

wget https://downloads.mariadb.org/rest-api/mariadb/$MARIADB_VERSION/mariadb-$MARIADB_VERSION.tar.gz
tar xzf mariadb-$MARIADB_VERSION.tar.gz
cd mariadb-$MARIADB_VERSION

cmake . \
    -DCMAKE_INSTALL_PREFIX=$LAMP_ROOT/mariadb-$MARIADB_VERSION \
    -DMYSQL_DATADIR=$LAMP_ROOT/mariadb-$MARIADB_VERSION/data \
    -DMYSQL_UNIX_ADDR=$LAMP_ROOT/mariadb-$MARIADB_VERSION/mysql.sock \
    -DMYSQL_USER=$USER_LAMP \
    -DWITH_INNOBASE_STORAGE_ENGINE=1 \
    -DWITH_ARCHIVE_STORAGE_ENGINE=1 \
    -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
    -DWITH_READLINE=1 \
    -DWITH_SSL=system \
    -DWITH_ZLIB=system \
    -DDEFAULT_CHARSET=utf8mb4 \
    -DDEFAULT_COLLATION=utf8mb4_unicode_ci

make -j$(nproc)
make install

Sezione 2 — Debian/Ubuntu (Debian 13, Ubuntu 26)

Variabili di configurazione

export LAMP_ROOT="/mnt/local1tb/Debian13/lamp"
export SITES_ROOT="/mnt/local1tb/Debian13/sitiweb"
export SESSION_ROOT="${LAMP_ROOT}/sessions_data"
export BUILD_DIR="/mnt/local2tb/temp"
export APACHE_VERSION="2.4.65"
export PHP_VERSION="8.4.12"
export MARIADB_VERSION="12.1.1"
export APACHE_PORT="8080"
export MARIADB_PORT="3307"
export USER_NAME=$(whoami)

Dipendenze di sistema

# Creazione directory
mkdir -p $LAMP_ROOT $SITES_ROOT $BUILD_DIR $SESSION_ROOT
mkdir -p $LAMP_ROOT/apache-$APACHE_VERSION \
         $LAMP_ROOT/php-$PHP_VERSION \
         $LAMP_ROOT/mariadb-$MARIADB_VERSION

# Installazione dipendenze
sudo apt update
sudo apt install -y build-essential wget curl git cmake \
    libssl-dev libexpat1-dev libpcre2-dev zlib1g-dev \
    libxml2-dev libbz2-dev libcurl4-openssl-dev \
    libjpeg-dev libpng-dev libfreetype6-dev \
    libonig-dev libzip-dev libsqlite3-dev \
    libreadline-dev libncurses-dev pkg-config \
    bison flex libgnutls28-dev libgmp-dev \
    libxslt1-dev re2c

Apache

In Debian/Ubuntu le librerie APR di sistema sono sufficienti, ma per garantire compatibilità si consiglia di compilarle integrate come per RHEL. In alternativa, con i pacchetti libapr1-dev e libaprutil1-dev già installati, è possibile omettere --with-included-apr.

cd $BUILD_DIR

wget https://archive.apache.org/dist/httpd/httpd-${APACHE_VERSION}.tar.gz
wget https://archive.apache.org/dist/apr/apr-1.7.5.tar.gz
wget https://archive.apache.org/dist/apr/apr-util-1.6.3.tar.gz

tar xzf httpd-${APACHE_VERSION}.tar.gz
tar xzf apr-1.7.5.tar.gz
tar xzf apr-util-1.6.3.tar.gz

cp -r apr-1.7.5 httpd-${APACHE_VERSION}/srclib/apr
cp -r apr-util-1.6.3 httpd-${APACHE_VERSION}/srclib/apr-util

cd httpd-${APACHE_VERSION}

./configure \
    --prefix=${LAMP_ROOT}/apache-${APACHE_VERSION} \
    --enable-rewrite \
    --enable-ssl \
    --enable-deflate \
    --enable-headers \
    --enable-expires \
    --enable-mime-magic \
    --enable-info \
    --enable-status \
    --enable-cgi \
    --enable-vhost-alias \
    --enable-negotiation \
    --enable-dir \
    --enable-alias \
    --enable-so \
    --enable-proxy \
    --enable-proxy-fcgi \
    --enable-userdir \
    --enable-unique-id \
    --with-included-apr

make -j$(nproc)
make install

cd $BUILD_DIR
rm -rf httpd-${APACHE_VERSION} httpd-${APACHE_VERSION}.tar.gz \
       apr-1.7.5 apr-1.7.5.tar.gz \
       apr-util-1.6.3 apr-util-1.6.3.tar.gz

PHP

cd $BUILD_DIR

wget https://www.php.net/distributions/php-${PHP_VERSION}.tar.gz
tar xzf php-${PHP_VERSION}.tar.gz
cd php-${PHP_VERSION}

./configure \
    --prefix=${LAMP_ROOT}/php-${PHP_VERSION} \
    --enable-fpm \
    --with-fpm-user=${USER_NAME} \
    --with-fpm-group=${USER_NAME} \
    --with-config-file-path=${LAMP_ROOT}/php-${PHP_VERSION}/etc \
    --with-config-file-scan-dir=${LAMP_ROOT}/php-${PHP_VERSION}/etc/conf.d \
    --enable-bcmath \
    --enable-calendar \
    --enable-exif \
    --enable-ftp \
    --enable-gd \
    --with-freetype \
    --with-jpeg \
    --enable-intl \
    --enable-mbstring \
    --with-mysqli=mysqlnd \
    --enable-mysqlnd \
    --with-pdo-mysql=mysqlnd \
    --enable-opcache \
    --with-openssl \
    --enable-pcntl \
    --enable-posix \
    --enable-session \
    --enable-shmop \
    --enable-soap \
    --enable-sockets \
    --with-sodium \
    --enable-sysvmsg \
    --enable-sysvsem \
    --enable-sysvshm \
    --with-curl \
    --with-zip \
    --with-zlib \
    --with-gmp \
    --with-gettext \
    --with-xsl \
    --enable-fileinfo

make -j$(nproc)
make install

cp php.ini-development ${LAMP_ROOT}/php-${PHP_VERSION}/etc/php.ini

cd $BUILD_DIR
rm -rf php-${PHP_VERSION} php-${PHP_VERSION}.tar.gz

MariaDB

Su Debian/Ubuntu si scarica il sorgente da GitHub per maggiore affidabilità:

cd $BUILD_DIR

git clone --branch mariadb-${MARIADB_VERSION} \
    https://github.com/MariaDB/server.git mariadb-${MARIADB_VERSION}
cd mariadb-${MARIADB_VERSION}
git submodule update --init --recursive

mkdir build && cd build

cmake .. \
    -DCMAKE_INSTALL_PREFIX=${LAMP_ROOT}/mariadb-${MARIADB_VERSION} \
    -DMYSQL_DATADIR=${LAMP_ROOT}/mariadb-${MARIADB_VERSION}/data \
    -DMYSQL_UNIX_ADDR=${LAMP_ROOT}/mariadb-${MARIADB_VERSION}/mysql.sock \
    -DDEFAULT_CHARSET=utf8mb4 \
    -DDEFAULT_COLLATION=utf8mb4_unicode_ci \
    -DWITH_INNOBASE_STORAGE_ENGINE=1 \
    -DWITH_ARCHIVE_STORAGE_ENGINE=1 \
    -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
    -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
    -DWITH_READLINE=1 \
    -DWITH_SSL=system \
    -DWITH_ZLIB=system

make -j$(nproc)
make install

cd $BUILD_DIR
rm -rf mariadb-${MARIADB_VERSION}

Configurazione comune

Le sezioni seguenti si applicano a entrambe le distribuzioni. Adatta i percorsi e le variabili alla tua distribuzione ($LAMP_ROOT / $SITES_ROOT o $SITIWEB_ROOT, $USER_LAMP / $USER_NAME).

Nelle sezioni seguenti viene usata la nomenclatura Debian/Ubuntu ($SITES_ROOT, $USER_NAME). Per RHEL sostituisci con $SITIWEB_ROOT e $USER_LAMP.

Configurazione Apache

# Backup
cp ${LAMP_ROOT}/apache-${APACHE_VERSION}/conf/httpd.conf \
   ${LAMP_ROOT}/apache-${APACHE_VERSION}/conf/httpd.conf.backup

# Porta e ServerName
sed -i "s/Listen 80/Listen ${APACHE_PORT}/" \
    ${LAMP_ROOT}/apache-${APACHE_VERSION}/conf/httpd.conf
sed -i "s/#ServerName www.example.com:80/ServerName localhost:${APACHE_PORT}/" \
    ${LAMP_ROOT}/apache-${APACHE_VERSION}/conf/httpd.conf

# Utente
sed -i "s/User daemon/User ${USER_NAME}/" \
    ${LAMP_ROOT}/apache-${APACHE_VERSION}/conf/httpd.conf
sed -i "s/Group daemon/Group ${USER_NAME}/" \
    ${LAMP_ROOT}/apache-${APACHE_VERSION}/conf/httpd.conf

# Moduli
sed -i 's/#LoadModule rewrite_module/LoadModule rewrite_module/' \
    ${LAMP_ROOT}/apache-${APACHE_VERSION}/conf/httpd.conf
sed -i 's/#LoadModule deflate_module/LoadModule deflate_module/' \
    ${LAMP_ROOT}/apache-${APACHE_VERSION}/conf/httpd.conf
sed -i 's/#LoadModule expires_module/LoadModule expires_module/' \
    ${LAMP_ROOT}/apache-${APACHE_VERSION}/conf/httpd.conf
sed -i 's/#LoadModule headers_module/LoadModule headers_module/' \
    ${LAMP_ROOT}/apache-${APACHE_VERSION}/conf/httpd.conf

# Abilita virtual hosts
sed -i 's|#Include conf/extra/httpd-vhosts.conf|Include conf/extra/httpd-vhosts.conf|' \
    ${LAMP_ROOT}/apache-${APACHE_VERSION}/conf/httpd.conf

Configurazione PHP

# PHP-FPM
cp ${LAMP_ROOT}/php-${PHP_VERSION}/etc/php-fpm.conf.default \
   ${LAMP_ROOT}/php-${PHP_VERSION}/etc/php-fpm.conf
cp ${LAMP_ROOT}/php-${PHP_VERSION}/etc/php-fpm.d/www.conf.default \
   ${LAMP_ROOT}/php-${PHP_VERSION}/etc/php-fpm.d/www.conf

sed -i "s/user = .*/user = ${USER_NAME}/" \
    ${LAMP_ROOT}/php-${PHP_VERSION}/etc/php-fpm.d/www.conf
sed -i "s/group = .*/group = ${USER_NAME}/" \
    ${LAMP_ROOT}/php-${PHP_VERSION}/etc/php-fpm.d/www.conf
sed -i "s|listen = .*|listen = 127.0.0.1:9000|" \
    ${LAMP_ROOT}/php-${PHP_VERSION}/etc/php-fpm.d/www.conf

# Limiti php.ini
PHP_INI="${LAMP_ROOT}/php-${PHP_VERSION}/etc/php.ini"
sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 100M/'   $PHP_INI
sed -i 's/post_max_size = 8M/post_max_size = 100M/'               $PHP_INI
sed -i 's/max_execution_time = 30/max_execution_time = 300/'      $PHP_INI
sed -i 's/max_input_time = 60/max_input_time = 300/'              $PHP_INI
sed -i 's/memory_limit = 128M/memory_limit = 512M/'               $PHP_INI
sed -i 's/output_buffering = 4096/output_buffering = On/'         $PHP_INI

# Session save path
echo "session.save_path = \"${SESSION_ROOT}\"" >> $PHP_INI

Configurazione MariaDB

# Inizializzazione database
${LAMP_ROOT}/mariadb-${MARIADB_VERSION}/scripts/mariadb-install-db \
    --user=${USER_NAME} \
    --basedir=${LAMP_ROOT}/mariadb-${MARIADB_VERSION} \
    --datadir=${LAMP_ROOT}/mariadb-${MARIADB_VERSION}/data

# my.cnf
cat > ${LAMP_ROOT}/mariadb-${MARIADB_VERSION}/my.cnf << EOF
[mysqld]
basedir=${LAMP_ROOT}/mariadb-${MARIADB_VERSION}
datadir=${LAMP_ROOT}/mariadb-${MARIADB_VERSION}/data
socket=${LAMP_ROOT}/mariadb-${MARIADB_VERSION}/mysql.sock
port=${MARIADB_PORT}
user=${USER_NAME}
bind-address=127.0.0.1

[mysql]
socket=${LAMP_ROOT}/mariadb-${MARIADB_VERSION}/mysql.sock

[client]
socket=${LAMP_ROOT}/mariadb-${MARIADB_VERSION}/mysql.sock
port=${MARIADB_PORT}
EOF

Avvia MariaDB temporaneamente per impostare la password di root:

${LAMP_ROOT}/mariadb-${MARIADB_VERSION}/bin/mariadbd-safe \
    --defaults-file=${LAMP_ROOT}/mariadb-${MARIADB_VERSION}/my.cnf \
    --user=${USER_NAME} &

sleep 5

# Imposta password root (premi Invio se chiede la password attuale)
${LAMP_ROOT}/mariadb-${MARIADB_VERSION}/bin/mariadb -u root \
    --socket=${LAMP_ROOT}/mariadb-${MARIADB_VERSION}/mysql.sock \
    -e "ALTER USER 'root'@'localhost' IDENTIFIED BY 'root'; FLUSH PRIVILEGES;"

# Procedura guidata di sicurezza
${LAMP_ROOT}/mariadb-${MARIADB_VERSION}/bin/mariadb-secure-installation \
    --socket=${LAMP_ROOT}/mariadb-${MARIADB_VERSION}/mysql.sock

# Ferma MariaDB
${LAMP_ROOT}/mariadb-${MARIADB_VERSION}/bin/mariadb-admin \
    --socket=${LAMP_ROOT}/mariadb-${MARIADB_VERSION}/mysql.sock \
    -u root -p shutdown

Virtual Host e siti

# Directory siti
mkdir -p ${SITES_ROOT}/localhost
mkdir -p ${SITES_ROOT}/pma.local

# File di test
echo "<?php phpinfo(); ?>" > ${SITES_ROOT}/localhost/info.php
echo "<h1>Localhost</h1>" > ${SITES_ROOT}/localhost/index.html

# Backup e configurazione virtual hosts
cp ${LAMP_ROOT}/apache-${APACHE_VERSION}/conf/extra/httpd-vhosts.conf \
   ${LAMP_ROOT}/apache-${APACHE_VERSION}/conf/extra/httpd-vhosts.conf.backup

cat > ${LAMP_ROOT}/apache-${APACHE_VERSION}/conf/extra/httpd-vhosts.conf << EOF
<VirtualHost *:${APACHE_PORT}>
    ServerName localhost
    DocumentRoot "${SITES_ROOT}/localhost"
    DirectoryIndex index.php index.html
    <Directory "${SITES_ROOT}/localhost">
        AllowOverride All
        Require all granted
        <FilesMatch \.php$>
            SetHandler "proxy:fcgi://127.0.0.1:9000"
        </FilesMatch>
    </Directory>
    ErrorLog "logs/localhost_error.log"
    CustomLog "logs/localhost_access.log" common
</VirtualHost>

<VirtualHost *:${APACHE_PORT}>
    ServerName pma.local
    DocumentRoot "${SITES_ROOT}/pma.local"
    DirectoryIndex index.php
    <Directory "${SITES_ROOT}/pma.local">
        AllowOverride All
        Require all granted
        <FilesMatch \.php$>
            SetHandler "proxy:fcgi://127.0.0.1:9000"
        </FilesMatch>
    </Directory>
    ErrorLog "logs/pma_error.log"
    CustomLog "logs/pma_access.log" common
</VirtualHost>
EOF

# Aggiunta al file hosts
echo "127.0.0.1 pma.local" | sudo tee -a /etc/hosts

Per aggiungere un nuovo sito in seguito:

# Crea la directory
mkdir -p ${SITES_ROOT}/miosito.local

# Aggiungi il virtual host
cat >> ${LAMP_ROOT}/apache-${APACHE_VERSION}/conf/extra/httpd-vhosts.conf << EOF

<VirtualHost *:${APACHE_PORT}>
    ServerName miosito.local
    DocumentRoot "${SITES_ROOT}/miosito.local"
    DirectoryIndex index.php index.html
    <Directory "${SITES_ROOT}/miosito.local">
        AllowOverride All
        Require all granted
        <FilesMatch \.php$>
            SetHandler "proxy:fcgi://127.0.0.1:9000"
        </FilesMatch>
    </Directory>
    ErrorLog "logs/miosito_error.log"
    CustomLog "logs/miosito_access.log" common
</VirtualHost>
EOF

# Aggiunta al file hosts
echo "127.0.0.1 miosito.local" | sudo tee -a /etc/hosts

phpMyAdmin

cd ${SITES_ROOT}/pma.local

wget https://www.phpmyadmin.net/downloads/phpMyAdmin-latest-all-languages.tar.gz
tar -xzf phpMyAdmin-latest-all-languages.tar.gz --strip-components=1
rm phpMyAdmin-latest-all-languages.tar.gz

cp config.sample.inc.php config.inc.php

# Configura host e porta
sed -i "s/\['host'\] = 'localhost'/['host'] = '127.0.0.1'/" config.inc.php
sed -i "s/\['port'\] = ''/['port'] = '${MARIADB_PORT}'/" config.inc.php

# Genera e imposta blowfish_secret
BFSECRET=$(openssl rand -base64 32)
sed -i "s|\(\$cfg\['blowfish_secret'\] = '\)|\1${BFSECRET}|" config.inc.php

# Directory temporanea
mkdir -p tmp && chmod 777 tmp

Per il login automatico (opzionale), aggiungi nel config.inc.php:

$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = 'root';
$cfg['Servers'][$i]['AllowNoPassword'] = false;

Script di avvio e stop

cat > ${LAMP_ROOT}/start_lamp.sh << 'EOF'
#!/bin/bash
LAMP_ROOT="/mnt/local1tb/Debian13/lamp"
APACHE_VERSION="2.4.65"
PHP_VERSION="8.4.12"
MARIADB_VERSION="12.1.1"
APACHE_PORT="8080"
MARIADB_PORT="3307"
USER_NAME=$(whoami)

export PATH=${LAMP_ROOT}/apache-${APACHE_VERSION}/bin:${LAMP_ROOT}/php-${PHP_VERSION}/bin:${LAMP_ROOT}/php-${PHP_VERSION}/sbin:${LAMP_ROOT}/mariadb-${MARIADB_VERSION}/bin:$PATH

echo "Avvio MariaDB..."
${LAMP_ROOT}/mariadb-${MARIADB_VERSION}/bin/mariadbd-safe \
    --defaults-file=${LAMP_ROOT}/mariadb-${MARIADB_VERSION}/my.cnf \
    --user=${USER_NAME} &
sleep 5

echo "Avvio PHP-FPM..."
${LAMP_ROOT}/php-${PHP_VERSION}/sbin/php-fpm \
    --fpm-config ${LAMP_ROOT}/php-${PHP_VERSION}/etc/php-fpm.conf &
sleep 2

echo "Avvio Apache..."
${LAMP_ROOT}/apache-${APACHE_VERSION}/bin/httpd -D FOREGROUND &

echo "LAMP avviato:"
echo "  http://localhost:${APACHE_PORT}"
echo "  http://pma.local:${APACHE_PORT}"
echo "  MariaDB porta: ${MARIADB_PORT}"
wait
EOF

cat > ${LAMP_ROOT}/stop_lamp.sh << 'EOF'
#!/bin/bash
LAMP_ROOT="/mnt/local1tb/Debian13/lamp"
MARIADB_VERSION="12.1.1"

echo "Arresto Apache..."
pkill -f "httpd -D FOREGROUND"

echo "Arresto PHP-FPM..."
pkill -f "php-fpm"

echo "Arresto MariaDB..."
${LAMP_ROOT}/mariadb-${MARIADB_VERSION}/bin/mariadb-admin \
    --socket=${LAMP_ROOT}/mariadb-${MARIADB_VERSION}/mysql.sock \
    -u root -p shutdown

echo "LAMP arrestato."
EOF

chmod +x ${LAMP_ROOT}/start_lamp.sh
chmod +x ${LAMP_ROOT}/stop_lamp.sh

Avvio e stop:

${LAMP_ROOT}/start_lamp.sh
${LAMP_ROOT}/stop_lamp.sh

WordPress

Nel file wp-config.php imposta l’host del database nel formato 127.0.0.1:PORTA:

define( 'DB_HOST', '127.0.0.1:3307' );

Aggiungi anche queste costanti utili per lo sviluppo locale:

define('FS_METHOD', 'direct');
define('AUTOMATIC_UPDATER_DISABLED', true);
define('WP_POST_REVISIONS', 5);
define('ALLOW_UNFILTERED_UPLOADS', true);

Per la gestione delle immagini, se ImageMagick non è disponibile, forza l’uso di GD:

define('WP_IMAGE_EDITOR_GD', true);

ImageMagick (opzionale)

Se hai bisogno dell’estensione imagick per PHP (ad esempio per WordPress), compilala da sorgente:

# Dipendenze (Debian/Ubuntu)
sudo apt install -y libmagickwand-dev libmagickcore-dev

# RHEL
# sudo dnf install ImageMagick-devel

cd $BUILD_DIR
git clone https://github.com/Imagick/imagick.git
cd imagick

export PATH="${LAMP_ROOT}/php-${PHP_VERSION}/bin:$PATH"
${LAMP_ROOT}/php-${PHP_VERSION}/bin/phpize
./configure --with-php-config=${LAMP_ROOT}/php-${PHP_VERSION}/bin/php-config
make -j$(nproc)
make install

echo "extension=imagick.so" >> ${LAMP_ROOT}/php-${PHP_VERSION}/etc/php.ini

# Riavvia il LAMP con lo script stop/start
cd $BUILD_DIR && rm -rf imagick

Note sulla portabilità

Per spostare l’ambiente su un’altra macchina della stessa famiglia di distribuzioni:

  1. Copia la directory $LAMP_ROOT sulla nuova macchina
  2. Copia la directory dei siti web
  3. Installa le stesse dipendenze runtime
  4. Aggiorna i percorsi negli script se le directory di destinazione differiscono
  5. Lancia start_lamp.sh