Disclaimer

This blog is kind of my own personal work Notebook, and the processes below are only guaranteed to work for my specific configurations. So, use this info at your own risk, and please understand I won't be able to provide any help if you break something

Tuesday, February 25, 2025

Python Web Development Fundamentals

Python logo


These are Python Web Development fundamentals for developers familiar with PHP and JavaScript.

Core Frameworks

- Flask: Lightweight, similar to Express.js. Great for APIs and small apps.
- Django: Full-featured like Laravel/WordPress. Includes ORM, admin panel, auth system.
- FastAPI: Modern, high-performance framework with automatic API documentation.

Key Concepts

- Python uses indentation (not braces) for code blocks
- No semicolons needed
- Function-based views vs class-based views (similar to PHP procedural vs OOP)

Simple Flask Example (Compare to PHP)

```python
from flask import Flask, request, render_template

app = Flask(__name__)

@app.route('/')  # Like PHP routing or .htaccess rules
def home():
    return render_template('home.html', title='Home')  # Similar to PHP include/require

@app.route('/user/<username>')  # Dynamic URL parameter (like PHP $_GET)
def profile(username):
    return f"Profile for {username}"  # f-strings are Python's template literals

@app.route('/form', methods=['POST'])
def handle_form():
    data = request.form  # Similar to PHP $_POST
    return f"Received: {data['name']}"
```

Database Access (vs PHP/MySQL)

```python
# Using Django ORM (compare to raw PHP MySQL)
from django.db import models

class Post(models.Model):  # Similar to creating a DB table in PHP
    title = models.CharField(max_length=200)
    content = models.TextField()
    pub_date = models.DateTimeField('date published')
    

Query example

posts = Post.objects.filter(pub_date__year=2023).order_by('-pub_date')
# vs PHP: SELECT * FROM posts WHERE YEAR(pub_date) = 2023 ORDER BY pub_date DESC
```

Template System (vs PHP/HTML)

```html
<!-- Django template (compare to PHP in HTML) -->
<h1>{{ post.title }}</h1>  <!-- Like <?php echo $post->title; ?> -->

{% for comment in comments %}  <!-- Like <?php foreach($comments as $comment): ?> -->
    <p>{{ comment.text }}</p>
{% endfor %}  <!-- Like <?php endforeach; ?> -->
```

Python web development uses more abstraction than PHP but has similar concepts to what you already know. 

In PHP, you often work directly with the web server's request/response cycle. PHP files typically mix HTML and PHP code, with PHP handling server-side logic directly embedded in presentation markup. This is a more direct approach - the connection between your code and the HTTP mechanics is quite visible.

Python web development, by contrast, introduces more layers of abstraction:

  1. Framework-driven approach: Most Python web development happens through frameworks like Django or Flask that abstract away many HTTP details. Rather than writing code that directly outputs HTML, you define route handlers, views, and templates as separate components.
  2. Separation of concerns: Python web frameworks strongly encourage separating business logic, data access, and presentation. While PHP has frameworks that do this too (Laravel, Symfony), Python frameworks make this separation more fundamental.
  3. ORM prevalence: Python web development heavily relies on Object-Relational Mappers. While PHP has options like Doctrine, Python developers almost always use ORMs (Django ORM, SQLAlchemy) rather than writing raw SQL.
  4. Configuration over convention: Python frameworks often use decorators, configuration files, and class inheritance to define application behavior, versus PHP's more direct procedural approach in many cases.

Despite these differences, the underlying concepts remain similar: routes map to functions/methods, templates render data, database operations persist information, etc. 

If you understand PHP's web development model, you'll recognize these patterns in Python - they're just wrapped in different syntax and architectural approaches.

Wednesday, January 8, 2025

Choosing the right Web Hosting Company for High-Performance WordPress and WooCommerce websites

Web Hosting Company for High-Performance WordPress and WooCommerce websites"

