ITGeeksHub

Web hosting on Linux server using WordPress

Leveraging a Linux server for website hosting enables creativity and diverse revenue opportunities. The guide outlines steps to create and host a WordPress site, starting from updating the server, installing necessary packages, and setting up MySQL. Finally, it details WordPress installation and configuration for successful deployment.

“By leveraging the robust power and flexibility of a Linux server to host your website, you open the door not only to limitless creativity but also to diverse revenue streams, turning your passion into profit.”

Create and Host Your First Website on Linux with WordPress

How to Create and Host Your First Website on a Linux Server Using WordPress

Step 1: Update Your Server

Open the terminal and run the following command to ensure your server is up to date:

sudo apt update && sudo apt upgrade

Step 2: Install Required Packages

Install Apache, MySQL, and PHP:

sudo apt install apache2 mysql-server php libapache2-mod-php php-mysql

Step 3: Start and Enable Apache and MySQL

Start and enable the services to run on startup:

sudo systemctl start apache2
sudo systemctl enable apache2
sudo systemctl start mysql
sudo systemctl enable mysql

Step 4: Secure MySQL Installation

Run the MySQL security script:

sudo mysql_secure_installation

Follow the prompts to set up your MySQL installation securely.

Step 5: Create a MySQL Database for WordPress

Log into MySQL:

sudo mysql -u root -p

Then run the following commands to create a database and user:

CREATE DATABASE wordpress;
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Step 6: Install WordPress

Change to the Apache root directory:

cd /var/www/html

Download WordPress:

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

Extract WordPress files:

tar xzf latest.tar.gz

Move the extracted files to the root directory:

sudo mv wordpress/* .
sudo rm -rf wordpress latest.tar.gz

Step 7: Configure WordPress

Copy the sample configuration file:

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

Edit the configuration file:

sudo nano wp-config.php

Update the database name, user, and password:

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

Step 8: Set Directory Permissions

Set the appropriate permissions:

sudo chown -R www-data:www-data /var/www/html
sudo chmod -R 755 /var/www/html

Step 9: Configure Apache for WordPress

Create a new Apache configuration file:

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

Add the following configuration:

<VirtualHost *:80>
    ServerAdmin admin@example.com
    DocumentRoot /var/www/html
    ServerName example.com
    ServerAlias www.example.com

    <Directory /var/www/html>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Enable the new site and the rewrite module:

sudo a2ensite wordpress
sudo a2enmod rewrite
sudo systemctl restart apache2

Step 10: Complete Installation from the Web Interface

Now, open your web browser and go to http://your_server_ip or your domain name. Follow the on-screen instructions to finish the WordPress installation.

Learn More

To deepen your Linux knowledge, consider enrolling in the following course:

Leave a Reply