One place for hosting & domains


      How to Install WordPress with LEMP on Ubuntu 20.04


      WordPress, one of the most popular content management systems (CMS) on the internet currently, allows users to set up flexible blogs and websites using a MySQL backend with PHP processing. WordPress has seen an incredible adoption rate among new and experienced engineers alike, and is a great choice for getting a website up and running efficiently. After an initial setup, almost all administration for WordPress websites can be done through its graphical interface— these features and more make WordPress a great choice for websites built to scale.

      In this tutorial, you’ll focus on getting an instance of WordPress set up on a LEMP stack (Linux, Nginx, MySQL, and PHP) for an Ubuntu 20.04 server.


      In order to complete this tutorial, you’ll need access to an Ubuntu 20.04 server. To successfully install WordPress with LEMP on your server, you’ll also need to perform the following tasks before starting this tutorial:

      • Create a sudo user on your server: The steps in this tutorial are using a non-root user with sudo privileges. You can create a user with sudo privileges by following our Ubuntu 20.04 initial server setup tutorial.
      • Install a LEMP stack: WordPress will need a web server, a database, and PHP in order to correctly function. Setting up a LEMP stack (Linux, Nginx, MySQL, and PHP) fulfills all of these requirements. Follow this tutorial to install and configure this software.

      Rather than setting up these components yourself, you can quickly provision Ubuntu 20.04 server that already has a LEMP stack installed with DigitalOcean’s LEMP 1-click install app.

      Be aware, though, that this tutorial still assumes you have an administrative sudo user and an Nginx server block configured on your server. Even with a server provisioned with the LEMP 1-click app, you’ll need to follow Steps 1, 2, 3, and 5 of our Ubuntu 20.04 initial server setup tutorial. You’ll also need to complete Step 4 of our guide on installing the LEMP Stack on Ubuntu 20.04 to configure an Nginx server block and configure Nginx to use the PHP Processor

      • Secure your site with SSL: WordPress serves dynamic content and handles user authentication and authorization. TLS/SSL is the technology that allows you to encrypt the traffic from your site so that your connection is secure. The way you set up SSL will depend on whether you have a domain name for your site.
        • If you have a domain name, the easiest way to secure your site is with Let’s Encrypt, which provides free, trusted certificates. Follow our Let’s Encrypt guide for Nginx to set this up.
        • If you do not have a domain and you’re using this configuration for testing or personal use, you can use a self-signed certificate instead. This provides the same type of encryption, but without the domain validation. Follow our self-signed SSL guide for Nginx to get set up.

      When you are finished with setup, log in to your server as the sudo user to continue.

      Step 1 — Creating a MySQL Database and User for WordPress

      WordPress uses MySQL to manage and store site and user information. Although you already have MySQL installed, let’s create a database and a user for WordPress to use.

      To get started, log in to the MySQL root (administrative) account. If MySQL is configured to use the auth_socket authentication plugin (which is default), you can log in to the MySQL administrative account using sudo:

      If you have changed the authentication method to use a password for the MySQL root account, use the following command instead:

      You will be prompted for the password you set for the MySQL root account.

      Once logged in, create a separate database that WordPress can control. You can call this whatever you would like, but we will be using wordpress in this guide to keep it simple. You can create a database for WordPress by entering:

      • CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;

      Note: Every MySQL statement must end in a semi-colon (;). If you’ve encountered an error, check to make sure the semicolon is present.

      Next, let’s create a separate MySQL user account that we will use exclusively to operate on our new database. Creating single-purpose databases and accounts is a good idea from a management and security standpoint. We’ll use the name wordpressuser in this guide — feel free to change this if you’d like.

      In the following command, you are going to create an account, set a password, and grant access to the database you created. Remember to choose a strong password here:

      • CREATE USER 'wordpressuser'@'localhost' IDENTIFIED BY 'password';
      • GRANT ALL ON wordpress.* TO 'wordpressuser'@'localhost’;

      You now have a database and user account, each made specifically for WordPress.

      With the database tasks complete, let’s exit out of MySQL by typing:

      The MySQL session will exit, returning you to the regular Linux shell.

      Step 2 — Installing Additional PHP Extensions

      When setting up the LEMP stack, it required a very minimal set of extensions to get PHP to communicate with MySQL. WordPress and many of its plugins leverage additional PHP extensions, and you’ll use a few more in this tutorial.

      Let’s download and install some of the most popular PHP extensions for use with WordPress by typing:

      • sudo apt install php-curl php-gd php-intl php-mbstring php-soap php-xml php-xmlrpc php-zip

      Note: Each WordPress plugin has its own set of requirements. Some may require additional PHP extension packages to be installed. Check your plugin documentation to discover its PHP requirements. If they are available, they can be installed with apt as demonstrated above.

      When you are finished installing the extensions, restart the PHP-FPM process so that the running PHP processor can leverage the newly installed features:

      • sudo systemctl restart php7.4-fpm

      You now have all of the PHP extensions needed, installed on the server.

      Step 3 — Configuring Nginx

      Next, let’s make a few adjustments to our Nginx server block files. Based on the prerequisite tutorials, you should have a configuration file for your site in the /etc/nginx/sites-available/ directory configured to respond to your server’s domain name or IP address and protected by a TLS/SSL certificate. We’ll use /etc/apache2/sites-available/wordpress as an example here, but you should substitute the path to your configuration file where appropriate.

      Additionally, we will use /var/www/wordpress as the root directory of our WordPress install in this guide. Again, you should use the web root specified in your own configuration.

      Note: It’s possible you are using the /etc/nginx/sites-available/default default configuration (with /var/www/html as your web root). This is fine to use if you’re only going to host one website on this server. If not, it’s best to split the necessary configuration into logical chunks, one file per site.

      Open your site’s server block file with sudo privileges to begin:

      • sudo nano /etc/nginx/sites-available/wordpress

      Within the main server block, let’s add a few location blocks.

      Start by creating exact-matching location blocks for requests to /favicon.ico and /robots.txt, both of which you do not want to log requests for.

      Use a regular expression location to match any requests for static files. We will again turn off the logging for these requests and will mark them as highly cacheable, since these are typically expensive resources to serve. You can adjust this static files list to contain any other file extensions your site may use:


      server {
          . . .
          location = /favicon.ico { log_not_found off; access_log off; }
          location = /robots.txt { log_not_found off; access_log off; allow all; }
          location ~* .(css|gif|ico|jpeg|jpg|js|png)$ {
              expires max;
              log_not_found off;
          . . .

      Inside of the existing location / block, let’s adjust the try_files list. Comment out the default setting by prepending the line with a pound sign (#) and then add the highlighted line. This way, instead of returning a 404 error as the default option, control is passed to the index.php file with the request arguments.

      This should look something like this:


      server {
          . . .
          location / {
              #try_files $uri $uri/ =404;
              try_files $uri $uri/ /index.php$is_args$args;
          . . .

      When you are finished, save and close the file.

      Now, let’s check our configuration for syntax errors by typing:

      If no errors were reported, reload Nginx by typing:

      • sudo systemctl reload nginx

      Next, let’s download and set up WordPress.

      Step 4 — Downloading WordPress

      Now that your server software is configured, let’s download and set up WordPress. For security reasons, it is always recommended to get the latest version of WordPress directly from the project’s website.

      Change into a writable directory and then download the compressed release by typing:

      This changes your directory to the temporary folder. Then, enter the following command to download the latest version of WordPress in a compressed file:

      • curl -LO

      Note: The -LO flag is used to get directly to the source of the compressed file. -L ensures that fetching the file is successful in the case of redirects, and -O writes the output of our remote file with a local file that has the same name. To learn more about curl commands, visit How to Download Files with cURL

      Extract the compressed file to create the WordPress directory structure:

      You will be moving these files into our document root momentarily, but before you do, let’s copy over the sample configuration file to the filename that WordPress actually reads:

      • cp /tmp/wordpress/wp-config-sample.php /tmp/wordpress/wp-config.php

      Now, let’s copy the entire contents of the directory into our document root. We’re using the -a flag to make sure our permissions are maintained, and a dot at the end of our source directory to indicate that everything within the directory should be copied (including hidden files):

      • sudo cp -a /tmp/wordpress/. /var/www/wordpress

      Now that our files are in place, you’ll assign ownership to the www-data user and group. This is the user and group that Nginx runs as, and Nginx will need to be able to read and write WordPress files in order to serve the website and perform automatic updates:

      • sudo chown -R www-data:www-data /var/www/wordpress

      Files are now in the server’s document root and have the correct ownership, but you still need to complete some additional configuration.

      Step 5 — Setting up the WordPress Configuration File

      Next, let’s make some changes to the main WordPress configuration file.

      When you open the file, you’ll start by adjusting some secret keys to provide some security for our installation. WordPress provides a secure generator for these values so that you don’t have to come up with values on your own. These are only used internally, so it won’t hurt usability to have complex, secure values here.

      To grab secure values from the WordPress secret key generator, type:

      • curl -s

      You will get back unique values that look something like this:

      Warning: It is important that you request unique values each time. Do NOT copy the values shown below!


      define('AUTH_KEY', '1jl/vqfs<XhdXoAPz9 DO NOT COPY THESE VALUES c_j{iwqD^<+c9.k<J@4H'); define('SECURE_AUTH_KEY', 'E2N-h2]Dcvp+aS/p7X DO NOT COPY THESE VALUES {Ka(f;rv?Pxf})CgLi-3'); define('LOGGED_IN_KEY', 'W(50,{W^,OPB%PB<JF DO NOT COPY THESE VALUES 2;y&,2m%3]R6DUth[;88'); define('NONCE_KEY', 'll,4UC)7ua+8<!4VM+ DO NOT COPY THESE VALUES #`DXF+[$atzM7 o^-C7g'); define('AUTH_SALT', 'koMrurzOA+|L_lG}kf DO NOT COPY THESE VALUES 07VC*Lj*lD&?3w!BT#-'); define('SECURE_AUTH_SALT', 'p32*p,]z%LZ+pAu:VY DO NOT COPY THESE VALUES C-?y+K0DK_+F|0h{!_xY'); define('LOGGED_IN_SALT', 'i^/G2W7!-1H2OQ+t$3 DO NOT COPY THESE VALUES t6**bRVFSD[Hi])-qS`|'); define('NONCE_SALT', 'Q6]U:K?j4L%Z]}h^q7 DO NOT COPY THESE VALUES 1% ^qUswWgn+6&xqHN&%');

      These are configuration lines that you can paste directly in your configuration file to set secure keys. Copy the output you received now.

      Now, open the WordPress configuration file:

      • sudo nano /var/www/wordpress/wp-config.php

      Find the section that contains the dummy values for those settings. It will look something like this:


      . . .
      define('AUTH_KEY',         'put your unique phrase here');
      define('SECURE_AUTH_KEY',  'put your unique phrase here');
      define('LOGGED_IN_KEY',    'put your unique phrase here');
      define('NONCE_KEY',        'put your unique phrase here');
      define('AUTH_SALT',        'put your unique phrase here');
      define('SECURE_AUTH_SALT', 'put your unique phrase here');
      define('LOGGED_IN_SALT',   'put your unique phrase here');
      define('NONCE_SALT',       'put your unique phrase here');
      . . .

      Delete those lines and paste in the values you copied from the command line:


      . . .
      . . .

      Next, let’s modify some of the database connection settings at the beginning of the file. You’ll have to adjust the database name, the database user, and the associated password that was configured within MySQL.

      The other change you should make is to set the method that WordPress uses to write to the filesystem. Since you’ve given the web server permission to write where it needs to, you can explicitly set the filesystem method to “direct”. Failure to set this with our current settings would result in WordPress prompting for FTP credentials when we perform some actions. Add this setting below the database connection settings, or anywhere else in the file:


      . . .
      define( 'DB_NAME', 'wordpress' );
      /** MySQL database username */
      define( 'DB_USER', 'wordpressuser' );
      /** MySQL database password */
      define( 'DB_PASSWORD', 'password' );
      . . .
      define( 'FS_METHOD', 'direct' );

      Save and close the file when you’re done.

      Step 6 — Completing the Installation Through the Web Interface

      Now that the server configuration is complete, you can finish up the installation through WordPress’ web interface.

      In your web browser, navigate to your server’s domain name or public IP address:


      Select the language you would like to use:

      WordPress language selection

      Next, you will come to the main setup page.

      Select a name for your WordPress site and choose a username (it is recommended not to choose something like “admin” for security purposes). A strong password is generated automatically. Save this password or select an alternative strong password.

      Enter your email address and select whether you want to discourage search engines from indexing your site:

      WordPress setup installation

      When you click ahead, you will be taken to a page that prompts you to log in:

      WordPress login prompt

      Once you log in, you will be taken to the WordPress administration dashboard:

      WordPress login prompt


      WordPress should be installed and ready to use! Some common next steps are to choose the permalinks setting for your posts (can be found in Settings > Permalinks) or to select a new theme (in Appearance > Themes). If this is your first time using WordPress, explore the interface a bit to get acquainted with your new CMS.

      If you’re looking for a one-click solution to install a WordPress Droplet, learn more about the WordPress One-Click App.

      Source link

      Cara Menginstal WordPress di Ubuntu 20.04 dengan Tumpukan LAMP


      WordPress adalah teknologi sumber terbuka yang saat ini sangat populer untuk membuat situs web dan blog di internet. Digunakan oleh 63% dari seluruh situs web yang menggunakan sistem manajemen konten (CMS), situs WordPress mencakup 36% dari semua situs web yang kini online.

      Ada banyak pendekatan berbeda untuk memperoleh akses ke WordPress dan beberapa proses penyiapan itu lebih kompleks dari yang lain. Tutorial ini dimaksudkan bagi mereka yang ingin menginstal dan mengelola instans WordPress di server awan yang tidak diawasi melalui baris perintah. Meskipun membutuhkan langkah lebih banyak daripada instalasi WordPress siap-pakai, pendekatan ini memberikan kontrol lebih besar terhadap lingkungan WordPress kepada administrator.

      Jika Anda sedang berusaha mengakses instalasi WordPress siap-pakai, DigitalOcean Marketplace menyajikan aplikasi sekali-klik untuk memandu Anda melakukan instalasi WordPress saat menjalankan server.

      Tergantung kebutuhan dan tujuan, Anda mungkin merasa lebih cocok dengan opsi lain. Sebagai perangkat lunak sumber terbuka, WordPress bebas diunduh dan diinstal, tetapi agar tersedia di web, Anda mungkin perlu membeli infrastruktur awan dan nama domain. Ikuti terus panduan ini jika Anda tertarik mengerjakan instalasi di sisi server dan menyiapkan situs WordPress.

      Tutorial ini akan menggunakan tumpukan LAMP (Linux, Apache, MySQL, dan PHP), yang merupakan satu opsi bagi arsitektur server yang mendukung WordPress dengan menyediakan sistem operasi Linux, server web Apache, basis data MySQL, dan bahasa pemrograman PHP. Kita akan menginstal dan menyiapkan WordPress melalui LAMP di server Linux Ubuntu 20.04.


      Untuk menyelesaikan tutorial ini, Anda akan membutuhkan akses ke server Ubuntu 20.04 dan perlu menyelesaikan langkah-langkah berikut sebelum memulai panduan ini:

      • Siapkan server Anda dengan mengikuti panduan penyiapan awal server Ubuntu 20.04 dari kami, dan pastikan Anda memiliki pengguna sudo non-root.
      • Instal tumpukan LAMP dengan mengikuti panduan LAMP kami untuk menginstal dan mengonfigurasi perangkat lunak ini.
      • Amankan situs Anda: WordPress mengambil masukan pengguna dan menyimpan data pengguna, sehingga perlu memiliki lapisan keamanan. TLS/SSL adalah teknologi yang memungkinkan Anda mengenkripsi lalu lintas dari situs Anda sehingga koneksi Anda dan pengguna Anda aman. Berikut ini dua opsi yang tersedia untuk memenuhi persyaratan ini:
        • Jika memiliki nama domain… Anda dapat mengamankan situs dengan Let’s Encrypt, yang menyediakan sertifikat gratis dan tepercaya. Ikuti panduan Let’s Encrypt untuk Apache dari kami untuk menyiapkannya.
        • Jika tidak memiliki domain… dan Anda hanya menggunakan konfigurasi ini untuk pengujian atau penggunaan pribadi, Anda dapat menggunakan sertifikat yang ditandatangani sendiri sebagai gantinya. Sertifikat ini menyediakan tipe enkripsi yang sama, tetapi tanpa validasi domain. Untuk menyiapkan, ikuti panduan SSL yang ditandatangani sendiri untuk Apache dari kami.

      Bila telah menyelesaikan langkah-langkah penyiapan, masuk ke server Anda sebagai pengguna sudo dan lanjutkan di bawah ini.

      Langkah 1 — Membuat Basis Data dan Pengguna MySQL untuk WordPress

      Langkah pertama yang akan kita ambil merupakan persiapan. WordPress menggunakan MySQL untuk mengelola dan menyimpan informasi situs dan pengguna. Kita sudah menginstal MySQL, tetapi kita perlu membuat basis data dan pengguna yang akan digunakan oleh WordPress.

      Untuk memulai, log masuk ke akun root (administratif) MySQL dengan mengeluarkan perintah ini (ingat, ini bukan pengguna root di server Anda):

      Anda akan diminta memasukkan kata sandi yang Anda buat untuk akun root MySQL saat menginstal perangkat lunak itu.

      Catatan: Jika Anda tidak dapat mengakses basis data MySQL melalui root, Anda sebagai pengguna sudo dapat memperbarui kata sandi pengguna root dengan masuk ke basis data seperti ini:

      Setelah menerima prompt MySQL, Anda dapat memperbarui kata sandi pengguna root. Di sini, ganti new_password dengan kata sandi yang kuat pilihan Anda.

      • ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'new_password';

      Anda sekarang dapat mengetikkan EXIT; dan dapat log masuk kembali ke dalam basis data melalui kata sandi dengan perintah berikut:

      Di dalam basis data, kita dapat membuat basis data eksklusif yang akan dikontrol WordPress. Anda dapat menamainya sesuai keinginan, tetapi kami akan menggunakan nama wordpress dalam panduan ini. Buat basis data untuk WordPress dengan mengetikkan:

      • CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;

      Catatan: Setiap pernyataan MySQL harus diakhiri dengan titik koma (;). Periksa untuk memastikan keberadaannya jika Anda mengalami masalah.

      Selanjutnya, kita akan membuat akun pengguna MySQL terpisah yang akan digunakan secara eksklusif untuk mengoperasikan basis data kita yang baru. Membuat basis data dan akun spesifik dapat mendukung kita dari sudut pandang manajemen dan keamanan. Kita akan menggunakan nama wordpressuser di dalam panduan ini, tetapi silakan menggunakan nama apa pun yang relevan bagi Anda.

      Kita akan membuat akun ini, menentukan kata sandi, dan memberikan akses ke basis data yang kita telah buat. Kita dapat melakukannya dengan mengetikkan perintah berikut. Ingatlah memilih kata sandi yang kuat di sini bagi pengguna basis data Anda dengan password yang kita miliki:

      • CREATE USER 'wordpressuser'@'%' IDENTIFIED WITH mysql_native_password BY 'password';

      Selanjutnya, beri tahu basis data bahwa wordpressuser kita harus memiliki akses lengkap ke basis data yang kita siapkan:

      • GRANT ALL ON wordpress.* TO 'wordpressuser'@'%';

      Kini, Anda memiliki basis data dan akun pengguna, masing-masing dibuat khusus untuk WordPress. Kita perlu memberikan privilese agar instans MySQL saat ini mengetahui perubahan terbaru yang kita lakukan:

      Keluarlah dari MySQL dengan mengetikkan:

      Pada langkah selanjutnya, kita akan menambahkan beberapa fondasi untuk plugin WordPress dengan mengunduh ekstensi PHP bagi server kita.

      Langkah 2 — Menginstal Ekstensi Tambahan PHP

      Saat menyiapkan tumpukan LAMP, kita hanya membutuhkan sedikit ekstensi untuk membuat PHP berkomunikasi dengan MySQL. WordPress dan kebanyakan plugin-nya memanfaatkan ekstensi tambahan PHP.

      Kita dapat mengunduh dan menginstal beberapa ekstensi PHP paling populer yang digunakan bersama WordPress dengan mengetikkan:

      • sudo apt update
      • sudo apt install php-curl php-gd php-mbstring php-xml php-xmlrpc php-soap php-intl php-zip

      Ini akan menjadi dasar untuk menginstal plugin tambahan ke dalam situs WordPress kita.

      Catatan: Setiap plugin WordPress memiliki persyaratannya sendiri. Sebagian mungkin mengharuskan instalasi paket PHP tambahan. Periksa dokumentasi plugin Anda untuk mengetahui persyaratan PHP-nya. Jika ada, itu dapat diinstal dengan apt seperti diperagakan di atas.

      Kita perlu memulai ulang Apache untuk memuat ekstensi baru ini, tetapi kita akan melakukan konfigurasi lebih banyak pada Apache di bagian selanjutnya, sehingga Anda bisa menunggu sampai konfigurasi Apache selesai atau memulai ulang sekarang untuk menyelesaikan proses ekstensi PHP.

      • sudo systemctl restart apache2

      Langkah 3 — Menyesuaikan Konfigurasi Apache untuk Memungkinkan Pengesampingan dan Penulisan Ulang .htaccess

      Selanjutnya, kita akan membuat beberapa penyesuaian kecil pada konfigurasi Apache. Berdasarkan tutorial prasyarat, Anda harus memiliki berkas konfigurasi untuk situs Anda di direktori /etc/apache2/sites-available/.

      Dalam panduan ini, kita akan menggunakan /etc/apache2/sites-available/wordpress.conf sebagai contoh di sini, tetapi Anda harus mengganti jalur ke berkas konfigurasi bila diperlukan. Selain itu, kita akan menggunakan /var/www/wordpress sebagai direktori root instalasi WordPress. Anda harus menggunakan root web yang ditetapkan dalam konfigurasi Anda. Jika mengikuti tutorial LAMP dari kami, ini bisa berupa nama domain Anda sebagai pengganti wordpress dalam kedua instans ini.

      Catatan: Anda dapat menggunakan konfigurasi asali 000-default.conf (dengan /var/www/html sebagai root web Anda). Hal ini bisa digunakan jika Anda hanya akan melaksanakan hos satu situs web di server ini. Jika tidak, sebaiknya membagi konfigurasi yang diperlukan menjadi beberapa potongan logis, satu berkas per situs.

      Dengan mengidentifikasi jalur, kita dapat beralih menangani .htaccess agar Apache dapat menangani perubahan konfigurasi berdasarkan masing-masing direktori.

      Mengaktifkan Pengesampingan .htaccess

      Saat ini, penggunaan berkas .htaccess dinonaktifkan. WordPress dan banyak plugin WordPress menggunakan berkas-berkas ini secara luas untuk penyesuaian di dalam direktori pada perilaku server web.

      Buka berkas konfigurasi Apache untuk situs web Anda dengan editor teks seperti nano.

      • sudo nano /etc/apache2/sites-available/wordpress.conf

      Untuk mengizinkan berkas .htaccess, kita perlu menetapkan arahan AllowOverride di dalam blok Directory yang mengarah ke root dokumen kita. Tambahkan blok teks berikut di dalam blok VirtualHost berkas konfigurasi Anda, pastikan menggunakan direktori root web yang benar:


      <Directory /var/www/wordpress/>
          AllowOverride All

      Setelah Anda selesai, simpan dan tutup berkas. Di nano, Anda dapat melakukannya dengan menekan CTRL dan X bersamaan, lalu Y, lalu ENTER.

      Mengaktifkan Modul Penulisan Ulang

      Selanjutnya, kita dapat mengaktifkan mod_rewrite untuk memanfaatkan fitur permalink WordPress:

      Hal ini memungkinkan Anda memiliki permalink yang lebih mudah dipahami orang pada pos Anda, seperti dua contoh berikut ini:

      Perintah a2enmod memanggil skrip yang akan mengaktifkan modul yang ditetapkan dalam konfigurasi Apache.

      Mengaktifkan Perubahan

      Sebelum menerapkan perubahan yang kita buat, periksa untuk memastikan kita tidak membuat kesalahan sintaks apa pun dengan menjalankan tes berikut.

      • sudo apache2ctl configtest

      Anda mungkin menerima keluaran seperti berikut:


      AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using Set the 'ServerName' directive globally to suppress this message Syntax OK

      Jika Anda ingin menyembunyikan baris teratas, tambahkan saja arahan ServerName ke berkas konfigurasi utama (global) Apache di /etc/apache2/apache2.conf. ServerName bisa berupa domain atau alamat IP server Anda. Namun, ini hanya pesan dan tidak akan memengaruhi fungsi situs Anda. Asalkan keluarannya berisi Syntax OK, Anda siap melanjutkan.

      Mulai ulang Apache untuk menerapkan perubahan. Pastikan memulai ulang sekarang sekalipun Anda telah memulai ulang sebelumnya dalam tutorial ini.

      • sudo systemctl restart apache2

      Selanjutnya, kita akan mengunduh dan menyiapkan WordPress itu sendiri.

      Langkah 4 — Mengunduh WordPress

      Kini setelah perangkat lunak server dikonfigurasi, kita dapat mengunduh dan menyiapkan WordPress. Karena alasan keamanan tertentu, selalu disarankan untuk mendapatkan versi terbaru WordPress dari situsnya.

      Ubah menjadi direktori yang dapat ditulis (kami merekomendasikan direktori sementara seperti /tmp) dan unduh rilis yang dikompresi.

      • cd /tmp
      • curl -O

      Ekstrak berkas yang dikompresi untuk membuat struktur direktori WordPress:

      Kita akan memindahkan berkas-berkas ini ke root dokumen sebentar lagi. Sebelum melakukannya, kita dapat menambah berkas .htaccess semu agar nanti dapat digunakan WordPress.

      Buat berkas dengan mengetikkan:

      • touch /tmp/wordpress/.htaccess

      Kita juga akan menyalin berkas konfigurasi sampel ke nama berkas yang dibaca WordPress:

      • cp /tmp/wordpress/wp-config-sample.php /tmp/wordpress/wp-config.php

      Kita juga dapat membuat direktori upgrade, agar WordPress tidak mengalami masalah izin saat mencoba melakukannya sendiri setelah pembaruan pada perangkat lunaknya:

      • mkdir /tmp/wordpress/wp-content/upgrade

      Sekarang, kita dapat menyalin seluruh isi direktori ke dalam root dokumen. Kita menggunakan titik di akhir direktori sumber untuk menunjukkan bahwa semua yang ada di dalam direktori harus disalin, termasuk berkas tersembunyi (seperti berkas .htaccess yang kita buat):

      • sudo cp -a /tmp/wordpress/. /var/www/wordpress

      Pastikan Anda mengganti direktori /var/www/wordpress dengan direktori yang telah Anda siapkan di server.

      Langkah 5 — Mengonfigurasi Direktori WordPress

      Sebelum melakukan penyiapan WordPress berbasis web, kita perlu menyesuaikan beberapa item dalam direktori WordPress.

      Menyesuaikan Kepemilikan dan Izin

      Langkah penting yang perlu kita lakukan adalah menyiapkan izin dan kepemilikan berkas yang semestinya.

      Kita akan mulai dengan memberikan kepemilikan semua berkas ke pengguna dan grup www-data. Inilah pengguna yang berjalan di server web Apache, dan Apache perlu bisa membaca dan menulis berkas WordPress untuk menyajikan situs web dan melakukan pembaruan otomatis.

      Perbarui kepemilikan dengan perintah chown yang memungkinkan Anda memodifikasi kepemilikan berkas. Pastikan mengarahkan ke direktori yang relevan di server Anda.

      • sudo chown -R www-data:www-data /var/www/wordpress

      Selanjutnya, kita akan menjalankan dua perintah find untuk mengatur izin yang benar pada direktori dan berkas WordPress:

      • sudo find /var/www/wordpress/ -type d -exec chmod 750 {} ;
      • sudo find /var/www/wordpress/ -type f -exec chmod 640 {} ;

      Izin ini akan membuat Anda bekerja secara efektif dengan WordPress, tetapi ingatlah bahwa beberapa plugin dan prosedur mungkin membutuhkan penyesuaian tambahan.

      Menyiapkan Berkas Konfigurasi WordPress

      Sekarang, kita perlu membuat beberapa perubahan pada berkas konfigurasi utama WordPress.

      Ketika membuka berkas itu, tugas pertama kita adalah menyesuaikan beberapa kunci rahasia untuk memberikan suatu tingkat keamanan bagi instalasi kita. WordPress menyediakan generator yang aman untuk nilai-nilai ini sehingga Anda tidak perlu memikirkan nilai yang bagus. Ini hanya digunakan secara internal, sehingga menggunakan nilai-nilai yang kompleks dan aman di sini tidak akan mengurangi kegunaan.

      Untuk mengambil nilai-nilai yang aman dari generator kunci rahasia WordPress, ketikkan:

      • curl -s

      Anda akan mendapatkan kembali nilai-nilai unik yang menyerupai keluaran seperti blok di bawah ini.

      Peringatan! Anda perlu meminta nilai-nilai unik ini setiap kali. JANGAN menyalin nilai-nilai di bawah ini!


      define('AUTH_KEY', '1jl/vqfs<XhdXoAPz9 DO NOT COPY THESE VALUES c_j{iwqD^<+c9.k<J@4H'); define('SECURE_AUTH_KEY', 'E2N-h2]Dcvp+aS/p7X DO NOT COPY THESE VALUES {Ka(f;rv?Pxf})CgLi-3'); define('LOGGED_IN_KEY', 'W(50,{W^,OPB%PB<JF DO NOT COPY THESE VALUES 2;y&,2m%3]R6DUth[;88'); define('NONCE_KEY', 'll,4UC)7ua+8<!4VM+ DO NOT COPY THESE VALUES #`DXF+[$atzM7 o^-C7g'); define('AUTH_SALT', 'koMrurzOA+|L_lG}kf DO NOT COPY THESE VALUES 07VC*Lj*lD&?3w!BT#-'); define('SECURE_AUTH_SALT', 'p32*p,]z%LZ+pAu:VY DO NOT COPY THESE VALUES C-?y+K0DK_+F|0h{!_xY'); define('LOGGED_IN_SALT', 'i^/G2W7!-1H2OQ+t$3 DO NOT COPY THESE VALUES t6**bRVFSD[Hi])-qS`|'); define('NONCE_SALT', 'Q6]U:K?j4L%Z]}h^q7 DO NOT COPY THESE VALUES 1% ^qUswWgn+6&xqHN&%');

      Ini adalah baris konfigurasi yang dapat kita tempelkan langsung dalam berkas konfigurasi untuk mengatur kunci aman. Salin keluaran yang Anda terima sekarang.

      Selanjutnya, buka berkas konfigurasi WordPress:

      • sudo nano /var/www/wordpress/wp-config.php

      Temukan bagian yang berisi nilai-nilai contoh untuk pengaturan itu.


      . . .
      define('AUTH_KEY',         'put your unique phrase here');
      define('SECURE_AUTH_KEY',  'put your unique phrase here');
      define('LOGGED_IN_KEY',    'put your unique phrase here');
      define('NONCE_KEY',        'put your unique phrase here');
      define('AUTH_SALT',        'put your unique phrase here');
      define('SECURE_AUTH_SALT', 'put your unique phrase here');
      define('LOGGED_IN_SALT',   'put your unique phrase here');
      define('NONCE_SALT',       'put your unique phrase here');
      . . .

      Hapus baris-baris itu dan tempelkan dalam nilai-nilai yang Anda salin dari baris perintah:


      . . .
      . . .

      Selanjutnya, kita akan memodifikasi beberapa pengaturan koneksi basis data di awal berkas. Anda perlu menyesuaikan nama basis data, pengguna basis data, dan kata sandi yang terkait yang Anda konfigurasikan dalam MySQL.

      Perubahan lain yang perlu kita buat adalah mengatur metode yang harus digunakan WordPress untuk menulis sistem berkas. Karena kita telah memberi izin server web untuk menulis bila membutuhkan, kita dapat secara eksplisit mengatur metode sistem berkas ke “direct”. Tidak mengaturnya dengan pengaturan saat ini akan mengakibatkan WordPress meminta kredensial FTP saat kita melakukan beberapa tindakan.

      Pengaturan ini dapat ditambahkan di bawah pengaturan koneksi basis data, atau di tempat lain dalam berkas:


      . . .
      // ** MySQL settings - You can get this info from your web host ** //
      /** The name of the database for WordPress */
      define( 'DB_NAME', 'wordpress' );
      /** MySQL database username */
      define( 'DB_USER', 'wordpressuser' );
      /** MySQL database password */
      define( 'DB_PASSWORD', 'password' );
      /** MySQL hostname */
      define( 'DB_HOST', 'localhost' );
      /** Database Charset to use in creating database tables. */
      define( 'DB_CHARSET', 'utf8' );
      /** The Database Collate type. Don't change this if in doubt. */
      define( 'DB_COLLATE', '' );
      . . .
      define('FS_METHOD', 'direct');

      Simpan dan tutup berkas saat Anda sudah selesai.

      Langkah 6 — Menyelesaikan Instalasi Melalui Antarmuka Web

      Karena konfigurasi server selesai, kita dapat menyelesaikan instalasi melalui antarmuka web.

      Dalam browser web Anda, navigasikan ke nama domain server atau alamat IP publik server Anda:


      Pilih bahasa yang ingin Anda gunakan:

      Pemilihan bahasa WordPress

      Selanjutnya, Anda akan masuk ke halaman penyiapan utama.

      Pilih nama untuk situs WordPress Anda dan pilih nama pengguna. Disarankan memilih nama yang unik dan hindari nama pengguna yang umum seperti “admin” untuk keperluan keamanan. Kata sandi yang kuat dibuat secara otomatis. Simpan kata sandi ini atau pilih alternatif kata sandi yang kuat.

      Masukkan alamat surel Anda dan pilih apakah ingin mencegah mesin pencari mengindeks situs Anda:

      Instalasi penyiapan WordPress

      Bila telah mengklik, Anda akan dibawa ke laman yang meminta Anda untuk log masuk:

      Prompt log masuk WordPress

      Setelah log masuk, Anda akan dibawa ke dasbor administrasi WordPress:

      Prompt log masuk WordPress

      Saat ini, Anda dapat mulai mendesain situs web WordPress! Jika ini adalah kali pertama Anda menggunakan WordPress, jelajahi sedikit antarmukanya untuk mengenal CMS Anda yang baru.


      Selamat, WordPress sekarang telah diinstal dan siap digunakan!

      Saat ini, Anda mungkin perlu melakukan hal berikut:

      • Pilih pengaturan permalink untuk pos WordPress, yang dapat ditemukan di Settings > Permalink.
      • Pilih tema baru di Appearance > Themes.
      • Instal plugin baru untuk menambah fungsionalitas situs Anda di Plugins > Add New.
      • Jika akan bekerja sama dengan orang lain, Anda mungkin perlu juga menambahkan pengguna tambahan saat ini di Users > Add New.

      Anda dapat menemukan sumber daya tambahan untuk cara alternatif menginstal WordPress, mempelajari cara menginstal WordPress pada distribusi server lain, mengotomatiskan instalasi WordPress, dan menskalakan situs WordPress dengan memeriksa tag Komunitas WordPress dari kami.

      Source link

      How To Automate WordPress Deployments with DigitalOcean and Buddy


      In this tutorial, you will automate WordPress deployments using Buddy CI/CD, a user-friendly tool offering continuous integration and continuous deployment solutions.

      Compared to many other CI/CD tools, Buddy requires less DevOps experience. It allows developers to create delivery pipelines with drag-and-drop actions in a visual GUI. This GUI leverages pre-configured actions (builds, test, deployments, etc.) in an approach similar to DigitalOcean’s interactive Droplet configuration. This means newcomers and expert developers alike can use Buddy to release more software, all while making fewer errors.

      Once you’ve completed this tutorial, you will be able to perform a WordPress deployment with a single command from your local terminal. For better insight, you will build a more advanced Sage-based WordPress theme that requires multiple build steps before you can deploy it to the WordPress server.


      Note: This tutorial was tested on Node.js version 14.13.0, npm version 6.14.8, and PHP version 7.4.10.

      Step 1 — Installing WordPress with Docker

      In this step you will pull the WordPress image from Docker and start your build.

      First, verify that Docker is running with the following command:

      You will receive an output like this:


      Client: Debug Mode: false Server: Containers: 0 Running: 0 Paused: 0 Stopped: 0 Images: 0 Server Version: 19.03.12 Storage Driver: overlay2 Backing Filesystem: extfs Supports d_type: true Native Overlay Diff: true Logging Driver: json-file Cgroup Driver: cgroupfs Plugins: Volume: local Network: bridge host ipvlan macvlan null overlay Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog Swarm: inactive ...

      Now that you’ve verified that Docker is running, download the latest version of the WordPress image:

      Next, create a folder for your project in your workspace:

      • mkdir docker-wordpress-theme

      Navigate inside your new project folder:

      • cd docker-wordpress-theme

      Now you need to define your build. Use nano or your preferred text editor to open and create a file called docker-compose.yml:

      Add the following definitions to the file. These describe the version of Docker Compose and the services to be launched. In this case, you are launching WordPress and MySQL database. Make sure to replace the highlighted fields with your credentials:


      version: "3.1"
          image: wordpress
          restart: always
            - 8080:80
            WORDPRESS_DB_HOST: db
            WORDPRESS_DB_USER: exampleuser
            WORDPRESS_DB_PASSWORD: examplepass
            WORDPRESS_DB_NAME: exampledb
            - wordpress:/var/www/html
            - ./sage:/var/www/html/wp-content/themes/sage/
          image: mysql:5.7
          restart: always
            MYSQL_DATABASE: exampledb
            MYSQL_USER: exampleuser
            MYSQL_PASSWORD: examplepass
            - db:/var/lib/mysql

      Here you are defining the images that Docker will launch in the service and then setting ports and environment variables

      Take note that you are mounting a folder called sage that you haven’t created yet. This will be your custom theme, which you will now create.

      Step 2 — Creating a Custom WordPress Theme

      In this step you will create a custom wordpress theme. You will then create a CI/CD pipeline so that you can push changes you make locally to your WordPress server with one command.

      Let’s start building our custom theme by installing the Sage framework on our local WordPress installation. This theme uses Node.js and Gulp to perform development and build functions. There won’t be any build dependencies installed on the production server – instead, all production build tasks will be performed on Buddy, the remote Continuous Integration server.

      Make sure you are in your project folder:

      • cd docker-wordpress-theme

      Use Composer to create a new Sage theme:

      • composer create-project roots/sage

      With everything properly configured, the following output will appear:


      Installing roots/sage (9.0.9) - Installing roots/sage (9.0.9): Loading from cache Created project in /home/mike/Projects/buddy/github/sage Loading composer repositories with package information Installing dependencies (including require-dev) from lock file Package operations: 29 installs, 0 updates, 0 removals - Installing composer/installers (v1.6.0): Downloading (100%) - Installing symfony/polyfill-mbstring (v1.10.0): Downloading (100%) - Installing symfony/contracts (v1.0.2): Downloading (100%) - ..........

      The installer will then ask you to select the framework to load:


      - Theme Name > Sage Starter Theme - Theme URI > - Theme Name [Sage Starter Theme]: - Theme Description > Sage is a WordPress starter theme. - Theme Version > 9.0.9 - Theme Author > Roots - Theme Author URI > - Local development URL of WP site > http://localhost:8080 - Path to theme directory > /wp-content/themes/sage - Which framework would you like to load? [Bootstrap]: [0] None [1] Bootstrap [2] Bulma [3] Foundation [4] Tachyons [5] Tailwind

      Note: Make sure sure that the local development URL matches the port.

      Press 1 to select the Bootstrap framework. You will be asked for permission to overwrite a couple of files. Type y to confirm and proceed:


      Are you sure you want to overwrite the following files? - scripts/autoload/_bootstrap.js - styles/autoload/_bootstrap.scss - styles/common/_variables.scss - styles/components/_comments.scss - styles/components/_forms.scss - styles/components/_wp-classes.scss - styles/layouts/_header.scss (yes/no) [no]:

      You now have the foundations of a custom WordPress theme. In the next step you will build and launch the theme, and then you will version it using Git.

      Step 3 — Building and Launching a Custom WordPress Theme

      In this step you will install all your build dependencies, create a production build, and lauch WordPress in a local Docker container.

      Navigate to the Sage folder:

      Install the node-sass binary to prevent installation failure (the rest of package.json will be installed, too):

      Run a production build that will compile all Sass/SCSS files and minify CSS and JS:

      With the build generated, exit the theme folder and launch your WordPress instance using Docker Compose:

      • cd ..
      • docker-compose up -d

      Launching WordPress in the Docker environment should only take a few seconds. Now open the URL http://localhost:8080 in a web browser to access your local WordPress site. Since this is the first time you are launching WordPress, you will be prompted to create an Admin account. Create one now.

      Once you have created an account and are logged in, head over to Appearance > Themes page on the dashboard. You will find several pre-installed themes including the Sage theme we’ve just created. Click the Activate button to set it as the current theme. Your home page will look something like this:

      Sage theme preview

      You have now built and activated a custom theme. In the next step, you will put your project under version control.

      Step 4 — Uploading a WordPress Project to a Remote Repository

      Version control is a cornerstone of the CI/CD workflow. In this step, you will upload your project to a remote Git repository that the Buddy platform can access. Buddy integrates with many popular Git providers, including:

      • GitHub
      • GitLab
      • Bitbucket
      • Privately-hosted Git repositories

      Create a remote repository on the platform of your choice. For the purpose of this guide we’ll use GitHub. Click here to read how you can create a new repo using the Github UI.

      Then, in your terminal, initialize Git in your project’s remote directory:

      Add the newly created remote repository. Replace the highlighted section with your own repository’s URL:

      git add remote

      Before you push your project, there are some files that you want to exclude from version control.

      Create a file called .gitignore:

      Add the following filenames:



      Save and close the file.

      Now you are ready to add your project under version control and commit the files to your repository on GitHub:

      • git add .
      • git commit -m 'my sage project'
      • git push

      You have now built a custom WordPress theme using the Sage framework and then pushed the code to a remote repository. Now you will automate the deployment of this theme to your WordPress server using Buddy.

      Step 5 — Automating WordPress Deployment with Buddy

      If you haven’t used Buddy before, sign up with your Git provider credentials or email address. There’s a 14-day trial with no limit on resources, and a free plan with 5 projects and 120 executions/month once it’s over, which is more than enough for our needs.

      Start by synchronizing Buddy with your repository. In the Buddy UI, click Create a new project, select your Git provider, and choose the repository that you created in the first section of this article.

      Next, you will be prompted to create your delivery pipeline. A pipeline is a set of actions that perform tasks on your repository code, like builds, tests, or deployments.

      The key settings to configure are:

      • Branch from which Buddy will deploy your code – in this case, set it to master
      • Pipeline trigger mode – set it to On push to automatically execute the pipeline on every push to the selected branch.

      Once you add the pipeline, you’ll need to create four actions:

      1. A PHP action that will install the required PHP packages
      2. A Node action that will download the dependencies and prepare a build for deployment
      3. A Droplet action that will upload the build code directly to your DO Droplet
      4. An SSH action with a script that will activate your theme.

      Based on the contents of your repository, Buddy will automatically suggest the actions to perform. Select PHP from the list.

      Action selection screen

      Clicking the action will open its configuration panel. Enter the following commands in the terminal section:

      # navigate to theme directory
      cd sage
      # install php packages
      composer validate
      composer install

      Save and run the pipeline to ensure it works:

      Pipeline execution

      Note: Buddy uses isolated containers with preinstalled frameworks for builds. The downloaded dependencies are cached in the container, meaning you don’t have to download them again. Think of it as a local development environment that remains consistent for everybody on the team.

      Next, add the Node.js action. In order for the theme to display properly, we’ll need to compile and minify assets, i.e. SCSS/SASS and JavaScript files.

      First, set Environment to node latest.

      Now you must add several commands. These commands will install the necessary dependencies and perform your build.

      Add them to the terminal box just like before:

      # navigate to theme directory
      cd sage
      # install packages
      yarn install
      # Create production build
      yarn build:production

      Once again, save and run the action to ensure it works.

      Next, add the Droplet action right after the Node.js build. If you’ve never used DigitalOcean with Buddy before, a wizard will appear that will guide you through the integration. Once you’ve completed this step, define the authentication details as follows:

      • Set the Source path to sage.

      • Choose Buddy’s SSH key authentication mode as that is the easiest one to set up. Just log in to your Droplet server via SSH and execute the commands displayed in Buddy’s key code snippet.

      After you execute those commands, go back to the browser and click the Remote path browse button – you will be able to navigate your Droplet’s filesystem and access the correct deployment folder. The default path will be /var/www/html/wp-content/themes/sage.

      You will also need to visit the Ignore paths section and provide the following to prevent uploading of Node.js dependencies:


      When done, click the Test action button to verify that everything’s been properly configured.

      Last, you’ll add one more action to activate your theme on the WordPress Droplet with a WP-CLI command. On your pipeline page, add the SSH action and input the following command in the commands section:

      • sudo -u www-data -- wp theme activate sage/resources

      Ensure you have set the correct Working directory setting – otherwise, the command won’t work.

      Since you already configured Buddy’s SSH key in the previous setup, you don’t need to do anything else. Alternatively, you can select private SSH key and then you can upload your DigitalOcean private key and use that to connect to your Droplet. Buddy’s SSH key is simpler and just as secure.

      Your complete pipeline will now contain 4 actions: PHP > Node > Droplet > SSH. Click the Run Pipeline button to test out all the actions at once. You will receive a green check mark for each stage:

      Pipeline execution screen

      On the first execution, Buddy will deploy all files from the repository to the selected revision. Future deployments will only update files that have changed or were deleted. This feature significantly reduces upload time because you don’t have to deploy everything from scratch on every update.

      Go to your hosted WordPress dashboard and refresh the Themes page. You will see your Sage theme. Activate it now.

      Your hosted home page will now match your local home page.

      Our pipeline is built and our local and remote machines are synced. Now, let’s test the entire workflow.

      Step 6 — Testing Buddy’s Auto-Deployment Workflow

      In this step you will make a small change to your theme and then deploy those changes to your WordPress server.

      Go back to your local terminal and run this yarn command:

      This will start a live proxy development server at localhost:3000. Any changes you make to your theme will get automatically reflected in this window. The page on localhost:8080 will remain unchanged until you run the production build script.

      Let’s test out our pipeline by making some minor changes to our CSS.

      Open the main.scss file for your Sage theme:

      • nano ./sage/resources/assets/styles/main.scss

      Insert the following code to introduce some subtle green color and an underline to the website’s font:


      .brand {
        @extend .display-3;
        color: #013d30;
      .entry-title {
        @extend .display-4;
        a {
          color: #015c48;
          text-decoration: underline;
      .page-header {
        display: none;

      Save and close the file.

      Commit these changes and upload them to your repo:

      • git add .
      • git commit -m "minor style changes"
      • git push

      Once the code is uploaded to the repository, Buddy will automatically trigger your pipeline and execute all actions one by one:

      Wait for the pipeline to finish and then refresh your WordPress Droplet’s home page to see your updates.

      Updated WP Droplet

      Your pipeline is now pushing changes from your local machine to GitHub to Buddy to your production WordPress server, all triggered by one git command.


      Buddy is a very user friendly and powerful CI/CD tool. Buddy even has a video that shows just how quickly you can create pipelines using their interface.

      By automating your development workflow, you can focus on implementing styles and features for your custom theme or plugin without wasting time on manual deployments. The CI/CD workflow can also significantly reduce the risk of manual errors. In addition, automation allows you to further enhance the quality of your code by running unit tests and analysis tools, such as PHP Sniffer, on every change.

      You can take this tutorial even further by setting up an advanced branching strategy and a staging server, where you can perform quality control checks before you deploy new code to the production server. This way you can release better software more often without losing the momentum.

      Source link