Below there’s a detailed run-down of some of the best hosting companies, focusing on factors such as speed, reliability, support, and features specifically tailored for WordPress and WooCommerce. 

Disclaimer: 

Throughout my career, I have had the opportunity to work with and become affiliated with all of these web hosting providers. My involvement with them has primarily been driven by clients who had already chosen specific hosting packages for their projects.

Bear in mind that when selecting the most suitable web host for your business, it is crucial to understand that there is no one-size-fits-all solution. Each business has unique needs and requirements, therefore the decision should be made with careful consideration of several factors, including anticipated traffic, technical support needs, and the specific features offered by the hosting providers.

Selecting the right web host is a pivotal decision that can significantly impact the performance, security, and scalability of your website. Therefore, I encourage you to thoroughly evaluate your options, considering both your current needs and future growth, to ensure you choose the web hosting provider that aligns with your business objectives. Drop me a line and I'll be happy to help you choose.


1. Kinsta

Kinsta is a premium managed WordPress hosting provider powered by Google Cloud Platform (GCP). Known for its exceptional performance and customer support, Kinsta is a top choice for businesses that require robust hosting solutions. 

Key Features 

  • High Performance: Kinsta utilizes GCP's C2 machines, which are known for their high performance. This ensures fast load times and optimal website performance. 
  • Staging Environments: Offers staging environments for testing changes before going live. 
  • Automatic Backups: Daily automatic backups with options for manual backups. 
  • 24/7 Support: Expert WordPress support available around the clock. 
  • Developer-Friendly: SSH access, WP-CLI, Git integration, and more. 

Pros 

- Excellent uptime and speed. 
- Scalable infrastructure. 
- Comprehensive security features. 
- Developer-friendly tools and environment. 

 Cons 

- Higher cost compared to other hosting providers. 
- No email hosting included.


2. WP Engine

WP Engine is another leading managed WordPress hosting provider, known for its reliability and speed. It's particularly well-suited for businesses and developers looking for a hassle-free hosting experience. 

Key Features 

  • Managed Hosting: Automatic updates, daily backups, and robust security measures. 
  • Performance: Proprietary caching technology and CDN integration. 
  • Development Tools: Staging environments, SSH, and Git integration. 
  • Customer Support: 24/7 support with WordPress experts. 
  • ecommerce Optimization: Specific features for WooCommerce performance enhancement. 

Pros 

- Strong focus on WordPress and WooCommerce. 
- Fast, reliable, and secure. 
- Excellent support and resources. 
- Scalable plans to accommodate growth. 

Cons 

- Higher price point. 
- Additional cost for some advanced features.


3. SiteGround

SiteGround is known for its excellent customer support and reliable hosting services. It offers a range of plans that cater to both small businesses and large enterprises. 

Key Features 

  • Speed: SuperCacher technology and free CDN for improved load times. 
  • Security: Daily backups, free SSL, and proactive monitoring. 
  • Support: 24/7 customer support with WordPress expertise. 
  • Ease of Use: User-friendly interface and automated WordPress installation. 
  • eCommerce: WooCommerce-optimized hosting plans. 

 Pros 

- Affordable pricing.
 - Strong emphasis on security.
 - Excellent customer support. 
- High performance and reliability. 

 Cons 

- Limited storage on lower-tier plans. 
- Renewal rates can be high.


4. Bluehost

Bluehost is a well-established hosting provider recommended by WordPress.org. It offers a range of hosting plans, including specialized WordPress hosting. 

 Key Features 

  • One-Click WordPress Install: Simplifies the setup process. 
  • Performance: Free CDN and SSD storage for faster load times. 
  • Support: 24/7 customer support with WordPress experts. 
  • Security: Free SSL certificate and regular backups. 
  • WooCommerce Integration: Specific plans designed for WooCommerce. 

 Pros 

- Affordable and beginner-friendly. 
- Easy WordPress integration. 
- Free domain for the first year. 
- Good uptime and performance. 

 Cons 

