Database Setup

Installing Bitnami *AMP

Go here and download the right Bitnami *AMP for your OS:

Windows: Bitnami WAMP: https://bitnami.com/stack/wamp

Macs: Bitnami MAMP: https://bitnami.com/stack/mamp

Macs also need the Homebrew package manager: https://brew.sh/

Linux: Bitnami LAMP: https://bitnami.com/stack/lamp

There might be multiple versions available for download for a given OS. Just use the latest version. And sometimes, when you are downloading software, it might mention 32-bit or 64-bit. Long story short, if your computer has more than 4GB of RAM, then it’s definitely running a 64-bit OS. 32-bit operating systems are older and can support a maximum of 4GB of RAM. They are on their way out.

The AMP portion stands for Apache, MySQL, and PHP. It basically just means server back-end stuff all bundled together. The alternative to installing a WAMP/LAMP/MAMP stack would be to install and configure each piece of software separately, which is annoying and error-prone. I don’t recommend it. You could technically build your own car piece by piece, but most people buy a car that’s already built because it’s more convenient.

Windows-specific instructions for WAMP (skip if you’re on macOS or Linux):

After you’ve downloaded WAMP, run the installer. You will be prompted to enter a root password for the WAMP server. You should either write this down in a password manager such as LastPass, or just memorize it. You will need to know the password later on. Also, Bitnami WAMP doesn’t support punctuation, but use uppercase, lowercase, and numbers as your password. It will then ask you if you want to launch wampstack in the cloud. Uncheck it. You want to run it locally, not in the cloud. Click next a few more times, and then it will take a while to finish installing (maybe 10 minutes or so), even if you have a fast CPU and SSD. You will get a firewall-related pop-up asking if you want to allow mysqld to be used over the network. Mysqld is the MySQL daemon, hence mysqld. The simplest explanation of a daemon is that it’s software that runs in the background and waits to be used. You do not specifically have to click on a daemon to run it. It is already running in the background.

For the mysqld firewall pop-up, only check the box for private networks or local networks, not public ones. The same thing goes for the next pop-up about Apache HTTP Server. You might think of a server as a piece of hardware, but in reality, what makes a server a server is actually the software on it. A server is something that waits and listens for requests from users who initiate connections with it, and sends responses to said requests.

Installing MySQL Workbench and creating a connection to WAMP (Windows only)

When Bitnami WAMP has finished installing, download MySQL Workbench from here:

https://dev.mysql.com/downloads/workbench/

It is available for Windows, macOS, and Linux. However, when testing it on macOS and Linux, it had some issues which required more complex configuration to get it to work with Bitnami *AMP, so I decided against using it for macOS and Linux, just to keep it simple. But on Windows, the installation process is much simpler and faster than that of Bitnami WAMP.

Once it has been installed, start MySQL Workbench. Then, under the MySQL Connections section, click the + icon to add a new connection. Leave in the default settings, such as 127.0.0.1 and root. But you will need to type in the password for Bitnami *AMP that you set up earlier. You will also need to set a name for the connection, such as BitnamiWAMP. Once you hit OK, and it works correctly, you should be able to see the connection under the MySQL Connections section. Click the newly-created connection. If you did everything correctly, you should see something that says “Query 1.” Now you will be able to make SQL queries that will be used with your Bitnami *AMP stack’s database.

Mac-specific instructions for MAMP (skip if you’re on Linux or Windows):

Download MAMP: https://bitnami.com/stack/mamp

Double click on the installer, then double click MAMP.app to install it. Depending on your macOS security settings, it might ask if you want to proceed, with something like this:

“MAMP.app” is an app downloaded from the Internet. Are you sure you want to open it?

Then hit open. After a couple seconds, you should see the Setup window. Click next three times, then enter in a root password for your MySQL database. You will need to keep track of this, such as putting it in a password manager, or making something you can remember. Resetting MySQL passwords can be a pain, so it’s best if you just know what it is to begin with.

Click next. Then it will ask if you want to run mampstack in the cloud. Uncheck that box, because you want to run it locally, not in the cloud. Click next two more times. Then wait 5-10 minutes until it finishes. Then close the window. Then open a Finder window. Then click on Applications. Click on Launchpad. Scroll to the rightmost page of launchpad. You should see something that says manager-osx. That is how you will control Bitnami MAMP on your Mac. Click on manager-osx. Once the MAMP manager window is open, I recommend that you right click on the dock icon for it, and then hit Options -> Keep in Dock. Then you’ll be able to easily get back to it when you need to. Within the Bitnami MAMP manager program, click Manage Servers in order to see the status for MySQL Database and Apache Web Server. They should both say Running under the status column. If not, then click on each one and hit Start. Now go to Launchpad again and search for Terminal (or use iTerm2 if you prefer that).

