{"id":8893,"date":"2025-09-13T19:58:04","date_gmt":"2025-09-13T14:28:04","guid":{"rendered":"https:\/\/www.veeble.com\/kb\/?p=8893"},"modified":"2025-09-16T10:06:20","modified_gmt":"2025-09-16T04:36:20","slug":"how-to-compile-lamp-stack-from-source-on-ubuntu","status":"publish","type":"post","link":"https:\/\/www.veeble.com\/kb\/how-to-compile-lamp-stack-from-source-on-ubuntu\/","title":{"rendered":"How to Compile LAMP Stack from Source on Ubuntu: A Complete Guide"},"content":{"rendered":"\n<p>If you\u2019ve ever worked with web servers, you\u2019ve probably heard of the <strong><a href=\"https:\/\/www.ibm.com\/think\/topics\/lamp-stack\" target=\"_blank\" rel=\"noreferrer noopener\">LAMP stack<\/a><\/strong> \u2014 Linux, Apache, MySQL\/MariaDB, and PHP. It\u2019s one of the most popular setups for hosting dynamic websites and applications.<br><br>Most people install LAMP using ready-made packages from Ubuntu\u2019s repositories. That\u2019s quick and convenient, but it also means you\u2019re limited to whatever options and versions the package maintainers provide.<br><br>In this guide, we\u2019ll take things a step further and show you <strong>how to compile the LAMP stack from source<\/strong> on Ubuntu. Why would you do that? Because building from source gives you:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>More control<\/strong> over which modules and features get included.<\/li>\n\n\n\n<li><strong>Performance improvements<\/strong> tailored to your server\u2019s hardware.<\/li>\n\n\n\n<li><strong>Early access<\/strong> to the latest versions and features before they hit package managers.<\/li>\n<\/ul>\n\n\n\n<p>Don\u2019t worry if this sounds a bit advanced \u2014 we\u2019ll walk through each step clearly so you can follow along. By the end, you\u2019ll have a fully working LAMP stack that\u2019s customized for your needs.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2025\/09\/How-to-Compile-LAMP-Stack-from-Source-on-Ubuntu-Step-by-Step-Guide-1.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"683\" src=\"https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2025\/09\/How-to-Compile-LAMP-Stack-from-Source-on-Ubuntu-Step-by-Step-Guide-1-1024x683.jpg\" alt=\"\" class=\"wp-image-8924\" srcset=\"https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2025\/09\/How-to-Compile-LAMP-Stack-from-Source-on-Ubuntu-Step-by-Step-Guide-1-1024x683.jpg 1024w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2025\/09\/How-to-Compile-LAMP-Stack-from-Source-on-Ubuntu-Step-by-Step-Guide-1-300x200.jpg 300w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2025\/09\/How-to-Compile-LAMP-Stack-from-Source-on-Ubuntu-Step-by-Step-Guide-1-768x512.jpg 768w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2025\/09\/How-to-Compile-LAMP-Stack-from-Source-on-Ubuntu-Step-by-Step-Guide-1.jpg 1536w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\t\t\t\t<div class=\"wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-4ee6b342      \"\n\t\t\t\t\tdata-scroll= \"1\"\n\t\t\t\t\tdata-offset= \"30\"\n\t\t\t\t\tstyle=\"\"\n\t\t\t\t>\n\t\t\t\t<div class=\"uagb-toc__wrap\">\n\t\t\t\t\t\t<div class=\"uagb-toc__title\">\n\t\t\t\t\t\t\tTable Of Contents\t\t\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<div class=\"uagb-toc__list-wrap \">\n\t\t\t\t\t\t<ol class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#why-compile-from-source\" class=\"uagb-toc-link__trigger\">Why Compile from Source?<\/a><ul class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#building-from-source-allows-you-to\" class=\"uagb-toc-link__trigger\">Building from source allows you to:<\/a><\/li><\/ul><\/li><li class=\"uagb-toc__list\"><a href=\"#prerequisites-and-system-preparation\" class=\"uagb-toc-link__trigger\">Prerequisites and System Preparation<\/a><ul class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#system-requirements\" class=\"uagb-toc-link__trigger\">System Requirements:<\/a><li class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#install-build-dependencies\" class=\"uagb-toc-link__trigger\">Install Build Dependencies<\/a><\/li><\/ul><\/li><\/ul><\/li><li class=\"uagb-toc__list\"><a href=\"#step-1-compile-apache-from-source\" class=\"uagb-toc-link__trigger\">Step 1: Compile Apache from Source<\/a><ul class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#download-and-extract-apache\" class=\"uagb-toc-link__trigger\">Download and Extract Apache<\/a><li class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#download-and-install-apr-dependencies\" class=\"uagb-toc-link__trigger\">Download and Install APR Dependencies<\/a><li class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#configure-apache-build\" class=\"uagb-toc-link__trigger\">Configure Apache Build<\/a><ul class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#key-configuration-options-explained\" class=\"uagb-toc-link__trigger\">Key Configuration Options Explained:<\/a><\/li><\/ul><li class=\"uagb-toc__list\"><a href=\"#compile-and-install-apache\" class=\"uagb-toc-link__trigger\">Compile and Install Apache<\/a><\/li><\/ul><\/li><\/ul><\/li><\/ul><\/li><li class=\"uagb-toc__list\"><a href=\"#step-2-compile-mariadb-from-source\" class=\"uagb-toc-link__trigger\">Step 2: Compile MariaDB from Source<\/a><ul class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#download-mariadb-source\" class=\"uagb-toc-link__trigger\">Download MariaDB Source<\/a><li class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#install-mariadb-build-dependencies\" class=\"uagb-toc-link__trigger\">Install MariaDB Build Dependencies<\/a><li class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#configure-mariadb-build\" class=\"uagb-toc-link__trigger\">Configure MariaDB Build<\/a><li class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#compile-and-install-mariadb\" class=\"uagb-toc-link__trigger\">Compile and Install MariaDB<\/a><\/li><\/ul><\/li><\/ul><\/li><\/ul><\/li><\/ul><\/li><li class=\"uagb-toc__list\"><a href=\"#step-3-compile-php-from-source\" class=\"uagb-toc-link__trigger\">Step 3: Compile PHP from Source<\/a><ul class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#download-php-source\" class=\"uagb-toc-link__trigger\">Download PHP Source<\/a><li class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#build-configuration-script\" class=\"uagb-toc-link__trigger\">Build Configuration Script<\/a><li class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#configure-php-build\" class=\"uagb-toc-link__trigger\">Configure PHP Build<\/a><ul class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#key-php-configuration-options\" class=\"uagb-toc-link__trigger\">Key PHP Configuration Options:<\/a><\/li><\/ul><li class=\"uagb-toc__list\"><a href=\"#compile-and-install-php\" class=\"uagb-toc-link__trigger\">Compile and Install PHP<\/a><\/li><\/ul><\/li><\/ul><\/li><\/ul><\/li><\/ul><\/li><\/ul><\/li><li class=\"uagb-toc__list\"><a href=\"#step-4-integration-and-configuration\" class=\"uagb-toc-link__trigger\">Step 4: Integration and Configuration<\/a><ul class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#configure-apache-to-work-with-php\" class=\"uagb-toc-link__trigger\">Configure Apache to Work with PHP<\/a><li class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#create-basic-virtual-host\" class=\"uagb-toc-link__trigger\">Create Basic Virtual Host<\/a><li class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#start-services\" class=\"uagb-toc-link__trigger\">Start Services<\/a><li class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#test-installation\" class=\"uagb-toc-link__trigger\">Test Installation<\/a><\/li><\/ul><\/li><\/ul><\/li><\/ul><\/li><\/ul><\/li><\/ul><\/li><\/ul><\/li><li class=\"uagb-toc__list\"><a href=\"#conclusion\" class=\"uagb-toc-link__trigger\">Conclusion<\/a><\/ul><\/ul><\/ul><\/ul><\/ul><\/ul><\/ol>\t\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\n\n\n<div style=\"height:33px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"why-compile-from-source\">Why Compile from Source?<\/h2>\n\n<h5 class=\"wp-block-heading\" id=\"building-from-source-allows-you-to\">Building from source allows you to:<\/h5>\n\n\n<ul class=\"wp-block-list\">\n<li>Enable specific compile-time options and optimizations<\/li>\n\n\n\n<li>Get the latest features before they&#8217;re packaged<\/li>\n\n\n\n<li>Create lightweight builds with only needed modules<\/li>\n\n\n\n<li>Optimize for your specific hardware architecture<\/li>\n\n\n\n<li>Apply custom patches and modifications<\/li>\n\n\n\n<li>Understand the software&#8217;s internals better<\/li>\n<\/ul>\n\n\n<h2 class=\"wp-block-heading\" id=\"prerequisites-and-system-preparation\">Prerequisites and System Preparation<\/h2>\n\n<h5 class=\"wp-block-heading\" id=\"system-requirements\">System Requirements:<\/h5>\n\n\n<ul class=\"wp-block-list\">\n<li>Ubuntu 20.04+ with at least 2GB RAM and 5GB free disk space<\/li>\n\n\n\n<li>Root or sudo access<\/li>\n\n\n\n<li>Stable internet connection for downloading sources (approximately 1GB total)<\/li>\n\n\n\n<li>Basic familiarity with command-line operations<\/li>\n<\/ul>\n\n\n<h5 class=\"wp-block-heading\" id=\"install-build-dependencies\">Install Build Dependencies<\/h5>\n\n\n<p>First, update your system and install essential build tools:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt update &amp;&amp; sudo apt upgrade -y\nsudo apt install build-essential autoconf libtool bison re2c pkg-config \\\n    cmake git wget curl libssl-dev libxml2-dev libcurl4-openssl-dev \\\n    libpng-dev libjpeg-dev libonig-dev libzip-dev libreadline-dev \\\n    libgmp-dev libldap2-dev libsqlite3-dev zlib1g-dev libpcre3-dev \\\n    libffi-dev libsodium-dev libwebp-dev libexpat1-dev libnghttp2-dev \\\n    libsystemd-dev <\/code><\/pre>\n\n\n\n<p>Create a dedicated build directory:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo mkdir -p \/usr\/src\/lamp\ncd \/usr\/src\/lamp\nsudo chown $(whoami):$(whoami) \/usr\/src\/lamp<\/code><\/pre>\n\n\n<h2 class=\"wp-block-heading\" id=\"step-1-compile-apache-from-source\">Step 1: Compile Apache from Source<\/h2>\n\n<h5 class=\"wp-block-heading\" id=\"download-and-extract-apache\">Download and Extract Apache<\/h5>\n\n\n<pre class=\"wp-block-code\"><code># Download Apache HTTP Server\nsudo wget https:\/\/downloads.apache.org\/httpd\/httpd-2.4.65.tar.gz\nsudo wget https:\/\/downloads.apache.org\/httpd\/httpd-2.4.65.tar.gz.asc\n\n# Verify integrity (optional but recommended)\ngpg --verify httpd-2.4.65.tar.gz.asc httpd-2.4.65.tar.gz\n\n# Extract\ntar -xzf httpd-2.4.65.tar.gz\ncd httpd-2.4.65<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2025\/09\/Screenshot-2025-09-13-193332.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"491\" src=\"https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2025\/09\/Screenshot-2025-09-13-193332-1024x491.png\" alt=\"\" class=\"wp-image-8929\" srcset=\"https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2025\/09\/Screenshot-2025-09-13-193332-1024x491.png 1024w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2025\/09\/Screenshot-2025-09-13-193332-300x144.png 300w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2025\/09\/Screenshot-2025-09-13-193332-768x368.png 768w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2025\/09\/Screenshot-2025-09-13-193332-1536x736.png 1536w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2025\/09\/Screenshot-2025-09-13-193332.png 1866w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p>You can always download the latest stable version of Apache HTTP Server from the <a href=\"https:\/\/httpd.apache.org\/download.cgi\" target=\"_blank\" rel=\"noreferrer noopener\">official download page<\/a>.<\/p>\n\n\n<h5 class=\"wp-block-heading\" id=\"download-and-install-apr-dependencies\">Download and Install APR Dependencies<\/h5>\n\n\n<p>Apache requires APR (Apache Portable Runtime) libraries:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Download APR and APR-Util\nsudo wget https:\/\/downloads.apache.org\/apr\/apr-1.7.6.tar.gz\nsudo wget https:\/\/downloads.apache.org\/apr\/apr-util-1.6.3.tar.gz\n\n# Extract to srclib directory\ntar -xzf apr-1.7.6.tar.gz\ntar -xzf apr-util-1.6.3.tar.gz\nmv apr-1.7.6 srclib\/apr\nmv apr-util-1.6.3 srclib\/apr-util<\/code><\/pre>\n\n\n<h5 class=\"wp-block-heading\" id=\"configure-apache-build\">Configure Apache Build<\/h5>\n\n\n<pre class=\"wp-block-code\"><code>.\/configure \\\n    --prefix=\/opt\/apache2 \\\n    --with-included-apr \\\n    --enable-ssl \\\n    --enable-rewrite \\\n    --enable-deflate \\\n    --enable-headers \\\n    --enable-expires \\\n    --enable-mpms-shared=all \\\n    --enable-mods-shared=most \\\n    --with-pcre \\\n    --enable-http2 \\\n    --enable-proxy \\\n    --enable-proxy-http<\/code><\/pre>\n\n\n<h6 class=\"wp-block-heading\" id=\"key-configuration-options-explained\"><strong>Key Configuration Options Explained:<\/strong><\/h6>\n\n\n<ul class=\"wp-block-list\">\n<li><code>--prefix<\/code>: Installation directory<\/li>\n\n\n\n<li><code>--with-included-apr<\/code>: Use bundled APR libraries<\/li>\n\n\n\n<li><code>--enable-ssl<\/code>: SSL\/TLS support<\/li>\n\n\n\n<li><code>--enable-mpms-shared=all<\/code>: All Multi-Processing Modules as shared<\/li>\n\n\n\n<li><code>--enable-mods-shared=most<\/code>: Most modules as shared libraries<\/li>\n<\/ul>\n\n\n<h5 class=\"wp-block-heading\" id=\"compile-and-install-apache\">Compile and Install Apache<\/h5>\n\n\n<pre class=\"wp-block-code\"><code># Compile (this takes 5-15 minutes)\nmake -j$(nproc)\n\n# Run tests (optional)\nmake test\n\n# Install\nsudo make install\n\n# Set ownership\nsudo chown -R $(whoami):$(whoami) \/opt\/apache2\n\n# Create systemd service\nsudo tee \/etc\/systemd\/system\/apache2-custom.service &lt;&lt; 'EOF'\n&#091;Unit]\nDescription=Apache HTTP Server (Custom Build)\nAfter=network.target\n\n&#091;Service]\nType=forking\nExecStart=\/opt\/apache2\/bin\/httpd -D FOREGROUND\nExecReload=\/bin\/kill -HUP $MAINPID\nKillMode=process\nRestart=on-failure\nRestartSec=42s\n\n&#091;Install]\nWantedBy=multi-user.target\nEOF\n\nsudo systemctl daemon-reload\nsudo systemctl enable apache2-custom<\/code><\/pre>\n\n\n\n<p>\u26a0\ufe0f <strong>Note:<\/strong> Compiling Apache can take 10\u201315 minutes depending on your CPU. Be patient.<\/p>\n\n\n<h2 class=\"wp-block-heading\" id=\"step-2-compile-mariadb-from-source\">Step 2: Compile MariaDB from Source<\/h2>\n\n<h5 class=\"wp-block-heading\" id=\"download-mariadb-source\">Download MariaDB Source<\/h5>\n\n\n<pre class=\"wp-block-code\"><code>cd \/usr\/src\/lamp\nwget https:\/\/archive.mariadb.org\/mariadb-11.2.2\/source\/mariadb-11.2.2.tar.gz\ntar -xzf mariadb-11.2.2.tar.gz\ncd mariadb-11.2.2<\/code><\/pre>\n\n\n<h5 class=\"wp-block-heading\" id=\"install-mariadb-build-dependencies\">Install MariaDB Build Dependencies<\/h5>\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install build-essential cmake pkg-config bison \\\n    libncurses5-dev libssl-dev zlib1g-dev \\\n    libboost-all-dev liblz4-dev libsnappy-dev \\\n    libpcre2-dev libsystemd-dev \\\n    libgnutls28-dev libevent-dev \\\n    libboost-dev libxml2-dev libjemalloc-dev \\\n    libmsgpack-dev libbz2-dev liblzma-dev<\/code><\/pre>\n\n\n<h5 class=\"wp-block-heading\" id=\"configure-mariadb-build\">Configure MariaDB Build<\/h5>\n\n\n<pre class=\"wp-block-code\"><code># Create build directory\nmkdir build &amp;&amp; cd build\n\n# Configure with CMake\ncmake .. \\\n  -DCMAKE_INSTALL_PREFIX=\/opt\/mariadb \\\n  -DCMAKE_BUILD_TYPE=Release \\\n  -DMYSQL_DATADIR=\/opt\/mariadb\/data \\\n  -DSYSCONFDIR=\/opt\/mariadb\/etc \\\n  -DMYSQL_UNIX_ADDR=\/opt\/mariadb\/tmp\/mysql.sock \\\n  -DDEFAULT_CHARSET=utf8mb4 \\\n  -DDEFAULT_COLLATION=utf8mb4_general_ci \\\n  -DWITH_INNODB_LZ4=ON \\\n  -DWITH_INNODB_SNAPPY=ON \\\n  -DPLUGIN_ROCKSDB=NO \\\n  -DPLUGIN_TOKUDB=NO \\\n  -DWITH_SYSTEMD=yes<\/code><\/pre>\n\n\n<h5 class=\"wp-block-heading\" id=\"compile-and-install-mariadb\">Compile and Install MariaDB<\/h5>\n\n\n<pre class=\"wp-block-code\"><code># Compile (this can take 20-60 minutes)\nmake -j$(nproc)\n\n# Install\nsudo make install\n\n# Create mysql user and group\nsudo groupadd mysql\nsudo useradd -r -g mysql -s \/bin\/false mysql\n\n# Set proper ownership\nsudo chown -R mysql:mysql \/opt\/mariadb\nsudo chmod 755 \/opt\/mariadb\n\n# Initialize database\nsudo \/opt\/mariadb\/scripts\/mysql_install_db \\\n    --user=mysql \\\n    --basedir=\/opt\/mariadb \\\n    --datadir=\/opt\/mariadb\/data\n\n# Create systemd service\nsudo tee \/etc\/systemd\/system\/mariadb-custom.service &lt;&lt; 'EOF'\n&#091;Unit]\nDescription=MariaDB database server (Custom Build)\nAfter=network.target\n\n&#091;Service]\nType=notify\nUser=mysql\nGroup=mysql\nExecStart=\/opt\/mariadb\/bin\/mysqld --defaults-file=\/opt\/mariadb\/etc\/my.cnf\nTimeoutSec=300\nPrivateNetwork=false\n\n&#091;Install]\nWantedBy=multi-user.target\nEOF\n\nsudo systemctl daemon-reload\nsudo systemctl enable mariadb-custom<\/code><\/pre>\n\n\n\n<p>\ud83d\udca1 <strong>Tip:<\/strong> Always run <code>mysql_secure_installation<\/code> to remove test users and improve security.<\/p>\n\n\n<h2 class=\"wp-block-heading\" id=\"step-3-compile-php-from-source\">Step 3: Compile PHP from Source<\/h2>\n\n<h5 class=\"wp-block-heading\" id=\"download-php-source\">Download PHP Source<\/h5>\n\n\n<pre class=\"wp-block-code\"><code>cd \/usr\/src\/lamp\ngit clone https:\/\/github.com\/php\/php-src.git --branch=PHP-8.3\ncd php-src<\/code><\/pre>\n\n\n<h5 class=\"wp-block-heading\" id=\"build-configuration-script\">Build Configuration Script<\/h5>\n\n\n<pre class=\"wp-block-code\"><code>.\/buildconf --force<\/code><\/pre>\n\n\n<h5 class=\"wp-block-heading\" id=\"configure-php-build\">Configure PHP Build<\/h5>\n\n\n<pre class=\"wp-block-code\"><code>.\/configure \\\n    --prefix=\/opt\/php8 \\\n    --with-config-file-path=\/opt\/php8\/etc \\\n    --enable-fpm \\\n    --with-fpm-user=www-data \\\n    --with-fpm-group=www-data \\\n    --disable-short-tags \\\n    --with-openssl \\\n    --with-pcre-regex \\\n    --with-zlib \\\n    --enable-bcmath \\\n    --with-curl \\\n    --enable-filter \\\n    --enable-ftp \\\n    --with-gd \\\n    --with-jpeg \\\n    --with-webp \\\n    --enable-intl \\\n    --enable-mbstring \\\n    --with-mysqli=mysqlnd \\\n    --with-pdo-mysql=mysqlnd \\\n    --with-readline \\\n    --enable-sockets \\\n    --with-sodium \\\n    --enable-soap \\\n    --with-zip \\\n    --enable-opcache \\\n    --with-apache=\/opt\/apache2<\/code><\/pre>\n\n\n<h6 class=\"wp-block-heading\" id=\"key-php-configuration-options\"><strong>Key PHP Configuration Options:<\/strong><\/h6>\n\n\n<ul class=\"wp-block-list\">\n<li><code>--enable-fpm<\/code>: PHP FastCGI Process Manager<\/li>\n\n\n\n<li><code>--with-mysqli<\/code>: MySQL improved extension<\/li>\n\n\n\n<li><code>--with-pdo-mysql<\/code>: PDO MySQL support<\/li>\n\n\n\n<li><code>--enable-opcache<\/code>: Built-in opcode cache<\/li>\n\n\n\n<li><code>--with-apache<\/code>: Apache SAPI module<\/li>\n<\/ul>\n\n\n<h5 class=\"wp-block-heading\" id=\"compile-and-install-php\">Compile and Install PHP<\/h5>\n\n\n<pre class=\"wp-block-code\"><code># Compile (takes 5-20 minutes)\nmake -j$(nproc)\n\n# Run tests (optional, takes time)\n# make test\n\n# Install\nsudo make install\n\n# Copy configuration files\nsudo cp php.ini-production \/opt\/php8\/etc\/php.ini\nsudo cp sapi\/fpm\/php-fpm.conf \/opt\/php8\/etc\/\nsudo cp sapi\/fpm\/www.conf \/opt\/php8\/etc\/php-fpm.d\/\n\n# Create PHP-FPM systemd service\nsudo tee \/etc\/systemd\/system\/php8-fpm.service &lt;&lt; 'EOF'\n&#091;Unit]\nDescription=The PHP 8 FastCGI Process Manager\nAfter=network.target\n\n&#091;Service]\nType=notify\nPIDFile=\/opt\/php8\/var\/run\/php-fpm.pid\nExecStart=\/opt\/php8\/sbin\/php-fpm --nodaemonize --fpm-config \/opt\/php8\/etc\/php-fpm.conf\nExecReload=\/bin\/kill -USR2 $MAINPID\n\n&#091;Install]\nWantedBy=multi-user.target\nEOF\n\nsudo systemctl daemon-reload\nsudo systemctl enable php8-fpm<\/code><\/pre>\n\n\n<h2 class=\"wp-block-heading\" id=\"step-4-integration-and-configuration\">Step 4: Integration and Configuration<\/h2>\n\n<h5 class=\"wp-block-heading\" id=\"configure-apache-to-work-with-php\">Configure Apache to Work with PHP<\/h5>\n\n\n<p>Edit Apache configuration:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo nano \/opt\/apache2\/conf\/httpd.conf<\/code><\/pre>\n\n\n\n<p>Add these lines:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Load PHP module\nLoadModule php_module modules\/libphp.so\n\n# Configure PHP\n&lt;FilesMatch \\.php$&gt;\n    SetHandler application\/x-httpd-php\n&lt;\/FilesMatch&gt;\n\nDirectoryIndex index.html index.php\n\n# PHP configuration\n&lt;IfModule mod_php.c&gt;\n    AddType application\/x-httpd-php .php\n&lt;\/IfModule&gt;<\/code><\/pre>\n\n\n<h5 class=\"wp-block-heading\" id=\"create-basic-virtual-host\">Create Basic Virtual Host<\/h5>\n\n\n<pre class=\"wp-block-code\"><code>sudo mkdir -p \/opt\/apache2\/htdocs\/example.com\nsudo tee \/opt\/apache2\/conf\/extra\/example.com.conf &lt;&lt; 'EOF'\n&lt;VirtualHost *:80&gt;\n    ServerName example.com\n    DocumentRoot \/opt\/apache2\/htdocs\/example.com\n    ErrorLog logs\/example.com_error.log\n    CustomLog logs\/example.com_access.log combined\n    \n    &lt;Directory \"\/opt\/apache2\/htdocs\/example.com\"&gt;\n        AllowOverride All\n        Require all granted\n    &lt;\/Directory&gt;\n&lt;\/VirtualHost&gt;\nEOF<\/code><\/pre>\n\n\n<h5 class=\"wp-block-heading\" id=\"start-services\">Start Services<\/h5>\n\n\n<pre class=\"wp-block-code\"><code># Start MariaDB\nsudo systemctl start mariadb-custom\n\n# Secure MariaDB installation\nsudo \/opt\/mariadb\/bin\/mysql_secure_installation\n\n# Start PHP-FPM\nsudo systemctl start php8-fpm\n\n# Start Apache\nsudo systemctl start apache2-custom<\/code><\/pre>\n\n\n<h5 class=\"wp-block-heading\" id=\"test-installation\">Test Installation<\/h5>\n\n\n<p>Create a test PHP file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo tee \/opt\/apache2\/htdocs\/index.php &lt;&lt; 'EOF'\n&lt;?php\nphpinfo();\n\/\/ Test database connection\ntry {\n    $pdo = new PDO('mysql:host=localhost', 'root', 'your_password');\n    echo \"&lt;h2&gt;Database connection: SUCCESS&lt;\/h2&gt;\";\n} catch (PDOException $e) {\n    echo \"&lt;h2&gt;Database connection: FAILED&lt;\/h2&gt;\";\n}\n?&gt;\nEOF<\/code><\/pre>\n\n\n\n<p>Visit&nbsp;<code>http:\/\/localhost<\/code>&nbsp;to verify everything works.<\/p>\n\n\n<h2 class=\"wp-block-heading\" id=\"conclusion\">Conclusion<\/h2>\n\n\n<p>Compiling the LAMP stack from source may take more time than running a few apt install commands, but the payoff is huge. You\u2019ll gain:<\/p>\n\n\n\n<p>\u2705 A faster, leaner web server environment<br>\u2705 The freedom to enable only what you need<br>\u2705 A deeper understanding of how your stack actually works<\/p>\n\n\n\n<p>That said, managing a custom-compiled LAMP setup also means <strong>staying on top of updates, security patches, and maintenance<\/strong>. If you want the performance and flexibility of a source-built stack without the hassle of managing it all yourself, that\u2019s exactly what we do at <strong><a href=\"https:\/\/www.veeble.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">Veeble Hosting<\/a><\/strong>.<\/p>\n\n\n\n<p>Our managed hosting services come with <strong>pre-optimized LAMP environments, security hardening, performance monitoring, and 24\/7 expert support<\/strong> \u2014 so you can focus on building your applications instead of fighting with server configurations.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you\u2019ve ever worked with web servers, you\u2019ve probably heard of the LAMP stack \u2014 Linux, Apache, MySQL\/MariaDB, and PHP. It\u2019s one of the [&hellip;]<\/p>\n","protected":false},"author":15,"featured_media":8923,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[5,3,11,10],"tags":[40,42,38,39,43,41],"class_list":["post-8893","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux","category-installation","category-mysql","category-php","tag-apache-from-source","tag-custom-lamp-installation","tag-how-to-compile-lamp-stack-from-source","tag-lamp-stack-from-source","tag-manual-lamp-installation","tag-mariadb-from-source"],"uagb_featured_image_src":{"full":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2025\/09\/How-to-Compile-LAMP-Stack-from-Source-on-Ubuntu-Step-by-Step-Guide.jpg",1536,1024,false],"thumbnail":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2025\/09\/How-to-Compile-LAMP-Stack-from-Source-on-Ubuntu-Step-by-Step-Guide-150x150.jpg",150,150,true],"medium":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2025\/09\/How-to-Compile-LAMP-Stack-from-Source-on-Ubuntu-Step-by-Step-Guide-300x200.jpg",300,200,true],"medium_large":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2025\/09\/How-to-Compile-LAMP-Stack-from-Source-on-Ubuntu-Step-by-Step-Guide-768x512.jpg",768,512,true],"large":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2025\/09\/How-to-Compile-LAMP-Stack-from-Source-on-Ubuntu-Step-by-Step-Guide-1024x683.jpg",1024,683,true],"1536x1536":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2025\/09\/How-to-Compile-LAMP-Stack-from-Source-on-Ubuntu-Step-by-Step-Guide.jpg",1536,1024,false],"2048x2048":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2025\/09\/How-to-Compile-LAMP-Stack-from-Source-on-Ubuntu-Step-by-Step-Guide.jpg",1536,1024,false]},"uagb_author_info":{"display_name":"Nasarul Naseer","author_link":"https:\/\/www.veeble.com\/kb\/author\/nasarulnaseer\/"},"uagb_comment_info":0,"uagb_excerpt":"If you\u2019ve ever worked with web servers, you\u2019ve probably heard of the LAMP stack \u2014 Linux, Apache, MySQL\/MariaDB, and PHP. It\u2019s one of the [&hellip;]","_links":{"self":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts\/8893","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/users\/15"}],"replies":[{"embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/comments?post=8893"}],"version-history":[{"count":30,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts\/8893\/revisions"}],"predecessor-version":[{"id":8936,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts\/8893\/revisions\/8936"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/media\/8923"}],"wp:attachment":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/media?parent=8893"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/categories?post=8893"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/tags?post=8893"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}