- Upselling during the checkout process. 
- Higher renewal rates. 
- Customer support can be inconsistent.


5. Flywheel

Flywheel is a managed WordPress hosting provider known for its user-friendly interface and robust performance. It's a great option for freelancers, agencies, and developers. 

 Key Features 

  • Speed: Built-in caching and CDN for fast load times. 
  • Security: Nightly backups, malware monitoring, and free SSL. 
  • User Interface: Intuitive dashboard designed for ease of use. 
  • Collaboration Tools: Features for team collaboration and client management. 
  • Performance: Optimized for WooCommerce with specific features to enhance store performance. 

 Pros 

- User-friendly interface. 
- Excellent support and resources. 
- High performance and reliability. 
- Great for agencies and freelancers. 

 Cons 

- Higher price compared to some other providers. 
- Limited customization options.


6. A2 Hosting

A2 Hosting is known for its speed-focused hosting solutions. It offers a variety of hosting plans, including managed WordPress hosting. 

 Key Features 

  • Performance: Turbo servers for up to 20x faster load times. 
  • Security: Free SSL, automatic backups, and enhanced security measures. 
  • Support: 24/7 Guru Crew support. 
  • Developer Tools: SSH access, WP-CLI, and staging environments. 
  • WooCommerce: Specific plans optimized for WooCommerce. 

 Pros 

- Affordable and competitive pricing. 
- Excellent speed and performance. 
- Developer-friendly features. 
- Reliable customer support. 

 Cons 

- Interface can be complex for beginners. 
- Some features available only on higher-tier plans.


7. IONOS

IONOS is a german web hosting provider, known for offering a wide range of hosting services tailored to various types of users, from individuals to large enterprises.

Established in 1988 as 1&1 Internet, the company rebranded to IONOS in 2018, reflecting its growth and expanded service offerings.

Key Features 

  • Affordable and Scalable: Shared hosting plans are cost-effective, making them suitable for small websites, blogs, and startups. 
  • Ease of Use: Intuitive control panel, ensuring that even users with minimal technical expertise can manage their websites effectively. 
  • Support: Managed hosting plans coWith SSD storage and a high uptime guarantee, IONOS ensures fast load times and reliable service.
  • Optimized for WordPress: Specific plans come pre-configured with WordPress, ensuring optimal performance and security.

 Pros 

- Competitive Pricing. 
- Comprehensive Support. 
- Advanced Infrastructure. 
- Global Presence. 

 Cons 

- Interface can be complex for beginners. 
- Advanced security tools and premium support, may come with additional costs.


8. Cloudways

Cloudways is one of my choices when I have the freedom to set up everything from scratch (the other one is ServerPilot), something that unfortunately only happens in very rare occasions. 

Cloudways can be considered as a server management platform. It provides managed cloud hosting, enabling you to deploy and manage web applications on cloud servers from providers like DigitalOcean, AWS, Google Cloud Platform, Vultr, and Linode. It combines the power of these cloud platforms with managed hosting features tailored for WordPress and WooCommerce.

Key Features

  • Choice of Cloud Providers: Users can choose from five cloud infrastructure providers: DigitalOcean, Linode, Vultr, AWS, and Google Cloud Platform.
  • Performance Optimization: Advanced caching mechanisms (Varnish, Memcached, Redis), CDN integration, and PHP 7 ready servers for high performance.
  • Scalability: Easy vertical scaling to increase server resources as needed.
  • Managed Security: Regular security patching, dedicated firewalls, free SSL, and automated backups.
  • Staging Environment: One-click staging environment for testing and development.
  • 24/7 Support: 24/7 support via live chat and a ticketing system with an option for premium support plans.
  • Ease of Use: User-friendly console with features like 1-click app installation and managed server monitoring.
  • WooCommerce Optimization: Specific server configurations and features optimized for WooCommerce to handle high traffic and transactions.