If you didn’t already install Homebrew, which was covered in the command line chapter, do so now:

https://brew.sh/

Install vim using brew install vim. You will need this later.

Within a terminal window, do the following command:

cd /Applications/mampstack-7.2.24-0/

Replace 7.2.24-0 with whatever version you downloaded. The numbers might be different because you might download a newer version, since I had to write this book before you started reading it.

To use the mysql> command prompt, use the following commands from within the mampstack directory:

./use_mampstack

mysql -u root -p

Then you will have to enter in your Bitnami MAMP password that you set up when installing MAMP.

If you did everything correctly, you should see a prompt like this: mysql>

Now type exit; to leave. Then type exit again to leave use_mampstack.

Keep in mind that the mysql> prompt only works if you use the Bitnami MAMP manager to start the MySQL database and Apache Web Server.

Linux-specific instructions for LAMP (skip if you’re on macOS or Windows):

Go here and download LAMP, and then save it in your home directory:

https://bitnami.com/stack/lamp

The file will be called something like bitnami-lampstack-7.2.24-0-linux-x64-installer.run. It might have different numbers, such as if there’s a new release of Bitnami LAMP in the future.

Open a terminal window. Use cd ~/ to go to your home directory, which is where you should have either downloaded or moved your LAMP file to. Type the following command:

chmod +x bitnami-lampstack-7.2.24-0-linux-x64-installer.run

Now run it:

./bitnami-lampstack-7.2.24-0-linux-x64-installer.run

Hit next three times. Then you will see the password screen. Type in the root password you want to use. I recommend using a password manager to keep track of it. After typing the password you want to use, hit next.

Then uncheck “launch lampstack in the cloud with Bitnami” because you want to run it locally, not in the cloud. Then click next.

Then wait a while (5-10 minutes) for it to finish installing. Not everyone’s computer has the same performance, so it might take you even more or less time than that. But once it’s finished, hit finish and it will launch LAMP. You can close the browser tab that it opens. The Bitnami LAMP window looks basically the same in Linux as the one in Windows. You can also close the Bitnami manager window too.

Then go to the “Manage Servers” tab and click “Start” for Apache Web Server and MySQL Database. It should say “Running” for both of them. Only then will you be able to proceed with the MySQL Workbench stuff.

I was originally going to make instructions for using Bitnami LAMP with MySQL Workbench, but long story short, it was a big hassle, and it’s easier if you just use the command line for mysql.

Now open a terminal, and assuming you’re in the lampstack directory, type the following commands:

./use_lampstack

mysql -u root -p

Then it will prompt you to enter your password that you chose when installing Bitnami LAMP. The -u means user, root is the user you’re picking, and -p means password, which you will enter on a separate line so that it doesn’t get put into your bash history.

Once you’re done, if it was successful, you should see the following prompt:

mysql>

If you ever close the terminal window or restart your computer, you will need to do ./use_lampstack and mysql -u root -p again.

If you’re in mysql> in a terminal window and you want to quit, use the following command:

quit;

But now you should be able to do the query demonstrations that are in section 11.3. The only difference is that the Bitnami WAMP instructions are for the graphical MySQL Workbench program, which involves clicking a button to run a query. But in Linux, you will have to hit enter after typing in your query. It’s basically the same aside from that though.

Why WAMP/LAMP/MAMP?

