Setup LAMP (Linux, Apache, Mysql, Php) di Nixos

Cara install dan menjalankan wordpress, drupal, joomla, laravel, codeigniter, dengan LAMP stack di Nixos secara local


JagoTekno.com - Setelah kemarin kita sudah belajar setup LEMP stack di nixos. Sekarang kita coba setup LAMP stack.

Jika Anda mencari cara untuk mengatur lingkungan pengembangan web atau server yang kuat dan aman untuk menjalankan platform-platform seperti WordPress, Laravel, Drupal, dan Joomla di NixOS, maka Anda berada di tempat yang tepat. Artikel ini akan memberikan panduan langkah demi langkah tentang cara menyiapkan LAMP Stack (Linux, Apache, MySQL, PHP) di NixOS untuk hosting berbagai jenis situs web.

Apa itu LAMP Stack?

LAMP adalah singkatan dari kombinasi teknologi berikut:

Linux: Sistem operasi open-source yang akan menjadi fondasi server Anda.
Apache: Server web open-source yang akan mengatur lalu lintas HTTP ke situs web Anda.
MySQL: Sistem manajemen basis data relasional yang akan digunakan untuk menyimpan data situs web Anda.
PHP: Bahasa pemrograman server yang digunakan untuk menghasilkan halaman web dinamis.

Cara install LAMP stack di nixos

  1. Buat file config web server di luar file configuration.nix
cd /etc/nixos/
mkdir apache
cd apache
vim default.nix
  1. Kemudian copy paste configurasi berikut pada file default.nix yang baru saja dibuat.
{ lib, config, pkgs, ...}:

{

networking.firewall.allowedTCPPorts = [ 80 443 ];
# apache
services.httpd.enable = true;
services.httpd.package = pkgs.apacheHttpd;
# php
services.httpd.enablePHP = true;
services.httpd.phpPackage = pkgs.php;
# mysql
services.mysql.enable = true;
services.mysql.package = pkgs.mariadb;

# setting apache virtualhost
services.httpd.user = "yourusername";
services.httpd.group = "users";

services.httpd.virtualHosts = {
 "wp.localhost" = {
	documentRoot = "/home/yourusername/Project/wp/wordpress";
	extraConfig = ''
		Timeout 600
		ProxyTimeout 600

		Alias /wordpress "/home/yourusername/Project/wp/wordpress/"
		DirectoryIndex index.php index.html index.htm
		<Directory "/home/yourusername/Project/wp/wordpress/">
			Options FollowSymLinks
			AllowOverride Limit Options FileInfo
			DirectoryIndex index.php
			Require all granted
		</Directory>
		'';
	addSSL = true;
	enableACME = true;
	};
 "drupal.localhost" = {
	documentRoot = "/home/yourusername/Project/drupal/drupalweb";
    extraConfig = ''
        Alias /drupal "/home/yourusername/Project/drupal/drupalweb/"

        <Directory "/home/yourusername/Project/drupal/drupalweb/">
            Options Indexes FollowSymLinks
            AllowOverride All
            Require all granted
        </Directory>
        '';
	addSSL = true;
	enableACME = true;
	};
 "joomla.localhost" = {
	documentRoot = "/home/yourusername/Project/joomla/joomlaweb";
	extraConfig = ''
		Timeout 600
		ProxyTimeout 600

		Alias /joomla "/home/yourusername/Project/joomla/joomlaweb/"
		DirectoryIndex index.php index.html index.htm
		<Directory "/home/yourusername/Project/joomla/joomlaweb/">
			Options FollowSymLinks
			AllowOverride Limit Options FileInfo
			DirectoryIndex index.php
			Require all granted
		</Directory>
		'';
	addSSL = true;
	enableACME = true;
	};
};

services.httpd.phpOptions = ''
  date.timezone = "Asia/Makassar";
  display_errors = on;
  upload_max_filesize = "100M";
  post_max_size = "100M";
'';

security.acme = {
	acceptTerms = true;
	useRoot = true;
	certs = {
		"wp.localhost" = {
			webroot = "/var/lib/acme/acme-challenge";
			email = "youremail@address.com";
		};
		"drupal.localhost" = {
			webroot = "/var/lib/acme/acme-challenge";
			email = "youremail@address.com";
		};
		"joomla.localhost" = {
			webroot = "/var/lib/acme/acme-challenge";
			email = "youremail@address.com";
		};
	};
};


services.phpfpm.pools.mypool = {
  user = "nobody";
  settings = {
    pm = "dynamic";
    "listen.owner" = config.services.httpd.user;
    "pm.max_children" = 5;
    "pm.start_servers" = 2;
    "pm.min_spare_servers" = 1;
    "pm.max_spare_servers" = 3;
    "pm.max_requests" = 500;
  };
};

}
  1. Kemudian edit file configuration.nix untuk include config LAMP web server yang barusan dibuat.
{ config, pkgs, ... }:

...
    [ # Include the results of the hardware scan.
      ./hardware-configuration.nix
      ./apache/default.nix
    ];
    nix.extraOptions = ''
    experimental-features = nix-command
    '';
...

# tambahkan juga 
  # Host for open reddit
  networking.extraHosts = ''
    127.0.0.1         local.nixhost
  '';

...
  1. Rebuild system sudo nixos-rebuild switch.

  2. Sekarang silahkan develop web anda pada /home sesuai folder root yang sudah diset pada konfigurasi di atas.

Checklist yang berhasil dilakukan

  • Web dev dengan SSL yang sudah aktif.
  • Bisa menjalankan npm (tailwind, dkk di lamp karena folder web ada di /home, bukan di /var/www/).
  • Mysql berjalan tanpa password database, jadi saat install wordpress, drupal, dkk tidak usah isi password database. Cukup jalankan dengan perintah mysql -u root saja.
  • Akses web dengan link virtualhost yang sudah dibuat (wp.localhost, drupal.localhost, joomla.localhost)

Mengecek service yang berjalan

Silahkan ketik sudo systemctl --type=service --state=running

pastikan phpfpm, mysql, dan httpd berjalan.

list running service systemctl nixos

Selesai.

Cara Setting File PHP.ini di Nixos untuk menambah upload_max_filesize dan post_max_size
Ditulis oleh Rafi pada Saturday, 23 September 2023
mrfdn author

Rafi

  • 15 year+ of Linux user.
  • 5 years+ blogger and web developer.

Jika artikel yang dibuatnya ternyata bermanfaat, support dengan cara

Baca juga


comments powered by Disqus