Pros

  • Flexibility: The ability to choose from multiple cloud providers allows for tailored solutions based on specific performance and budget needs.
  • Performance: High-speed performance with advanced caching and the latest server technologies.
  • Scalability: Easy scaling options ensure your website can handle increased traffic and demand.
  • Managed Services: Takes care of server management, security, and backups, allowing you to focus on your website.
  • Cost Efficiency: Pay-as-you-go pricing model helps in managing costs effectively.

Cons

  • Complexity for Beginners: The flexibility and range of options can be overwhelming for users who are not familiar with cloud hosting.
  • Support Limitations: Standard support is good, but priority and advanced support options come at an additional cost.
  • No Domain Registration: Unlike traditional hosting providers, Cloudways does not offer domain registration services.
  • No Email Hosting: Email hosting is not included, and you will need to use third-party email services.

Tuesday, January 7, 2025

Converting MyISAM tables to InnoDB on MediaWiki

Converting MyISAM tables to InnoDB is generally safe and recommended for most use cases, as InnoDB offers better reliability, performance, and features like transactions and row-level locking. 

However, there are some potential risks and considerations you should be aware of before proceeding. 

Here's a detailed breakdown:


Potential Risks and Considerations


1. Full-Text Search Limitations

  • MyISAM: Supports full-text indexing and searching natively.

  • InnoDB: Full-text search support was added in MySQL 5.6+ and MariaDB 10.0+, but it may behave differently or have performance implications compared to MyISAM.

  • Action: If your MediaWiki installation relies heavily on full-text search (e.g., for searching article content), test the performance after conversion.



2. Table-Level Locking vs. Row-Level Locking

  • MyISAM: Uses table-level locking, which can cause contention during heavy write operations.

  • InnoDB: Uses row-level locking, which is more efficient for concurrent writes but may require more system resources (e.g., CPU and RAM).

  • Action: Ensure your server has sufficient resources to handle InnoDB's row-level locking.



3. Storage Requirements

  • MyISAM: Typically uses less disk space than InnoDB.

  • InnoDB: May use more disk space due to its support for transactions, foreign keys, and other features.

  • Action: Ensure you have enough disk space before converting large tables.



4. Foreign Key Constraints

  • MyISAM: Does not support foreign keys.

  • InnoDB: Enforces foreign key constraints, which can cause errors if your schema relies on MyISAM's lack of enforcement.

  • Action: Review your database schema for any implicit dependencies that might break when foreign keys are enforced.



5. Performance Differences

  • MyISAM: Can be faster for read-heavy workloads with minimal writes.

  • InnoDB: Generally performs better for mixed read/write workloads and high concurrency.

  • Action: Test the performance of your MediaWiki installation after conversion to ensure it meets your expectations.



6. Downtime During Conversion

  • Converting large tables can take time and may require downtime, especially if the table is heavily used.

  • Action: Schedule the conversion during a maintenance window or when traffic is low.



7. Backup and Rollback

  • If something goes wrong during the conversion, you’ll need a backup to restore the original state.

  • Action: Always back up your database before converting tables.



Steps to Safely Convert MyISAM Tables to InnoDB

1. Backup the Database

Before making any changes, back up your entire database:

bash
Copy
sudo mysqldump -h localhost -u user_name -p db_name > db_name_backup.sql


2. Identify MyISAM Tables

Run the following SQL query to list all MyISAM tables in your database:

sql
Copy
SELECT TABLE_NAME 
FROM information_schema.TABLES 
WHERE TABLE_SCHEMA = 'db_name
' AND ENGINE = 'MyISAM';


3. Test Conversion on a Single Table

Before converting all tables, test the conversion on a single, less critical table to ensure there are no issues:

sql
Copy
ALTER TABLE table_name ENGINE=InnoDB;

Replace table_name with the name of the table.



4. Monitor Performance and Functionality

