{"id":13207,"date":"2025-08-31T16:44:54","date_gmt":"2025-08-31T10:59:54","guid":{"rendered":"https:\/\/nestnepal.com\/blog\/?p=13207"},"modified":"2025-09-03T16:35:02","modified_gmt":"2025-09-03T10:50:02","slug":"lamp-stack-configuration-setup-for-vps-2025","status":"publish","type":"post","link":"https:\/\/nestnepal.com\/blog\/lamp-stack-configuration-setup-for-vps-2025\/","title":{"rendered":"Setting Up a LAMP Stack on VPS (Linux, Apache, MySQL, PHP) in 2025"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Introduction<\/h2>\n\n\n\n<p>Remember when setting up a web server felt like trying to assemble a motorcycle while blindfolded? Those days don&#8217;t have to be behind us, but they can be it if you know what you&#8217;re doing. Setting up a LAMP stack (Linux, Apache, MySQL, PHP) is still one of the most fundamental skills every web developer and business owner should master, especially if you&#8217;re running your own VPS.<\/p>\n\n\n\n<p>At Nest Nepal, we&#8217;ve helped hundreds of businesses migrate from shared hosting to VPS, and the first thing they need is a solid LAMP stack setup. Whether you&#8217;re hosting a simple business website, running an e-commerce store, or managing multiple client sites, getting your LAMP stack right is crucial for performance, security, and peace of mind.<\/p>\n\n\n\n<p>Today, we&#8217;re going to walk through setting up a modern, secure, and optimized LAMP stack on a VPS in 2025. This isn&#8217;t your grandfather&#8217;s web server setup; we&#8217;re talking about current best practices, security hardening, and performance optimization that will make your sites fly.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>What Exactly Is a LAMP Stack and Why Does It Still Matter?<\/strong><\/h2>\n\n\n\n<p>Before we dive into the technical details, let&#8217;s ensure we&#8217;re all on the same page. LAMP is an acronym that stands for:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/nestnepal.com\/blog\/litespeed-vs-apache-vs-nginx-choose-for-2025\/\"><strong>L<\/strong>inux &#8211; The operating system<\/a><\/li>\n\n\n\n<li><strong>A<\/strong>pache &#8211; The web server<\/li>\n\n\n\n<li><a href=\"https:\/\/nestnepal.com\/blog\/mysql-vs-mariadb-vs-postgresql-hosting-2025\/\"><strong>M<\/strong>ySQL (or MariaDB) &#8211; The database<\/a><\/li>\n\n\n\n<li><strong>P<\/strong>HP &#8211; The programming language<\/li>\n<\/ul>\n\n\n\n<p>Think of LAMP as the foundation of your digital house. Linux is the foundation you build on, Apache is the structure that holds everything together, MySQL is where you store all your valuable data, and PHP is the electricity that makes everything work.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Why LAMP Still Dominates in 2025<\/strong><\/h3>\n\n\n\n<p>You might wonder, &#8220;Isn&#8217;t LAMP old technology?&#8221; Well, so is the wheel, but we&#8217;re still using it because it works brilliantly. Here&#8217;s why LAMP remains the go-to choice:<\/p>\n\n\n\n<p><strong>1. Proven Reliability:<\/strong> LAMP has been battle-tested by millions of websites over decades. It&#8217;s stable, predictable, and just works.<\/p>\n\n\n\n<p><strong>2. Universal Compatibility:<\/strong> Almost every web application, CMS, or framework supports LAMP. WordPress, Joomla, Drupal, custom PHP applications, they all love LAMP.<\/p>\n\n\n\n<p><strong>3. Cost-Effective:<\/strong> Everything in the LAMP stack is open-source and free. No licensing fees, no vendor lock-in.<\/p>\n\n\n\n<p><strong>4. Massive Community Support:<\/strong> Stuck with a problem? There&#8217;s probably a solution already documented somewhere, or thousands of developers ready to help.<\/p>\n\n\n\n<p><strong>5. Performance When Properly Configured:<\/strong> A well-tuned LAMP stack can handle massive traffic loads. Facebook started on LAMP, and many high-traffic sites still use it.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Choosing Your VPS: The Foundation Matters<\/strong><\/h2>\n\n\n\n<p>Before we start installing anything, let&#8217;s talk about choosing the right VPS. Not all VPS providers are created equal, and your choice will affect everything we do next.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Minimum Recommendations for LAMP in 2025<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td><strong>Resource<\/strong><\/td><td><strong>Minimum<\/strong><\/td><td><strong>Recommended<\/strong><\/td><td><strong>High-Traffic<\/strong><\/td><\/tr><tr><td><strong>RAM<\/strong><\/td><td>1GB<\/td><td>2GB<\/td><td>4GB+<\/td><\/tr><tr><td><strong>CPU<\/strong><\/td><td>1 vCPU<\/td><td>2 vCPU<\/td><td>4+ vCPU<\/td><\/tr><tr><td><strong>Storage<\/strong><\/td><td>20GB SSD<\/td><td>40GB SSD<\/td><td>100GB+ SSD<\/td><\/tr><tr><td><strong>Bandwidth<\/strong><\/td><td>1TB<\/td><td>Unlimited<\/td><td>Unlimited<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Operating System Choice<\/strong><\/h3>\n\n\n\n<p>For this guide, we&#8217;ll use <strong>Ubuntu 22.04 LTS<\/strong> (Long Term Support). Here&#8217;s why:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>5 years of security updates<\/strong> (until 2027)<\/li>\n\n\n\n<li><strong>Excellent hardware compatibility<\/strong><\/li>\n\n\n\n<li><strong>Massive community and documentation<\/strong><\/li>\n\n\n\n<li><strong>APT package manager<\/strong> makes installations easy<\/li>\n\n\n\n<li><strong>Regular, predictable update cycles<\/strong><\/li>\n<\/ul>\n\n\n\n<p>Choices that work great:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>CentOS Stream<\/strong> or <strong>Rocky Linux<\/strong> (RHEL-based)<\/li>\n\n\n\n<li><strong>Debian 12<\/strong> (super stable)<\/li>\n\n\n\n<li><strong>AlmaLinux<\/strong> (CentOS replacement)<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Initial Server Setup: Security First<\/strong><\/h2>\n\n\n\n<p>This is crucial; never skip server hardening. I&#8217;ve seen too many businesses get hacked because they skipped these basic security steps.<\/p>\n\n\n\n<p><strong>Step 1: Initial Connection and Updates<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>First, connect to your fresh VPS:\n# Connect via SSH (replace with your server IP)\nssh root@your-server-ip\n\n# Update the system completely\napt update &amp;&amp; apt upgrade -y\n\n# Install essential packages\napt install -y curl wget vim ufw fail2ban htop<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 2: Create a Non-Root User<\/strong><\/h3>\n\n\n\n<p>Never run services as root. Create a regular user with sudo privileges:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Create new user (replace 'nepal' with your preferred username)\nadduser nepal\n\n# Add user to sudo group\nusermod -aG sudo nepal\n\n# Test sudo access\nsu - nepal\nsudo whoami  # Should return 'root'<\/code><\/pre>\n\n\n\n<p><strong>Step 3: Configure SSH Security<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Edit SSH configuration\nsudo vim \/etc\/ssh\/sshd_config\n\n# Make these changes:\n# Port 2222                    # Change from default port 22\n# PermitRootLogin no          # Disable root login\n# PasswordAuthentication no   # Use keys only (after setting up keys)\n# MaxAuthTries 3              # Limit login attempts\n\n# Restart SSH service\nsudo systemctl restart ssh\n\nImportant: Set up SSH keys before disabling password authentication!<\/code><\/pre>\n\n\n\n<p><strong>Step 4: Configure Firewall<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Configure UFW (Uncomplicated Firewall)\nsudo ufw default deny incoming\nsudo ufw default allow outgoing\n\n# Allow SSH on your custom port\nsudo ufw allow 2222\n\n# Allow HTTP and HTTPS\nsudo ufw allow 80\nsudo ufw allow 443\n\n# Enable firewall\nsudo ufw enable\n\n# Check status\nsudo ufw status<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Installing Linux Components<\/strong><\/h2>\n\n\n\n<p>Your VPS likely came with Linux already installed, but let&#8217;s make sure we have everything optimized.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>System Optimization<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code># Install additional useful packages\nsudo apt install -y software-properties-common apt-transport-https ca-certificates\n\n# Configure timezone (important for logs and cron jobs)\nsudo timedatectl set-timezone Asia\/Kathmandu\n\n# Verify timezone setting\ntimedatectl\n\n# Configure automatic security updates\nsudo apt install -y unattended-upgrades\nsudo dpkg-reconfigure -plow unattended-upgrades<\/code><\/pre>\n\n\n\n<p><strong>Memory and Swap Configuration<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Check current memory\nfree -h\n\n# Create swap file (recommended: 2x RAM for servers with &lt;2GB RAM)\nsudo fallocate -l 2G \/swapfile\nsudo chmod 600 \/swapfile\nsudo mkswap \/swapfile\nsudo swapon \/swapfile\n\n# Make swap permanent\necho '\/swapfile none swap sw 0 0' | sudo tee -a \/etc\/fstab\n\n# Optimize swap usage (optional)\necho 'vm.swappiness=10' | sudo tee -a \/etc\/sysctl.conf<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Installing Apache: Your Web Server Foundation<\/strong><\/h2>\n\n\n\n<p>Apache remains the most popular web server globally, and for good reason. It&#8217;s flexible, well-documented, and handles almost any scenario you can throw at it.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 1: Install Apache<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code># Install Apache\nsudo apt install -y apache2\n\n# Start and enable Apache\nsudo systemctl start apache2\nsudo systemctl enable apache2\n\n# Check status\nsudo systemctl status apache2\n\n# Test installation\ncurl http:\/\/localhost<\/code><\/pre>\n\n\n\n<p>You should see the Apache default page HTML.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 2: Configure Apache Security<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code># Edit main Apache configuration\nsudo vim \/etc\/apache2\/conf-enabled\/security.conf\n\n# Add or modify these settings:\nServerTokens Prod\nServerSignature Off\n\n# Edit Apache main config\nsudo vim \/etc\/apache2\/apache2.conf\n\n# Add these security headers (at the end):\n# Hide Apache version\nServerTokens Prod\nServerSignature Off\n\n# Prevent access to .htaccess files\n&lt;FilesMatch \"^\\.ht\"&gt;\n    Require all denied\n&lt;\/FilesMatch&gt;<\/code><\/pre>\n\n\n\n<p><strong>Step 3: Enable Essential Apache Modules<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Enable important modules\nsudo a2enmod rewrite\nsudo a2enmod ssl\nsudo a2enmod headers\nsudo a2enmod deflate\nsudo a2enmod expires\n\n# Restart Apache to load modules\nsudo systemctl restart apache2<\/code><\/pre>\n\n\n\n<p><strong>Step 4: Create Your First Virtual Host<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Create directory for your website\nsudo mkdir -p \/var\/www\/mysite.com\n\n# Set proper ownership\nsudo chown -R $USER:www-data \/var\/www\/mysite.com\n\n# Create a simple index file\necho \"&lt;h1&gt;Welcome to My Site!&lt;\/h1&gt;\" | sudo tee \/var\/www\/mysite.com\/index.html\n\n# Create virtual host configuration\nsudo vim \/etc\/apache2\/sites-available\/mysite.com.conf\n\nAdd this configuration:\n&lt;VirtualHost *:80&gt;\n    ServerAdmin admin@mysite.com\n    ServerName mysite.com\n    ServerAlias www.mysite.com\n    DocumentRoot \/var\/www\/mysite.com\n    \n    &lt;Directory \/var\/www\/mysite.com&gt;\n        Options -Indexes +FollowSymLinks\n        AllowOverride All\n        Require all granted\n    &lt;\/Directory&gt;\n    \n    ErrorLog ${APACHE_LOG_DIR}\/mysite.com_error.log\n    CustomLog ${APACHE_LOG_DIR}\/mysite.com_access.log combined\n&lt;\/VirtualHost&gt;\n\n# Enable the site\nsudo a2ensite mysite.com.conf\n\n# Disable default site (optional)\nsudo a2dissite 000-default.conf\n\n# Test configuration\nsudo apache2ctl configtest\n\n# Reload Apache\nsudo systemctl reload apache2<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Installing MySQL: Your Data Powerhouse<\/strong><\/h2>\n\n\n\n<p><a href=\"https:\/\/nestnepal.com\/blog\/mysql-vs-mariadb-vs-postgresql-hosting-2025\/\">MySQL<\/a> is where all your website data lives. In 2025, we have some great options, but let&#8217;s go with MariaDB, it&#8217;s MySQL-compatible but with better performance and features.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 1: Install MariaDB<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code># Install MariaDB server\nsudo apt install -y mariadb-server mariadb-client\n\n# Start and enable MariaDB\nsudo systemctl start mariadb\nsudo systemctl enable mariadb\n\n# Check status\nsudo systemctl status mariadb<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 2: Secure MariaDB Installation<\/strong><\/h3>\n\n\n\n<p>This is critical \u2013 never skip this step:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Run security script\nsudo mysql_secure_installation<\/code><\/pre>\n\n\n\n<p>Answer the prompts like this:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Set root password<\/strong>: Yes (choose a strong password)<\/li>\n\n\n\n<li><strong>Remove anonymous users<\/strong>: Yes<\/li>\n\n\n\n<li><strong>Disallow root login remotely<\/strong>: Yes<\/li>\n\n\n\n<li><strong>Remove test database<\/strong>: Yes<\/li>\n\n\n\n<li><strong>Reload privilege tables<\/strong>: Yes<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 3: Configure MariaDB for Performance<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code># Edit MariaDB configuration\nsudo vim \/etc\/mysql\/mariadb.conf.d\/50-server.cnf\n\nAdd these optimizations under &#91;mysqld]:\n# Performance tuning for small to medium sites\ninnodb_buffer_pool_size = 128M\ninnodb_log_file_size = 32M\ninnodb_file_per_table = 1\ninnodb_flush_method = O_DIRECT\n\n# Query cache (helps with read-heavy sites)\nquery_cache_type = 1\nquery_cache_size = 16M\nquery_cache_limit = 1M\n\n# Connection settings\nmax_connections = 50\nthread_cache_size = 8\n\n# Binary logging (important for backups)\nlog-bin = mysql-bin\nexpire_logs_days = 7\n\n# Restart MariaDB to apply changes\nsudo systemctl restart mariadb<\/code><\/pre>\n\n\n\n<p><strong>Step 4: Create a Database and User<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Connect to MariaDB as root\nsudo mysql -u root -p\n\n# Create a database for your website\nCREATE DATABASE mysite_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;\n\n# Create a user for your website\nCREATE USER 'mysite_user'@'localhost' IDENTIFIED BY 'strong_password_here';\n\n# Grant privileges\nGRANT ALL PRIVILEGES ON mysite_db.* TO 'mysite_user'@'localhost';\n\n# Refresh privileges\nFLUSH PRIVILEGES;\n\n# Exit MySQL\nEXIT;<\/code><\/pre>\n\n\n\n<p><strong>Step 5: Test Database Connection<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Test connection with new user\nmysql -u mysite_user -p mysite_db\n\n# Run a test query\nSHOW DATABASES;\nEXIT;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Installing PHP: Bringing Your Sites to Life<\/strong><\/h2>\n\n\n\n<p>PHP powers over 70% of the web, including WordPress, and in 2025, PHP 8.3 is the sweet spot for performance and compatibility.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 1: Add PHP Repository and Install<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code># Add Ond\u0159ej's PHP repository (most up-to-date PHP versions)\nsudo add-apt-repository ppa:ondrej\/php -y\nsudo apt update\n\n# Install PHP 8.3 and essential modules\nsudo apt install -y php8.3 php8.3-fpm php8.3-mysql php8.3-common php8.3-cli<\/code><\/pre>\n\n\n\n<p><strong>Step 2: Install Essential PHP Extensions<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Install commonly needed PHP extensions\nsudo apt install -y php8.3-curl php8.3-gd php8.3-intl php8.3-mbstring \\\nphp8.3-soap php8.3-xml php8.3-xmlrpc php8.3-zip php8.3-bcmath \\\nphp8.3-imagick php8.3-redis php8.3-memcached\n\n# For Apache integration\nsudo apt install -y libapache2-mod-php8.3<\/code><\/pre>\n\n\n\n<p><strong>Step 3: Configure PHP for Production<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Edit PHP configuration\nsudo vim \/etc\/php\/8.3\/apache2\/php.ini\n\nFind and modify these settings:\n; Security settings\nexpose_php = Off\nallow_url_fopen = Off\nallow_url_include = Off\n\n; Performance settings\nmemory_limit = 256M\nmax_execution_time = 300\nmax_input_time = 300\npost_max_size = 32M\nupload_max_filesize = 32M\nmax_file_uploads = 20\n\n; Session security\nsession.cookie_httponly = 1\nsession.use_strict_mode = 1\nsession.cookie_secure = 1\n\n; Timezone\ndate.timezone = \"Asia\/Kathmandu\"\n\n; Error reporting (disable in production)\ndisplay_errors = Off\nlog_errors = On\nerror_log = \/var\/log\/php_errors.log<\/code><\/pre>\n\n\n\n<p><strong>Step 4: Configure PHP-FPM (Recommended)<\/strong><\/p>\n\n\n\n<p>PHP-FPM provides better performance and resource management:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Start and enable PHP-FPM\nsudo systemctl start php8.3-fpm\nsudo systemctl enable php8.3-fpm\n\n# Configure PHP-FPM pool\nsudo vim \/etc\/php\/8.3\/fpm\/pool.d\/www.conf\n\nKey settings to modify:\n; Process management\npm = dynamic\npm.max_children = 20\npm.start_servers = 2\npm.min_spare_servers = 2\npm.max_spare_servers = 6\npm.max_requests = 500\n\n; Security\nsecurity.limit_extensions = .php\n\n; Performance monitoring\npm.status_path = \/fpm-status\nping.path = \/fpm-ping<\/code><\/pre>\n\n\n\n<p><strong>Step 5: Enable Apache PHP-FPM Module<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Enable required modules\nsudo a2enmod proxy_fcgi setenvif\nsudo a2enconf php8.3-fpm\n\n# Restart services\nsudo systemctl restart apache2\nsudo systemctl restart php8.3-fpm<\/code><\/pre>\n\n\n\n<p><strong>Step 6: Test PHP Installation<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Create a PHP info file\necho \"&lt;?php phpinfo(); ?&gt;\" | sudo tee \/var\/www\/mysite.com\/info.php\n\n# Test PHP processing\ncurl http:\/\/your-server-ip\/info.php<\/code><\/pre>\n\n\n\n<p><strong>Important<\/strong>: Remove the info.php file after testing for security!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Testing Your Complete LAMP Stack<\/strong><\/h2>\n\n\n\n<p>Let&#8217;s create a simple test to ensure everything works together:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Create a Database Connection Test<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code># Create a comprehensive test file\nsudo vim \/var\/www\/mysite.com\/test.php\n\nAdd this content:\n&lt;?php\n\/\/ Database connection test\n$servername = \"localhost\";\n$username = \"mysite_user\";\n$password = \"strong_password_here\";\n$dbname = \"mysite_db\";\n\ntry {\n    $pdo = new PDO(\"mysql:host=$servername;dbname=$dbname\", $username, $password);\n    $pdo-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);\n    echo \"&lt;h2&gt;\u2705 Database Connection: SUCCESS&lt;\/h2&gt;\";\n    \n    \/\/ Test query\n    $stmt = $pdo-&gt;query(\"SELECT VERSION() as version\");\n    $version = $stmt-&gt;fetch();\n    echo \"&lt;p&gt;MySQL Version: \" . $version&#91;'version'] . \"&lt;\/p&gt;\";\n    \n} catch(PDOException $e) {\n    echo \"&lt;h2&gt;\u274c Database Connection: FAILED&lt;\/h2&gt;\";\n    echo \"&lt;p&gt;Error: \" . $e-&gt;getMessage() . \"&lt;\/p&gt;\";\n}\n\n\/\/ PHP information\necho \"&lt;h2&gt;\u2705 PHP Working&lt;\/h2&gt;\";\necho \"&lt;p&gt;PHP Version: \" . phpversion() . \"&lt;\/p&gt;\";\necho \"&lt;p&gt;Server Time: \" . date('Y-m-d H:i:s') . \"&lt;\/p&gt;\";\n\n\/\/ Apache information  \necho \"&lt;h2&gt;\u2705 Apache Working&lt;\/h2&gt;\";\necho \"&lt;p&gt;Server Software: \" . $_SERVER&#91;'SERVER_SOFTWARE'] . \"&lt;\/p&gt;\";\necho \"&lt;p&gt;Document Root: \" . $_SERVER&#91;'DOCUMENT_ROOT'] . \"&lt;\/p&gt;\";\n\n\/\/ Test file operations\n$testFile = '\/tmp\/lamp_test.txt';\nif (file_put_contents($testFile, 'LAMP Stack Test')) {\n    echo \"&lt;h2&gt;\u2705 File System: Working&lt;\/h2&gt;\";\n    unlink($testFile);\n} else {\n    echo \"&lt;h2&gt;\u274c File System: Issues detected&lt;\/h2&gt;\";\n}\n\necho \"&lt;h2&gt;\ud83c\udf89 LAMP Stack is Ready!&lt;\/h2&gt;\";\n?&gt;<\/code><\/pre>\n\n\n\n<p>Visit http:\/\/your-server-ip\/test.php to see the results.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Performance Optimization<\/strong><\/h2>\n\n\n\n<p>Now that everything&#8217;s working, let&#8217;s make it fast.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Apache Performance Tuning<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code># Edit Apache main config\nsudo vim \/etc\/apache2\/apache2.conf\n\nAdd these optimizations:\n# Performance settings\nKeepAlive On\nMaxKeepAliveRequests 100\nKeepAliveTimeout 15\n\n# Enable compression\nLoadModule deflate_module modules\/mod_deflate.so\n&lt;IfModule mod_deflate.c&gt;\n    AddOutputFilterByType DEFLATE text\/html text\/plain text\/xml text\/css text\/javascript application\/javascript\n&lt;\/IfModule&gt;\n\n# Enable caching\nLoadModule expires_module modules\/mod_expires.so\n&lt;IfModule mod_expires.c&gt;\n    ExpiresActive On\n    ExpiresByType text\/css \"access plus 1 month\"\n    ExpiresByType application\/javascript \"access plus 1 month\"\n    ExpiresByType image\/png \"access plus 1 year\"\n    ExpiresByType image\/jpg \"access plus 1 year\"\n    ExpiresByType image\/jpeg \"access plus 1 year\"\n    ExpiresByType image\/gif \"access plus 1 year\"\n    ExpiresByType image\/ico \"access plus 1 year\"\n&lt;\/IfModule&gt;<\/code><\/pre>\n\n\n\n<p><strong>MySQL\/MariaDB Performance Tuning<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Install MySQLTuner for recommendations\nsudo apt install -y mysqltuner\n\n# Run tuner after your site has been running for a while\nsudo mysqltuner<\/code><\/pre>\n\n\n\n<p><strong>Enable OPcache for PHP<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Edit PHP configuration\nsudo vim \/etc\/php\/8.3\/apache2\/php.ini\n\nAdd these OPcache settings:\n; OPcache settings\nopcache.enable=1\nopcache.memory_consumption=128\nopcache.interned_strings_buffer=8\nopcache.max_accelerated_files=4000\nopcache.revalidate_freq=2\nopcache.fast_shutdown=1\nopcache.enable_cli=1<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Security Hardening<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Install and Configure ModSecurity<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code># Install ModSecurity\nsudo apt install -y libapache2-mod-security2\n\n# Enable module\nsudo a2enmod security2\n\n# Download OWASP Core Rule Set\ncd \/etc\/modsecurity\nsudo git clone https:\/\/github.com\/SpiderLabs\/owasp-modsecurity-crs.git\nsudo mv owasp-modsecurity-crs\/crs-setup.conf.example owasp-modsecurity-crs\/crs-setup.conf\n\n# Configure ModSecurity\nsudo vim \/etc\/apache2\/mods-enabled\/security2.conf\n\nAdd this configuration:\n&lt;IfModule security2_module&gt;\n    SecRuleEngine On\n    SecRequestBodyAccess On\n    SecResponseBodyAccess On\n    SecResponseBodyMimeType text\/plain text\/html text\/xml\n    SecDataDir \/tmp\/\n    Include \/etc\/modsecurity\/owasp-modsecurity-crs\/crs-setup.conf\n    Include \/etc\/modsecurity\/owasp-modsecurity-crs\/rules\/*.conf\n&lt;\/IfModule&gt;<\/code><\/pre>\n\n\n\n<p><strong>Set Up Automatic Backups<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Create backup script\nsudo vim \/usr\/local\/bin\/lamp-backup.sh\n\n#!\/bin\/bash\n# LAMP Stack Backup Script\n\nBACKUP_DIR=\"\/backups\"\nDATE=$(date +%Y%m%d_%H%M%S)\nDB_USER=\"root\"\nDB_PASS=\"your_root_password\"\n\n# Create backup directory\nmkdir -p $BACKUP_DIR\n\n# Backup databases\nmysqldump -u $DB_USER -p$DB_PASS --all-databases &gt; $BACKUP_DIR\/all_databases_$DATE.sql\n\n# Backup web files\ntar -czf $BACKUP_DIR\/webfiles_$DATE.tar.gz \/var\/www\/\n\n# Backup Apache configuration\ntar -czf $BACKUP_DIR\/apache_config_$DATE.tar.gz \/etc\/apache2\/\n\n# Clean old backups (keep last 7 days)\nfind $BACKUP_DIR -type f -mtime +7 -delete\n\necho \"Backup completed: $DATE\"\n\n# Make script executable\nsudo chmod +x \/usr\/local\/bin\/lamp-backup.sh\n\n# Add to crontab (daily at 2 AM)\necho \"0 2 * * * \/usr\/local\/bin\/lamp-backup.sh\" | sudo crontab -<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Installing SSL Certificates with Let&#8217;s Encrypt<\/strong><\/h2>\n\n\n\n<p>Never run a website without HTTPS in 2025. Let&#8217;s Encrypt makes it free and automatic.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Install Certbot<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code># Install snapd\nsudo apt install -y snapd\n\n# Install certbot via snap\nsudo snap install --classic certbot\n\n# Create symlink\nsudo ln -s \/snap\/bin\/certbot \/usr\/bin\/certbot<\/code><\/pre>\n\n\n\n<p><strong>Get an SSL Certificate<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Get certificate for your domain\nsudo certbot --apache -d mysite.com -d www.mysite.com\n\n# Test automatic renewal\nsudo certbot renew --dry-run<\/code><\/pre>\n\n\n\n<p>Certbot automatically configures Apache for HTTPS and sets up auto-renewal.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Monitoring and Maintenance<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Install System Monitoring<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code># Install htop for process monitoring\nsudo apt install -y htop iotop nethogs\n\n# Install log analysis tools\nsudo apt install -y logwatch goaccess\n\n# Configure logwatch for daily reports\nsudo vim \/etc\/cron.daily\/00logwatch<\/code><\/pre>\n\n\n\n<p><strong>Set Up Log Rotation<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Configure logrotate for Apache logs\nsudo vim \/etc\/logrotate.d\/apache2\n\n\/var\/log\/apache2\/*.log {\n    daily\n    missingok\n    rotate 14\n    compress\n    delaycompress\n    notifempty\n    create 640 root adm\n    sharedscripts\n    postrotate\n        \/etc\/init.d\/apache2 reload &gt; \/dev\/null\n    endscript\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Troubleshooting Common Issues<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Apache Won&#8217;t Start<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code># Check for configuration errors\nsudo apache2ctl configtest\n\n# Check detailed error logs\nsudo tail -f \/var\/log\/apache2\/error.log\n\n# Check if port is already in use\nsudo netstat -tulpn | grep :80<\/code><\/pre>\n\n\n\n<p><strong>MySQL Connection Issues<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Check MySQL status\nsudo systemctl status mariadb\n\n# Check MySQL error logs\nsudo tail -f \/var\/log\/mysql\/error.log\n\n# Test MySQL connection\nmysql -u root -p -e \"SELECT 1\"<\/code><\/pre>\n\n\n\n<p><strong>PHP Not Processing<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Check PHP-FPM status\nsudo systemctl status php8.3-fpm\n\n# Check PHP-FPM error logs\nsudo tail -f \/var\/log\/php8.3-fpm.log\n\n# Verify Apache PHP module\napache2ctl -M | grep php<\/code><\/pre>\n\n\n\n<p><strong>High Memory Usage<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Check memory usage\nfree -h\nsudo htop\n\n# Check which processes are using most memory\nps aux --sort=-%mem | head -10\n\n# Optimize MySQL memory usage\nsudo mysqltuner<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Scaling Your LAMP Stack<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Adding Multiple Sites<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code># Create new site structure\nsudo mkdir -p \/var\/www\/site2.com\nsudo chown -R $USER:www-data \/var\/www\/site2.com\n\n# Create virtual host\nsudo vim \/etc\/apache2\/sites-available\/site2.com.conf\n\n# Enable site\nsudo a2ensite site2.com.conf\nsudo systemctl reload apache2<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Load Balancing with Multiple Servers<\/strong><\/h3>\n\n\n\n<p>For high-traffic scenarios, consider:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>nginx as a reverse proxy<\/strong> in front of Apache<\/li>\n\n\n\n<li><strong>Database replication<\/strong> for read scaling<\/li>\n\n\n\n<li><strong>Redis\/Memcached<\/strong> for session storage<\/li>\n\n\n\n<li><strong>CDN integration<\/strong> for static assets<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Performance Monitoring<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code># Install monitoring tools\nsudo apt install -y netdata\n\n# Access monitoring dashboard\n# Visit: http:\/\/your-server:19999<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>2025 Best Practices Summary<\/strong><\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Always use HTTPS<\/strong> &#8211; No exceptions<\/li>\n\n\n\n<li><strong>Regular security updates<\/strong> &#8211; Set up automatic updates<\/li>\n\n\n\n<li><strong>Monitor performance<\/strong> &#8211; Use tools like netdata or New Relic<\/li>\n\n\n\n<li><strong>Backup everything<\/strong> &#8211; Database, files, and configurations<\/li>\n\n\n\n<li><strong>Use PHP-FPM<\/strong> &#8211; Better performance than mod_php<\/li>\n\n\n\n<li><strong>Enable OPcache<\/strong> &#8211; Significant PHP performance boost<\/li>\n\n\n\n<li><strong>Configure firewalls<\/strong> &#8211; UFW + fail2ban minimum<\/li>\n\n\n\n<li><strong>Log monitoring<\/strong> &#8211; Set up alerts for errors<\/li>\n\n\n\n<li><strong>Use strong passwords<\/strong> &#8211; For all accounts and databases<\/li>\n\n\n\n<li><strong>Regular maintenance<\/strong> &#8211; Updates, cleanup, optimization<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Conclusion: Your LAMP Stack Journey<\/strong><\/h2>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"800\" height=\"600\" data-src=\"https:\/\/nestnepal.com\/blog\/wp-content\/uploads\/2025\/08\/image-37.png\" alt=\"LAMP\" class=\"wp-image-13209 lazyload\" data-srcset=\"https:\/\/nestnepal.com\/blog\/wp-content\/uploads\/2025\/08\/image-37.png 800w, https:\/\/nestnepal.com\/blog\/wp-content\/uploads\/2025\/08\/image-37-300x225.png 300w, https:\/\/nestnepal.com\/blog\/wp-content\/uploads\/2025\/08\/image-37-768x576.png 768w, https:\/\/nestnepal.com\/blog\/wp-content\/uploads\/2025\/08\/image-37-400x300.png 400w\" data-sizes=\"(max-width: 800px) 100vw, 800px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 800px; --smush-placeholder-aspect-ratio: 800\/600;\" \/><\/figure>\n\n\n\n<p>Congratulations! You&#8217;ve just built a production-ready LAMP stack that can power everything from a simple business website to a complex web application. This isn&#8217;t just any LAMP stack \u2013 this is a 2025-optimized, secure, and performance-tuned foundation that can grow with your needs.<\/p>\n\n\n\n<p>What you&#8217;ve accomplished here puts you in the top tier of web developers and system administrators. Many agencies and freelancers in Nepal still struggle with proper server setup, but you now have the skills to deploy and manage professional-grade web hosting infrastructure.<\/p>\n\n\n\n<p>The LAMP stack you&#8217;ve built today includes:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Security hardening<\/strong> that protects against common attacks<\/li>\n\n\n\n<li><strong>Performance optimization<\/strong> that can handle significant traffic<\/li>\n\n\n\n<li><strong>Monitoring and backup systems<\/strong> for reliable operations<\/li>\n\n\n\n<li><strong>SSL encryption<\/strong> for user trust and SEO benefits<\/li>\n\n\n\n<li><strong>Scalable architecture<\/strong> ready for growth<\/li>\n<\/ul>\n\n\n\n<p>Remember, this is a foundation, not a destination. As your sites grow and your needs evolve, you can add caching layers (<a href=\"https:\/\/redis.io\/\" target=\"_blank\" rel=\"noopener\">Redis<\/a>, <a href=\"https:\/\/memcached.org\/\" target=\"_blank\" rel=\"noopener\">Memcached<\/a>), implement load balancing, set up database clustering, or even migrate to cloud-native architectures.<\/p>\n\n\n\n<p>But for now, you have something powerful: a solid, secure, fast web server that you understand inside and out. That&#8217;s invaluable knowledge in today&#8217;s digital economy, whether you&#8217;re building sites for local businesses in Kathmandu, serving international clients, or launching the next big Nepali startup.<\/p>\n\n\n\n<p>Keep learning, keep optimizing, and most importantly, keep building amazing things on the foundation you&#8217;ve created today. The Nepal tech scene is growing rapidly, and skilled system administrators who truly understand their infrastructure are in high demand.<\/p>\n\n\n\n<p>Your LAMP stack is ready. Now go build something awesome on it.<\/p>\n\n\n\n<p><em>Need help with advanced LAMP stack configurations, performance tuning, or scaling to handle high traffic? The team at <a href=\"https:\/\/nestnepal.com\/\">Nest Nepal<\/a> has years of experience optimizing web servers for businesses of all sizes. Whether you&#8217;re <a href=\"https:\/\/nestnepal.com\/nepal-based-vps-hosting\/\">launching your first VPS<\/a> or managing multiple production servers, we&#8217;re here to help you succeed.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Remember when setting up a web server felt like trying to assemble a motorcycle while blindfolded? Those days don&#8217;t&#8230;<\/p>\n","protected":false},"author":15,"featured_media":13265,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[207],"tags":[310],"class_list":["post-13207","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-vps","tag-vps-hosting-in-nepal"],"_links":{"self":[{"href":"https:\/\/nestnepal.com\/blog\/wp-json\/wp\/v2\/posts\/13207","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nestnepal.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nestnepal.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nestnepal.com\/blog\/wp-json\/wp\/v2\/users\/15"}],"replies":[{"embeddable":true,"href":"https:\/\/nestnepal.com\/blog\/wp-json\/wp\/v2\/comments?post=13207"}],"version-history":[{"count":5,"href":"https:\/\/nestnepal.com\/blog\/wp-json\/wp\/v2\/posts\/13207\/revisions"}],"predecessor-version":[{"id":13253,"href":"https:\/\/nestnepal.com\/blog\/wp-json\/wp\/v2\/posts\/13207\/revisions\/13253"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nestnepal.com\/blog\/wp-json\/wp\/v2\/media\/13265"}],"wp:attachment":[{"href":"https:\/\/nestnepal.com\/blog\/wp-json\/wp\/v2\/media?parent=13207"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nestnepal.com\/blog\/wp-json\/wp\/v2\/categories?post=13207"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nestnepal.com\/blog\/wp-json\/wp\/v2\/tags?post=13207"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}