Linux Apache MySQL Setup Guide: No XAMPP Needed

January 14, 2025
No Comments
9 min read

To set up and smoothly use Apache2 and MySQL on Linux without XAMPP, follow these steps:


1. Install Apache2

  • Update the package list:
Bash
sudo apt update
  • Install Apache2:
Bash
sudo apt install apache2 -y
  • Enable and start Apache2:
Bash
sudo systemctl enable apache2 
sudo systemctl start apache2

Verify Apache2 installation: Open a browser and visit http://localhost. You should see the Apache2 default page.


2. Install MySQL

1. Install MySQL server:

Bash
sudo apt install mysql-server -y

2. Secure MySQL installation:

Bash
sudo mysql_secure_installation

Follow the prompts to set up a root password and secure the installation.

3. Verify MySQL installation:

Bash
sudo systemctl status mysql

Ensure it’s active and running.


3. Install PHP

1. Install PHP and required extensions:

Bash
sudo apt install php libapache2-mod-php php-mysql php-cli php-curl php-gd php-xml -y

2. Test PHP integration with Apache:

  • Create a PHP file in /var/www/html/:
Bash
sudo nano /var/www/html/info.php
  • Add the following code:
Bash
<?php 
phpinfo(); 
?>
  • Save and close the file, then visit http://localhost/info.php in a browser.

4. Configure Apache for Your Projects

1. Set up a Virtual Host for WordPress or Laravel:

  • Create a configuration file:
Bash
sudo nano /etc/apache2/sites-available/your_project.conf

Add the following:

Bash
<VirtualHost *:80>
    ServerName your_project.local
    DocumentRoot /path/to/your/project/public
    <Directory /path/to/your/project/public>
        AllowOverride All
        Require all granted
    </Directory>
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

2. Enable the site and restart Apache:

Bash
sudo a2ensite your_project.conf 
sudo systemctl restart apache2

3. Edit /etc/hosts to map your domain:

Bash
sudo nano /etc/hosts Add: 127.0.0.1 your_project.local

5. Start Working on WordPress or Laravel

  • For WordPress:
    • Download WordPress, place it in your project directory, and follow the installation process via the browser.
  • For Laravel:
    • Ensure Composer is installed:
Bash
sudo apt install composer
  • Create a new Laravel project:
Bash
composer create-project --prefer-dist laravel/laravel your_project

6. Optional: Install phpMyAdmin for Database Management

1. Install phpMyAdmin:

Bash
 sudo apt install phpmyadmin

2. Integrate phpMyAdmin with Apache:

Bash
sudo ln -s /usr/share/phpmyadmin /var/www/html

3. Access phpMyAdmin: Visit http://localhost/phpmyadmin in your browser.


7. Common Commands for Maintenance

  • Restart Apache:
Bash
sudo systemctl restart apache2
  • Restart MySQL:
Bash
sudo systemctl restart mysql
  • Check Apache logs:
Bash
tail -f /var/log/apache2/error.log

To manage multiple WordPress (or other) projects on Apache2, you should organize your files and configure Apache to serve each project separately. Here's a step-by-step guide:


1. Directory Structure for Projects

Create a dedicated folder for your projects under /var/www/. For example:

Bash
sudo mkdir -p /var/www/project1
sudo mkdir -p /var/www/project2
sudo mkdir -p /var/www/project3

You can name the folders as per your project names.


2. Place WordPress Files

Download and extract WordPress into each project folder:

Bash
cd /tmp
wget https://wordpress.org/latest.tar.gz
tar -xvf latest.tar.gz

Copy WordPress files to each project directory:

