LAMP stack (Linux, Apache, MariaDB / MySQL, dan PHP) adalah perangkat lunak yang paling banyak digunakan tumpukan teknologi yang digunakan oleh perusahaan hosting untuk meng-host situs web dan blog. Selain itu, tumpukan ini biasanya digunakan untuk menerapkan sistem manajemen konten seperti WordPress, Drupal, Joomla, dll.
Di sini, kita akan melihat cara menginstal LAMP stack di Ubuntu 20.04.
Instal AMP Stack
Di Ubuntu, Anda dapat menginstal tumpukan AMP secara manual dengan menginstal Apache, MariaDB, dan PHP satu per satu atau seluruh tumpukan dengan satu perintah.
Saat menginstal AMP Stack menggunakan satu perintah, itu akan menginstal MySQL v8.0. Namun, pada saat yang sama, jika Anda memilih untuk menginstal tumpukan LAMP secara manual, Anda akan mendapatkan MariaDB v10.6.Metode 1:Instal LAMP Stack Secara Manual (Satu per satu)
Kami akan menginstal AMP (Apache v2.4, PHP v8.1, dan MariaDB v10.6) di Ubuntu 20.04.
Instal Apache
Pertama, perbarui indeks repositori paket.
sudo apt update
Kemudian, instal paket apache2 menggunakan apt
perintah.
sudo apt install -y apache2 apache2-utils
Instal MariaDB
MariaDB telah menggantikan MySQL sebagai server database default di Ubuntu, dan tersedia (v10.6) dari repositori Ubuntu.
Anda juga dapat menginstal versi terbaru MariaDB dari repositori MariaDB.
sudo apt install -y mariadb-server mariadb-client
Kemudian, jalankan mysql_secure_installation
perintah untuk mengamankan instalasi MySQL.
sudo mysql_secure_installation
Keluaran:
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MariaDB to secure it, we'll need the current password for the root user. If you've just installed MariaDB, and haven't set the root password yet, you should just press enter here. Enter current password for root (enter for none): << Just Press Enter OK, successfully used password, moving on... Setting the root password or using the unix_socket ensures that nobody can log into the MariaDB root user without the proper authorisation. You already have your root account protected, so you can safely answer 'n'. Switch to unix_socket authentication [Y/n] N << Disable Unix Socket Authentication ... skipping. You already have your root account protected, so you can safely answer 'n'. Change the root password? [Y/n] Y << Set MariaDB root password New password: xxx << Enter new MariaDB root password Re-enter new password: xxx << Re-enter new MariaDB root password Password updated successfully! Reloading privilege tables.. ... Success! By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Y/n] Y << Remove Anonymous Users ... Success! Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n] Y << Disallow root login remotely ... Success! By default, MariaDB comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y/n] Y << Remove test database - Dropping test database... ... Success! - Removing privileges on test database... ... Success! Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n] Y << Reload privilege tables ... Success! Cleaning up... All done! If you've completed all of the above steps, your MariaDB installation should now be secure. Thanks for using MariaDB!
Instal PHP
Secara default, server Apache hanya mendukung penyajian file HTML statis, bukan PHP. Oleh karena itu, Anda perlu menginstal PHP dan paket ekstensi PHP untuk MariaDB/MySQL jika diperlukan untuk mengaktifkan dukungan PHP.
Ubuntu 22.04 hadir dengan PHP v8.1.
sudo apt install -y php php-mysql libapache2-mod-php
Setelah instalasi, restart server web Apache.
sudo systemctl restart apache2
Sekarang, Anda dapat menuju ke Pengujian LAMP Stack.
Metode 2:Instal LAMP Stack Dalam Satu Perintah
Kami akan menginstal AMP (Apache v2.4, PHP v8.1, dan MySQL v8.0) di Ubuntu 20.04.
Perbarui cache repositori menggunakan perintah apt.
sudo apt update
Rekatkan di bawah baris di terminal dan tekan enter.
sudo apt install -y lamp-server^
Perintah di atas akan mencari dan menginstal paket yang diperlukan untuk server LAMP. Anda perlu menunggu beberapa menit agar penginstalan tumpukan LAMP selesai.
Jalankan mysql_secure_installation
perintah untuk mengamankan instalasi MySQL.
sudo mysql_secure_installation
Keluaran:
Securing the MySQL server deployment. Connecting to MySQL using a blank password. VALIDATE PASSWORD COMPONENT can be used to test passwords and improve security. It checks the strength of password and allows the users to set only those passwords which are secure enough. Would you like to setup VALIDATE PASSWORD component? Press y|Y for Yes, any other key for No: Y << Enable validate password component to validate the strength of user passwords There are three levels of password validation policy: LOW Length >= 8 MEDIUM Length >= 8, numeric, mixed case, and special characters STRONG Length >= 8, numeric, mixed case, special characters and dictionary file Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2 << Level of password validation policy Please set the password for root here. New password: xxx << Set MySQL root password Re-enter new password: xxx << Re-Enter MySQL root password Estimated strength of the password: 100 Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y << Continue By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y << Remove anonymous users Success. Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y << Disable root login remotely Success. By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y << Remove test database - Dropping test database... Success. - Removing privileges on test database... Success. Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y << Reload tables Success. All done!MySQL menggunakan mekanisme otentikasi Unix Socket untuk pengguna root MySQL ketika diinstal dari repositori Ubuntu. Mekanisme otentikasi ini memungkinkan pengguna root MySQL untuk masuk hanya dari soket Unix (# prompt atau sudo).
Untuk menonaktifkan otentikasi Unix Socket dan mengaktifkan mekanisme kata sandi asli, ikuti langkah-langkah di bawah ini.
Masuk sebagai pengguna root MariaDB.
sudo mysql -u root -p
Tidak perlu kata sandi
use mysql; update user set plugin='mysql_native_password' where user='root'; flush privileges; quit;
Uji Tumpukan LAMP
Akar dokumen default Apache adalah /var/www/html
dan file konfigurasi utamanya adalah /etc/apache2/apache2.conf
. Anda dapat menemukan konfigurasi tambahan seperti host dan modul virtual di /etc/apache2/*-enabled
direktori.
Untuk menguji PHP, kami akan menempatkan satu file PHP ke root dokumen default Apache.
echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php
Sekarang buka browser web dan ketik berikut ini ke alamat web untuk mengakses halaman pengujian:
http://ip.ad.dr.ess/info.phpHalamannya akan terlihat seperti di bawah ini.
Gulir halaman ke bawah untuk melihat detail ekstensi PHP untuk MySQL/MariaDB.
Kesimpulan
Itu saja. Saya harap, sekarang, Anda memiliki tumpukan LAMP di Ubuntu 20.04. Silakan bagikan tanggapan Anda di bagian komentar.