Although you can use *AMP on Windows or macOS, the fact of the matter is that most web servers run Linux, so LAMP is a very standard stack. Apple used to make servers, but not anymore. You can technically run Windows Server for IIS or ASP.NET (with C#), but in the real world, most servers run Linux. Windows Server is commonly used within an organization’s LAN for something like SMB for file sharing, or LDAP, turning a Windows Server machine into something called a domain controller, which is in charge of authenticating users. But Windows Server is used less for web server stuff and more for internal business-related roles.

Linux is the most widely used server OS (such as Ubuntu, CentOS, or Red Hat), Apache is the most widely used web server program, WordPress is the most widely used content management system (for people who want a website but don’t want to make it from scratch), and PHP is the most widely used server programming language. MySQL is the second most popular DBMS, but it’s the #1 most popular free one (Oracle Database is more popular, but costs quite a lot of money). As such, there are tons of jobs in LAMP.

LAMP has been around for a while, though it still continues to be updated and used. Some people in tech are obsessed with new things. But LAMP, while not super new anymore, is not obsolete either. LAMP is a well-established, mature, useful stack. I took a class in college about web development and databases, and it actually used the MEAN stack (MongoDB, Express, Angular, and Node), which is newer and “cooler” than LAMP, but it’s actually less useful except for “disruptive” startups, as most companies are using older stuff. The thing about technology is that companies build on the existing stuff they have rather than throwing something out entirely and replacing it with something new just because it’s newer. So I had to teach myself LAMP after noticing that there are fewer opportunities in MEAN. And just because something is new does not mean it will last long or become “the next big thing.” Some flash-in-the-pan new tech comes and goes quickly while older, well-established tech lives on. This is not always the case, but it’s true at least some of the time.

Stopping and starting *AMP

Windows:

When you have Bitnami WAMP installed, it will start automatically when you boot up your computer. You can manage the Bitnami WAMP stack using the WAMP manager. In Windows, it’s located at C:\Bitnami\wampstack-7.3.11-0\manager-windows.exe. Your exact version might be different, so it will be wampstack-[some other numbers]\manager-windows.exe.

Mac:

In your dock, click the MAMP manager icon that you created in the previous steps. Click Manage Servers to manage the Apache and MySQL services.

Linux:

Please note: the default for Bitnami LAMP is that it won’t start automatically when your OS boots up. You will not be able to connect to your MySQL database if LAMP isn’t started. If you reboot your computer, you can open a terminal window and then type the following commands in order to start the Bitnami LAMP stack again:

cd ~/lampstack-7.2.24-0/

./manager-linux-x64.run

Dedicated LAMP servers or VMs (optional and not recommended for beginners)

If you just want to get right into WAMP/LAMP/MAMP development for learning SQL and PHP, you can skip this sub-section.

Bitnami *AMP runs locally on your computer. This is typically only done on developer machines for the purpose of development, not as a server that users or customers will connect to. It’s easy to set up and makes it quick to get started with LAMP stack development. However, no actual web server on the internet will be running on a regular laptop or desktop computer. Instead, people set up dedicated servers in data centers and then install virtual machines on them. A web hosting company will use hypervisor software, such as VMware ESXi (or Xen or KVM), to allow users to have different virtual machines. A hypervisor takes one computer and basically turns it into multiple slower computers (VMs). If you pay a web hosting company for a server, and you don’t choose a very expensive option, then your VM will be running on a shared server that many other customer VMs are also running on, though they won’t be able to interact with one another. Also, fun fact: Bitnami was recently purchased by VMware. Big players in virtualization, even traditional stuff as opposed to containers (like Docker), are seeing the value in pre-configured virtual appliances rather than setting up an OS installation from scratch.

I absolutely do not recommend learning LAMP development on an internet-facing server. What you should do is practice and learn on either a local WAMP program on your computer, or on a LAMP server that is only accessible on your local area network. When you are messing around with stuff, you might accidentally make your server insecure, so you don’t want to put it on the internet where hackers could find and abuse it. This is a common thing for software developers: you have a test server/environment, and then only when it’s been properly tested and vetted, you push the code to production, such as an internet-facing server.

You can also have your own home server if you want. You can buy a used server on ebay, such as a Dell PowerEdge R710, which has good performance for the money, but the downside is that it’s very loud. The performance is great for the money, but it can be unbearably loud unless you have a basement you can put it in, where it will be far enough away from you that you can’t hear it. I live in an apartment with no basement, so I have some old desktop computers that I use as servers.

But if you have an old desktop or laptop, you can install either Proxmox or ESXi on it, and then within that, you can create an Ubuntu Server virtual machine. You can install Bitnami LAMP in that, or you can use Ubuntu’s package manager to install Apache, MySQL, and PHP. But a preconfigured LAMP stack is easy to deal with. Or you can skip the hypervisor portion and install Ubuntu Server directly onto the hardware. But then it won’t be quite as flexible, VM-wise.

Having a dedicated server can be useful if you want many devices to access it, if you want it running 24/7, or if you want to use fewer resources on your main computer. And if you’re ever planning on making your own full-stack website project that you want to put on the internet, it could be useful to try out a LAN-only server first. But this is entirely optional. I recommend skipping this for the time being, but maybe coming back to it later.

I’ve personally built a server rack with many inexpensive servers in it, but I didn’t start out this way when I was first learning to code.

I’ve known some people who hosted their public website on their own home server, doing something called port forwarding on their router, and using a dynamic DNS service such as Dyn. I don’t recommend doing this. If you want a public server, pay for a shared web host or VPS host. But don’t try to open up ports on your home router to let people connect to your home server. That won’t end well. You could either get hacked or your ISP might complain because some ISPs have policies against users doing things like that. But the good news is that a web server can cost as little as a few bucks a month. A home server should be for you and other people in your household only.

← Previous | Next →

SQL and Databases Topic List

Main Topic List

Leave a Reply

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