After converting a table:

  • Check for errors in the MariaDB logs.

  • Test the functionality of your MediaWiki installation (e.g., editing pages, searching, etc.).

  • Monitor server performance (CPU, RAM, disk I/O).



5. Convert All MyISAM Tables

If the test conversion is successful, convert all MyISAM tables to InnoDB. You can generate the conversion commands dynamically:

sql
Copy
SELECT CONCAT('ALTER TABLE ', TABLE_NAME, ' ENGINE=InnoDB;') 
FROM information_schema.TABLES 
WHERE TABLE_SCHEMA = 'db_name' AND ENGINE = 'MyISAM';

Copy and execute the generated commands in the MariaDB shell.



6. Verify the Conversion

After converting all tables, verify that they are now using the InnoDB engine:

sql
Copy
SELECT TABLE_NAME, ENGINE 
FROM information_schema.TABLES 
WHERE TABLE_SCHEMA = 'db_name';


7. Optimize Tables (Optional)

After conversion, you may want to optimize the tables to reclaim unused space and improve performance:

sql
Copy
OPTIMIZE TABLE table_name;


What to Do If Something Goes Wrong

If you encounter issues after converting tables:

  1. Restore the database from the backup:

    bash
    Copy
    sudo mysql -h localhost -u user_name -p db_name < db_name
    _backup.sql
  2. Check MariaDB logs, review schema dependencies, etc.

  3. Unfortunately I won't be able to help, so restore your backup

  4. Seek help from the  MediaWiki support community  or a database administrator.

Saturday, June 1, 2024

Install MediaWiki on a secure, optimized stack with Nginx, MariaDB, and PHP on Ubuntu.

  1. Install Nginx, MariaDB, and PHP:
sudo apt update sudo apt install nginx mariadb-server php php-fpm php-mbstring php-xml php-json php-mysql php-curl php-intl php-gd php-mbstring texlive imagemagick unzip -y
  1. Configure MariaDB:
sudo mysql_secure_installation sudo mysql -u root -p

Inside the MariaDB shell:

CREATE DATABASE wikidb; GRANT ALL PRIVILEGES ON wikidb.* TO 'wikiuser'@'localhost' IDENTIFIED BY 'password'; FLUSH PRIVILEGES; EXIT;
  1. Download and Configure MediaWiki:
cd /var/www/html wget https://releases.wikimedia.org/mediawiki/1.31/mediawiki-1.31.0.tar.gz tar xvf mediawiki-1.31.0.tar.gz mv mediawiki-1.31.0 mediawiki sudo chown -R www-data:www-data /var/www/html/mediawiki
  1. Configure Nginx: Create a new Nginx configuration file:
sudo nano /etc/nginx/conf.d/wiki.conf

Add the following content:

server { listen 80; server_name wiki.example.com; root /var/www/html/mediawiki; index index.php; error_log /var/log/nginx/mediawiki.error; access_log /var/log/nginx/mediawiki.access; location / { try_files $uri $uri/ /index.php; } location ~ \.php$ { fastcgi_pass unix:/run/php/php7.4-fpm.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; include snippets/fastcgi-php.conf; } location ~ /\.ht { deny all; } }

Test and restart Nginx:

sudo nginx -t sudo systemctl restart nginx
  1. Secure with Let's Encrypt: Install Certbot:
sudo apt install certbot python3-certbot-nginx -y

Obtain and install the SSL certificate:

sudo certbot --nginx -d wiki.example.com
  1. Finalize MediaWiki Installation: Open your browser and navigate to http://wiki.example.com to complete the MediaWiki setup through the web interface.

Sunday, May 5, 2024

WordPress recovery mode

You can manually generate a recovery link to gain access to your WordPress site by adding: 

/wp-login.php?action=entered_recovery_mode

right after your domain name.  


For example, if your domain name is www.example.com, the 'safe mode' recovery URL would be: 

https://www.example.com/wp-login.php?action=entered_recovery_mode