# Install a Local Web Server Stack

1- Apache (Web Server)
  ```
  sudo apt update
  sudo apt install apache2
  ```

  Check it works:
  ```
  http://localhost
  ```

2- MariaDB (Database)
  ```
  sudo apt install mariadb-server
  ```

  Secure it:
  ```
  sudo mariadb-secure-installation
  ```

3- PHP + Required Extensions
  ```
  sudo apt install php libapache2-mod-php php-mysql php-cli php-curl php-gd php-mbstring php-xml php-zip php-intl
  ```

  Restart Apache:
  ```
  sudo systemctl restart apache2
  ```


# Install WordPress
1- Go to Apache web root:
  ```
  cd /var/www/html
  ```

2- Download WordPress:
  ```
  sudo wget https://wordpress.org/latest.tar.gz
  sudo tar -xzf latest.tar.gz
  ```

3- Fix permissions:
  ```
  sudo chown -R www-data:www-data wordpress;
  sudo find wordpress -type d -exec chmod 755 {} \;
  sudo find wordpress -type f -exec chmod 644 {} \;
  ```

4- Now open:
  ```
  http://localhost/wordpress
  ```


# Create a Database
1- Login to MariaDB:
  ```
  sudo mysql -u root -p
  ```

2- Inside MySQL:
  ```
  CREATE DATABASE wordpress;
  EXIT;
  ```

3- If you wanna use credentials in the WordPress ther than root (optional).
  ```
  CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'password';
  GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';
  FLUSH PRIVILEGES;
  EXIT;
  ```


# Make Apache accept big file uploads

1- Increase PHP Upload Limits
  Edit your php.ini file.
    * Find it:
    ```
    php --ini
    ```

    * Edit it:
    ```
    sudo nano /etc/php/8.x/apache2/php.ini
    ```

    * Increase these values:
    ```
    upload_max_filesize = 256M
    post_max_size = 256M
    memory_limit = 512M
    max_execution_time = 300
    max_input_time = 300
    ```

  Restart Apache:
  ```
  sudo systemctl restart apache2
  ```

  you can also try using WordPress
    * Inside wp-config.php:
    ```
    define('WP_MEMORY_LIMIT', '512M');
    ```


2- Check PHP info
  Create a test file:
  ```
  sudo nano /var/www/html/info.php
  ```
    * Add:
    ```
    <?php phpinfo(); ?>
    ```

  Visit:
  ```
  http://localhost/info.php
  ```

  Search for:
    - upload_max_filesize
    - post_max_size



# Disable Apache2 Debian Default Page
1- Remove default index file
  ```
  sudo rm /var/www/html/index.html
  ```


# Disable Index browsing
1- Edit Apache config
  ```
  sudo nano /etc/apache2/apache2.conf
  ```

2- Find this section:
  ```
  <Directory /var/www/>
      Options Indexes FollowSymLinks
      AllowOverride None
      Require all granted
  </Directory>
  ```
    * Change:
    ```
    Options Indexes FollowSymLinks
    ```
    * to
    ```
    Options -Indexes +FollowSymLinks
    ```
    * The -Indexes disables file browser view.

3- If you want to enable other directory just add
  ```
  <Directory /var/www/html/wordpress/xxxxx>
          Options Indexes FollowSymLinks
          AllowOverride All
          Require all granted
  </Directory>
  ```
  xxxxx: is the name of parent directory to allow index browsing


4- Restart Apache
  ```
  sudo systemctl restart apache2
  ```

5- Now if you visit:
  ```
  http://localhost
  ```

  * You'll get:
  ```
  Forbidden
  You don't have permission to access this resource.
  ```
  Which is correct, And your WordPress will still work at:
  ```
  http://localhost/wordpress
  ```


# Fix Divi errors (server config)

1- Enable mod_rewrite
  Run:
  ```
  sudo a2enmod rewrite
  sudo systemctl restart apache2
  ```

  Then make sure Apache allows .htaccess
    * Edit:
    ```
    sudo nano /etc/apache2/apache2.conf
    ```
    * Find:
    ```
    <Directory /var/www/>
        AllowOverride None
    ```
    * Change to:
    ```
    <Directory /var/www/>
        AllowOverride All
    ```

  Restart apache
  ```
  sudo systemctl restart apache2
  ```


2- Check WordPress Permalinks
  Go to:
  ```
  Settings → Permalinks
  ```

3- Check REST API:
  Visit this in your browser:
  ```
  curl http://localhost/wordpress/wp-json/
  ```
  If you get:
    - 404 → mod_rewrite problem
    - 403 → permissions problem
    - 500 → PHP error


4- Check Site URLs (After Migration)
  Inside database:
  ```
  SELECT option_name, option_value 
  FROM wp_options 
  WHERE option_name IN ('siteurl','home');
  ```

  They must match exactly (wordpress uri):
  ```
  http://localhost/wordpress
  ```


# Installed phpMyAdmin
1- Run:
  ```
  sudo apt update
  sudo apt install phpmyadmin
  ```

2- Check if the config file exists:`
  ```
  ls /etc/apache2/conf-available/
  ```

  if `phpmyadmin.conf` doesn't exits.
  * Check if the config file exists somewhere else
  ```
  ls /usr/share/phpmyadmin
  ```
  * If that directory exists, we can manually create the Apache config.
  * Manually Create the Apache Config
  ```
  sudo nano /etc/apache2/conf-available/phpmyadmin.conf
  ```
  * Paste this inside:
  ```
  Alias /phpmyadmin /usr/share/phpmyadmin

  <Directory /usr/share/phpmyadmin>
      Options SymLinksIfOwnerMatch
      DirectoryIndex index.php
      AllowOverride All
      Require all granted
  </Directory>

  <Directory /usr/share/phpmyadmin/setup>
      Require all denied
  </Directory>
  ```

3- Enable It:
  ```
  sudo a2enconf phpmyadmin
  sudo systemctl reload apache2
  ```
