, , ,

How to install WordPress using command prompt in Linux

Posted by

To install WordPress using the command prompt in Linux, you can follow these steps:

  1. Open a terminal: Press Ctrl+Alt+T to open a terminal window.
  2. Update package lists: Run the following command to update the package lists on your system:
   sudo apt update
  1. Install LAMP stack: WordPress requires a web server, a database, and PHP. You can install the LAMP stack (Linux, Apache, MySQL/MariaDB, PHP) using the following command:
   sudo apt install apache2 mysql-server php libapache2-mod-php php-mysql

During the installation process, you’ll be prompted to set a password for the MySQL root user. Make sure to remember this password as you’ll need it later.

  1. Configure MySQL/MariaDB: After the installation is complete, run the following command to secure your MySQL/MariaDB installation:
   sudo mysql_secure_installation

This command will guide you through a series of steps to configure the security settings. You can choose the default options or customize them based on your requirements.

  1. Create a MySQL database and user: Log in to the MySQL shell by running the following command and entering the MySQL root password you set earlier:
   sudo mysql -u root -p

Once logged in, create a new database for WordPress:

   CREATE DATABASE wordpress;

Create a new MySQL user and grant privileges to the WordPress database:

   GRANT ALL ON wordpress.* TO 'wordpressuser'@'localhost' IDENTIFIED BY 'password';

Remember to replace ‘wordpressuser’ with your desired username and ‘password’ with a strong password.

Flush the privileges to update the changes:

   FLUSH PRIVILEGES;

Exit the MySQL shell:

   EXIT;
  1. Download WordPress: Change to the Apache web server document root directory:
   cd /var/www/html

Download the latest version of WordPress using wget:

   sudo wget https://wordpress.org/latest.tar.gz

Extract the downloaded archive:

   sudo tar -xvzf latest.tar.gz
  1. Configure WordPress: Move into the WordPress directory:
   cd wordpress

Copy the sample configuration file to the actual configuration file:

   sudo cp wp-config-sample.php wp-config.php

Open the configuration file in a text editor:

   sudo nano wp-config.php

Update the following lines with your MySQL/MariaDB database details:

   define('DB_NAME', 'wordpress');
   define('DB_USER', 'wordpressuser');
   define('DB_PASSWORD', 'password');

Save and close the file.

  1. Set file permissions: Set the correct ownership and permissions for WordPress files:
   sudo chown -R www-data:www-data /var/www/html/wordpress
   sudo chmod -R 755 /var/www/html/wordpress
  1. Restart Apache: Restart the Apache web server to apply the changes:
   sudo service apache2 restart
  1. Access WordPress installation: Open a web browser and navigate to http://your_server_IP_address/wordpress. Replace your_server_IP_address with the actual IP address or domain name of your server. Follow the WordPress installation wizard to complete the installation. Provide the requested information such as site title, username, password, and email.

That’s it! You have now installed WordPress using the Command Prompt.