20 thoughts on “How to Run Python in an Apache server and access a MySQL database

  1. Searched through plentiful of articles and videos, this was the only one to demonstrate the whole process so smoothly!

  2. can someone help me with the CGI part? https://stackoverflow.com/questions/64514642/using-html-to-input-data-and-using-sqlite3-via-python-to-update-it

  3. Please please please noone do the "sudo rm /usr/bin/python" part. You will break your system. If you are gonna follow instructions blindly, much better to do the following

    echo "alias python=python3" >> ~/.bashrc

  4. nice job Mike! I used your video up to the hello world part (18 min) and it work great. Great video, I missed a hyphen in utf8 (sb utf-8) and it threw an error but I resolved it like you did in your code, i got the same error page. thanks so much! I subscribed btw. maybe I'll do the mysql later

  5. It wasn't working for me because the browser opened the .py like a text file, solved using sudo a2enmod cgi. Thanks for the tutorial.

  6. after watching this video i feel like i want to comment a 1000 times these words -"This is the best explanation ever"/

  7. One of the excellent and best explained implementation with perfect example and hands on ! Can you do the same for Apache and Django ?

  8. Hi Michael, I am using Amazon Linux which doesn't have a2enmod/a2dismod, do you know of an Amazon Linux version of this tutorial?

  9. #!/usr/bin/env python

    # Turn on debug mode
    import cgitb
    cgitb.enable()

    # Print required headers
    print("Content-Type:text/html;charset=utf-8")
    print()
    print("Hello World")

    import pymysql
    conn = pymysql.connect(db='example', user='root',passwd='yourPassword',host='localhost')
    c = conn.cursor()

    # Clear the database if not empty
    c.execute("TRUNCATE mytable")

    # Insert data into database
    c.execute("INSERT INTO mytable VALUES(1, 'One')")
    c.execute("INSERT INTO mytable VALUES(2, 'Two')")

    #Print contents of the database
    c.execute("SELECT * FROM mytable")
    print(c.fetchall())

  10. THE BEST EXPLAIN IN THE WHOLE WEB AND YOUTUEBE.. thanks a lot of

Leave a Reply

Your email address will not be published. Required fields are marked *