Bash
sudo cp -r wordpress/* /var/www/project1/
sudo cp -r wordpress/* /var/www/project2/
sudo cp -r wordpress/* /var/www/project3/

3. Set Correct Permissions

Set the correct ownership and permissions for your project directories:

Bash
sudo chown -R www-data:www-data /var/www/project1
sudo chown -R www-data:www-data /var/www/project2
sudo chown -R www-data:www-data /var/www/project3

sudo chmod -R 755 /var/www/

4. Configure Virtual Hosts

Create a separate Virtual Host configuration file for each project. For example:

Project 1:

Bash
sudo nano /etc/apache2/sites-available/project1.conf

Add the following content:

Bash
<VirtualHost *:80>
    ServerName project1.local
    DocumentRoot /var/www/project1
    <Directory /var/www/project1>
        AllowOverride All
        Require all granted
    </Directory>
    ErrorLog ${APACHE_LOG_DIR}/project1_error.log
    CustomLog ${APACHE_LOG_DIR}/project1_access.log combined
</VirtualHost>

Project 2:

Bash
sudo nano /etc/apache2/sites-available/project2.conf

Add similar content, changing the ServerName and DocumentRoot:

Bash
<VirtualHost *:80>
    ServerName project2.local
    DocumentRoot /var/www/project2
    <Directory /var/www/project2>
        AllowOverride All
        Require all granted
    </Directory>
    ErrorLog ${APACHE_LOG_DIR}/project2_error.log
    CustomLog ${APACHE_LOG_DIR}/project2_access.log combined
</VirtualHost>

Repeat for Project 3, etc.


5. Enable Virtual Hosts

Enable each configuration using a2ensite:

Bash
sudo a2ensite project1.conf
sudo a2ensite project2.conf
sudo a2ensite project3.conf

Reload Apache to apply changes:

Bash
sudo systemctl reload apache2

6. Update /etc/hosts for Local Domains

Edit the hosts file to map your project domains to localhost:

Bash
sudo nano /etc/hosts

Add the following lines:

Bash
127.0.0.1 project1.local
127.0.0.1 project2.local
127.0.0.1 project3.local

7. Access Your Projects

  • Open a browser and navigate to:
    • http://project1.local for Project 1
    • http://project2.local for Project 2
    • http://project3.local for Project 3

1. Install phpMyAdmin

If phpMyAdmin is not installed, follow these steps to install it:

Bash
sudo apt update
sudo apt install phpmyadmin -y

During the installation, you'll be prompted to choose a web server. Select Apache2 using the spacebar and press Enter.


2. Enable phpMyAdmin Configuration

After installation, ensure that phpMyAdmin is properly linked to Apache:

  • Create a symbolic link:
Bash
sudo ln -s /usr/share/phpmyadmin /var/www/html/phpmyadmin
  • Restart Apache:
Bash
sudo systemctl restart apache2

3. Verify phpMyAdmin Setup

Visit http://localhost/phpmyadmin in your browser. You should see the phpMyAdmin login page

Here’s how to create a new MySQL user, set a password, and grant database access:


1. Log in to MySQL

Open your terminal and log in to MySQL as the root user:

Bash
sudo mysql

2. Create a New User

To create a new user, run the following SQL command:

Bash
CREATE USER 'new_user'@'localhost' IDENTIFIED BY 'user_password';
  • Replace new_user with the desired username.
  • Replace user_password with a strong password.

3. Grant Database Access to the User

a. Grant Access to a Specific Database

If you want the user to have access to a specific database (e.g., example_db):

Bash
GRANT ALL PRIVILEGES ON example_db.* TO 'new_user'@'localhost';

This gives the user full access (SELECT, INSERT, UPDATE, DELETE, etc.) to the example_db database.

b. Grant Access to All Databases (Optional)

If you want the user to have access to all databases:

Bash
GRANT ALL PRIVILEGES ON *.* TO 'new_user'@'localhost' WITH GRANT OPTION;

4. Apply the Changes

Make sure to reload the privileges to apply the changes:

Bash
FLUSH PRIVILEGES;

5. Exit MySQL

Once done, exit the MySQL prompt:

Bash
EXIT;

6. Verify the New User

You can test the new user by logging in:

Bash
mysql -u new_user -p

Enter the password you set (user_password) when prompted. If successful, the new user is ready to use.

To check and change the password policy in MySQL, follow these steps:


1. Log in to MySQL

Open a terminal and log in as the root user:

Bash
sudo mysql

2. Check the Current Password Policy

Run the following query to check the current password policy settings:

Bash
SHOW VARIABLES LIKE 'validate_password%';

This will display several settings, including:

  • validate_password.policy
  • validate_password.length
  • validate_password.mixed_case_count
  • validate_password.number_count
  • validate_password.special_char_count

3. Understand the Password Policy Levels

The validate_password.policy variable controls the strength of the password. It has three levels:

  • LOW: Only checks the length of the password.
  • MEDIUM (default): Enforces length, mixed-case, numeric, and special characters.
  • STRONG: Requires everything in MEDIUM plus checks dictionary words.

4. Change the Password Policy

You can adjust the policy and other requirements:

a. Set the Password Policy Level

To set a specific policy level:

Bash
SET GLOBAL validate_password.policy = 'LOW';  -- Change to LOW, MEDIUM, or STRONG

b. Set Minimum Password Length

To change the minimum password length (default is 8):

Bash
SET GLOBAL validate_password.length = 12;  -- Change to your desired length

c. Set Minimum Number of Required Characters

  • Mixed-case characters:
Bash
SET GLOBAL validate_password.mixed_case_count = 1; -- Require at least 1 uppercase and 1 lowercase
  • Numbers:
Bash
SET GLOBAL validate_password.number_count = 1; -- Require at least 1 number
  • Special characters:
Bash
SET GLOBAL validate_password.special_char_count = 1; -- Require at least 1 special character

5. Verify the Changes

Run this query again to confirm the new settings:

Bash
SHOW VARIABLES LIKE 'validate_password%';

6. Make the Changes Permanent

To ensure these settings persist after a server restart, edit the MySQL configuration file:

Bash
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf

Add the following lines under the [mysqld] section:

Bash
validate_password.policy=MEDIUM
validate_password.length=12
validate_password.mixed_case_count=1
validate_password.number_count=1
validate_password.special_char_count=1

Save and close the file, then restart MySQL:

Bash
sudo systemctl restart mysql

The error ERROR 1524 (HY000): Plugin 'auth_plugin' is not loaded indicates that the specified authentication plugin (auth_plugin) is not enabled or installed in your MySQL server.

Solution

  1. Check available authentication plugins
    To list the available authentication plugins, run this query in MySQL:
Bash
SELECT * FROM information_schema.plugins WHERE plugin_type = 'AUTHENTICATION';

This will show you the plugins available on your MySQL server, such as mysql_native_password, caching_sha2_password, etc.

2. Use a valid authentication plugin
Choose an appropriate plugin from the list and update your command. For example:

  • If mysql_native_password is available:
Bash
CREATE USER 'admin'@'localhost' IDENTIFIED WITH 'mysql_native_password' BY 'root123';
  • If caching_sha2_password is available:
Bash
CREATE USER 'admin'@'localhost' IDENTIFIED WITH 'caching_sha2_password' BY 'root123';

3. Ensure the plugin is loaded
If the required plugin is not loaded, you may need to configure it in your MySQL configuration file (my.cnf or my.ini) and restart the MySQL server.

Add the following under the [mysqld] section:

Bash
plugin-load-add=auth_plugin_name.so

Replace auth_plugin_name with the desired plugin, such as mysql_native_password.

4. Restart MySQL
After making changes to the configuration file, restart the MySQL server:

Bash
sudo systemctl restart mysql
©2025 Linux Bangla | Developed & Maintaind by Linux Bangla.