The Magic Lamp

I figured it would be nice to build a web server of some kind because honestly most of the posts you will read on here will have to do with the web. Although I am familiar with several different languages, and know C++ and Java to name a couple, my favorite languages are PHP, HTML, JavaScript and CSS.

Just get to it already!

When I started out, I was very overwhelmed at the instructions I found on the internet regarding building a web server. And it appeared to me that the majority of these directions came from people that were more than likely Linux pros. (I bring up Linux because that is what I wanted to use. Not only does i appear to be the way of choice by most, but it is imao more robust and reliable the other OSs and it is free.) It was nice that I was being told to run enmod to fix my PHP problem, but how do I do that?
LAMP servers are kinda old school, and I think going the way of the Dinosaur. However, a LAMP server is easy to build, and a great place to start some web development. Hopefully, I will get to experiment with something like a MEAN server, and I will post about my experience. But for now, this is what we are doing.
OK. Let's get started. Since we are building this on a Linux system (Linux Apache MySQL PHP), you'll want to download your favorite Linux distro. I used Ubuntu. It seems to be the most popular among home users. However, you can install whatever incarnation of Linux your little heart desires. And as we're not going to really be using a GUI, anything will work. After it is installed, it doesn't matter what you are using. The following steps will work the same. Just know that Step 1 below will follow the installation of Ubuntu Server.

Step 1

Installing a Linux server

Update! While Ubuntu continually updates their operating system (there has already been an update as of the time of this writing), the following guide has been for years, and more than likely will remain the same.
Let's start by downloading the latest Ubuntu server. Put it on a USB stick (or burn it to a disc). I like to use Etcher. It's easy peasy. Basically from here, just follow the instructions. Some things are self-explanatory, like choosing your language, region, time and keyboard. When you are asked to input a hostname, different environments will determine if it will come up with your computers hostname or not. If you are installing this on a home network, you might want to choose a hostname. Whatever you want to call it. (Just keep to the standard of no spaces in the name.)

Screenshot from Ubuntu 16.04 setup/package selection
This is from Ubuntu 16.04, and has looked like this for several versions back

When you come to the software selection, the only thing you want to select (if you want to follow this tutorial) is the OpenSSH server. If you would like to, you can select the LAMP server, follow the prompts, and be done. I will say, I have never done this. I don't know what you will get. Some of the reasons for doing it the 'hard' way (both validated and suggested) are:

  • You know what you'll get
  • Building from scratch will give you the opportunity to update to the latest and greatest beforehand
  • Better control
  • You can check for functionality along the way
  • It's fun!
Screenshot from Ubuntu 18.04 setup/SSH selection
This is what Ubuntu 18.04 looks like
TBH, you don't even need to install the OpenSSH server. This is so you can remote into the server from somewhere else, which is nice. If you want to, you can install the desktop afterward by inputting sudo apt-get install ubuntu-desktop. Just understand that all the code in this guide is to be entered via command line, but if you are not very familiar with Linux, a desktop is nice because you will now have easy access to a browser on your server machine. After running the command line above to install the desktop, just type /sbin/shutdown -r now and your machine will reboot into desktop mode.
Screenshot from Ubuntu 18.04 setup/package selection
As you can see, LAMP isn't even an option anymore

If you aren't sure how to SSH or don't want to install a desktop (because it takes up a lot of time and space), I use PuTTY (this is a Windows app). I'm not going into detail here about how to use it. Maybe another time. If you are using a Mac or Linux, a quick Google should give you some good options.

Step 2

Installing Apache web server

Input sudo apt-get install apache2. There's not a lot to this. After installing Apache, you can check to make sure it works. Simply go to 'localhost' in your browser and if you see this...

Screenshot of Apache homepage

...then everything's OK (so far).

At this point, you're going to want to  give yourself some permissions. Linux is a stickler when it comes to permissions, and if you don't do this, then you won't be able to upload any files to your own server.

sudo chown -R [yourLinuxUsername] /var/www/html/

should do the trick.

Step 3

Installing a database

The M in LAMP stands for MySQL, which is still free and downloadable. Oracle owns it now, and who knows what the future holds? Because of this, a group of coders forked the code and created MariaDB... a MySQL clone that is meant to stay free and opensource. Take your pick as to which one you want to install.

Input either:

sudo apt-get install mysql-server

or

sudo apt-get install mariadb-server

Easy, right?

Step 4

Installing a front-end UI so you can use your database

Now in order to use your database, you will need some kind of front-end client (unless you are very proficient at SQL, and prefer to input SQL statements). phpMyAdmin seems to be the client of choice when it comes to this. To install this, just input

sudo apt-get install phpmyadmin

Not too difficult. When asked which server you're using, just select apache2 (since that is what you are using if you have been following this tutorial). You will also be prompted about configuring phpmyadmin. If you read the screen, you will see you more than likely want to choose yes, as since you are following this tutorial, you probably won't know what to do if you choose no. Set a password when prompted to.

We're almost done.

Step 5

Installing PHP

Last step. We need to install PHP. Not only is this needed to run phpMyAdmin, but PHP is a very important (IMHO) language to use when building websites. We're going to install PHP, along with a few other modules to get this to work fundamentally.

sudo apt-get install php php-mysql php-mcrypt php-gd libapache2-mod-php

At this point, we are finished (in theory). It might be a good idea to make sure the installation of PHP worked. A simple way to do this is to upload a small file. There are several ways to do this. Create it in a text editor and upload it (Filezilla is a good tool to use here), create and upload it using something like Dreamweaver or you can even create it right on the server (if you are proficient with vi or nano or gedit if you loaded the desktop).  I'm not going to get into the use of any of these options, as that is not the scope of this post. Google is a good friend here if you need it. Bottom line... you need a file that contains the line



You can call it whatever you would like to, as long as it is one word (no spaces in the filename) and the extension must be .php. Then you can open your browser and go to

[yourURL]/whateverYouCalledYourFile.php

If you see something like this...

Screenshot of php info page

Then all worked well.

Step 6

Starting creating

OK. This really isn't a step, but I want to mention one thing here. When I've opened phpMyAdmin, I get an error about mcrypt. A quick Google search let me see that there are a lot of people that have this issue, as well. I'm still not certain if it is a bug, everyone followed the same online guide that failed to include this much-needed module, or what. In any case, I've been able to fix this problem by entering

sudo php5enmod mcrypt

There are several other directions out there, and much more complicated. I don't know if all that extra stuff is needed, or not. All I know is the above command line has always worked for me (I've set up about a dozen web servers in the last month).

Anyway... I hope this tutorial hasn't been too painful. Thanks for listening to my babble (I tend to do that). If you liked this guide, please leave a comment below. If you didn't, please let me know how I can improve (please be nice... and remember, I am not a pro).

Happy coding!

Dave

Comments

Popular posts from this blog

Discovering the Atom

Get Sassy!