navigate site menu

Start learning with our library of video tutorials taught by experts. Get started

Up and Running with Linux for PHP Developers

Up and Running with Linux for PHP Developers

with Jon Peck

 


Install and configure a local Linux server optimized for web application development with the LAMP (Linux/Apache/MySQL/PHP) software stack. Author Jon Peck describes the components and how they work together, shows you how to install and configure a virtualized Linux server, and details how to configure the additional stack elements: Apache, MySQL, and PHP.

The course also explores topics such as working from the Linux command line, installing several major PHP development frameworks and content management systems, and troubleshooting common installation and configuration issues. The demonstrations are performed with the Ubuntu distribution of Linux, but are also applicable to other Linux distributions.
Topics include:
  • What is Linux and why should I use it?
  • Introducing the LAMP stack
  • Creating and configuring a virtual machine
  • Working with the command line
  • Configuring the server components, including the Exim email server
  • Building a simple web site that connects to the local database
  • Installing Drupal, WordPress, and more on the server
  • Troubleshooting and maintaining Linux server components
  • Managing the server with Webmin
  • Using a MySQL client with the database

show more

author
Jon Peck
subject
Developer, Application Servers, Platforms, Web, Databases
software
Linux , Apache , LAMP
level
Beginner
duration
1h 17m
released
Aug 07, 2012

Share this course

Ready to join? get started


Keep up with news, tips, and latest courses.

submit Course details submit clicked more info

Please wait...

Search the closed captioning text for this course by entering the keyword you’d like to search, or browse the closed captioning text by selecting the chapter name below and choosing the video title you’d like to review.



Introduction
Welcome
00:04Welcome to Up and Running with Linux for PHP Developers.
00:07I am Jon Peck, a Zend-certified PHP engineer with more than a decade of systems
00:11administration experience.
00:13In this course, I'll show you how to configure your Mac or Windows workstation
00:17to be your own no-cost private web development server.
00:20In the end, you'll have an optimized virtual server running like any other
00:23program in your existing operating system.
00:26The configuration you'll use is known as a LAMP stack, and it's an extremely
00:29popular and common collection of web industry software.
00:33The end result will be similar to a hosted virtual private server, or a
00:36VPS, except it will be much faster, cheaper, and accessible only from your workstation.
00:41Let's get started.
Collapse this transcript
Setting up your workstation
00:00Before you begin, you'll need to download a couple free programs.
00:03First, you'll need to download the server installation disk image.
00:06You'll be using Ubuntu Server 12.04 Long Term Support 64 bit, which can be
00:12found at ubuntu.com.
00:14Make note of where you downloaded it.
00:15You'll need to know where it is later on.
00:18I'll go into greater detail about what Linux is and why I chose Ubuntu in chapter 1.
00:22Next, you'll need to download and install VirtualBox, the virtualization product
00:26you'll be using to host your own private development server.
00:29You'll be using version 4.1.16, which can be found at virtualbox.org.
00:34Complete the straightforward installation, but hold off on configuration.
00:38I'll explore what VirtualBox is, how you'll be using it, and how to use it for your server.
00:43To communicate with your server, you'll need to get an SSH client.
00:46For Mac the terminal application in Utilities is already installed; for Windows
00:50the free program PuTTY is a very lightweight and powerful SSH client. Download
00:54it from the official PuTTY homepage.
00:56Other free and commercial solutions exist, but for the methods you'll be
01:00using, this will be fine.
01:01Finally, some sort of IDE or text editor is needed to edit your scripts and programs.
01:06For the purposes of the demonstration, I'll be using the free IDE NetBeans
01:097.1.2 from netbeans.org.
01:13You're not required to use NetBeans.
01:15There are countless other IDEs, both free and commercial, that will be compatible
01:18with your development server.
Collapse this transcript
1. Getting Started
What is Linux and why should I use it?
00:00Before you start using a tool, having context about what it is and why
00:04it's being recommended will deepen your understanding to the system that you're using.
00:07It's never helpful to know that you're doing something but be unable to
00:10question or justify it.
00:12Therefore, let's talk about Linux: what it is and why it's a viable solution
00:16for development work.
00:17So, the encompassing question: What is Linux?
00:20Linux is an operating system that leverages free and open source software.
00:24We'll run the software needed for our development server on Linux, but what's
00:28this free thing mean anyway?
00:30Well, anyone can copy and reuse the software.
00:33That does not necessarily refer to the price of the software.
00:36To quote the Free Software Foundation, think of free as in free speech, not as in free beer.
00:42With that said, most free software in this sense does not have a price.
00:45Commercial distributions of Linux exist, such as Red Hat Enterprise Linux.
00:49In these circumstances, you're also paying for support and custom development.
00:54So when you hear the term open source, what does that mean?
00:57Open source software refers to computer software where the source code has
01:00been made freely available under a specific license.
01:03Users are permitted to study, change, improve, and sometimes distribute
01:07open source software.
01:08As the source code is freely available, this facilitates collaboration, which in
01:13turn can lead to a stronger product.
01:15Why does this matter to you?
01:16Well, cost per license become a thing of the past.
01:19There's a wide variety of enterprise-grade software for you to use that is pure
01:24built, reviewed, and designed, which allows you to focus on developing your own
01:27core product rather than reinventing the wheel.
01:30Open source software generally has a large community-based support system
01:34including wikis, forums, and Internet relay chat. All of this is available to
01:38you as resources.
Collapse this transcript
What options are there?
00:00Saying that you're using Linux is like saying you drive a car;
00:03it's an extremely broad label.
00:05While cars typically have four wheels and an engine, Linux shares many specific
00:09components and values.
00:11With that said, there's a great variety in both cars and Linux distributions.
00:15There are thousands of distributions of Linux, each with their own
00:18unique qualities or goals.
00:20We'll take a brief look at three of the most popular and well-supported options:
00:23openSUSE, Fedora, and Ubuntu, which we'll use for our server.
00:27openSUSE is the fourth most popular distribution according to DistroWatch,
00:32intended to be easily accessible both in terms of acquisition and use.
00:36Variants have been developed since 1994, when it was formally known as SUSE Linux.
00:41openSUSE is a community program sponsored by Novell.
00:44It recently drew criticism from Linus Torvalds for usability issues,
00:48especially around security policies requiring root credentials to perform
00:51everyday operations.
00:53Fedora is a general-purpose Linux distribution.
00:56It's currently the third most popular Linux distribution according to DistroWatch.
01:00The Fedora project was created in early 2003 when Red Hat Linux was discontinued
01:04and split into the community and commercial editions.
01:07Fedora has a very short life cycle of only 13 months perversion.
01:11This can be very disruptive when relying on a specific version.
01:14Ubuntu, on the other hand, does not suffer from the same sorts of issues.
01:18Ubuntu is a fork or derivation of the Debian codebase, focused on features and support.
01:23It's the second most popular distribution only to Mint, a fork of Ubuntu.
01:27It's been around in various forms since 2004.
01:29There is no specific community group behind Ubuntu.
01:33It's sponsored by Canonical, which makes money selling support options for it.
01:37Ubuntu has a very regularly release cycle of 6 months with long-term support
01:41versions being created every two years.
01:44Each LTS server version is supported for five years.
01:47Ease of use, community and commercial support, and popularity are among the major
01:51factors that guided the decision to leverage Ubuntu for our development server.
Collapse this transcript
What is VirtualBox?
00:00Before I answer the question, what is VirtualBox? I'll give you some context
00:04about the concept of virtualization.
00:06Virtualization allows an unmodified operating system with all its installed
00:10software to run in an environment within your existing operating system.
00:13Using this technique, you can install a stock version of just about any
00:17operating system like any other program, instead of taking up an external
00:20resource such as another machine or VPS.
00:23For your purposes, a server- optimized operating system will be used.
00:27Oracle VM VirtualBox is a software package that creates a special environment
00:31that allows you to run a virtualized operating system.
00:34The container, commonly known as a box, is self-contained, meaning it won't be
00:38leaving bits and pieces of itself on your hard drive and the resources it
00:40consumes can be explicitly limited.
00:43As of 2010, it's the most popular virtualization product available.
00:47It's free to use and extremely versatile, making it a logical choice to use for
00:51your development server.
Collapse this transcript
2. The LAMP Stack
Introducing the LAMP stack
00:00Throughout this course, you will be building and configuring what is commonly
00:03known as a LAMP stack.
00:05LAMP is an acronym for a solution stack to build a viable general-purpose web server.
00:09The letters refer to Linux, the operating system in which the server software runs;
00:15Apache HTTP server, the web server itself;
00:18MySQL, which is the database server; and PHP, the scripting language used.
00:23Each of these components are free and open source.
00:26LAMP stacks are very common and can be found on most commercial hosts,
00:30meaning your development environment will be extremely similar, if not
00:32identical, to a hosted solution.
00:35Often, technological needs can be met with multiple solutions.
00:38A LAMP solution stack, while common, is not the only combination of components that
00:42can be used for a web server.
00:43There are lesser known variations of the stack with other programming languages
00:47such as Perl or Python that have the same acronym.
00:50As this course focuses on PHP, there is no need to go into them.
Collapse this transcript
Why we're using Linux
00:00Linux, the operating system that you'll be using, is not the only operating
00:04system that can be used as part of a web server solution stack.
00:07The two most common variants utilize Windows, known as WAMP, and Mac OS, known as MAMP.
00:13The reason this approach is not recommended for local development is that it can
00:16introduce additional variables to your site configuration, and either Windows or
00:20OS X are prepared out of the box for the package management and encapsulation
00:24that is available through virtualization.
00:26This isn't to say that these approaches aren't viable; however, the associated
00:30overhead and potential for compatibility and environmental issues makes them
00:33better suited for very specific configurations.
00:36Additionally, these configurations are not commonly used in production contexts.
00:40Developing in an environment that is similar, if not identical, to production is
00:44optimal for reducing local variations and potentially unforeseen complexities
00:48and complications that may, at best, hinder progress.
00:52In short, it's logical to be consistent between development and production and
00:56to use a tool optimized for your purposes.
00:58So Linux will be the operating system of choice.
Collapse this transcript
Why we're using Apache
00:00There are a number of web servers available.
00:02While Apache is the most common, commanding 64% of the market share according to
00:06NetCraft's March 2012 web survey,
00:08there are other alternatives.
00:10Another free web server, nginx, has a 10% market share.
00:13Ngnix is an open-source web server with a strong focus on high concurrency,
00:18performance, and low memory usage.
00:20When comparing Apache to nginx, Chris Lea succinctly said, "Apache is
00:24like Microsoft Word.
00:25It has a million options, but you only need six."
00:28ngnix does those six things, and it does five of them 50 times faster than Apache.
00:33The nginx stack, known as LAMP, performs extremely well and is easily configured.
00:38However, you will find fewer commercial instances of this configuration and
00:42overall there is less literature available for nginx when compared to Apache,
00:46which will not serve you well if you want to learn more.
00:48For these reasons, I have selected Apache.
Collapse this transcript
Why we're using MySQL
00:00MySQL is a high-performance SQL database management system.
00:04According to MySQL, it's the world's most popular open-source database with over
00:0865,000 downloads per day.
00:11The most common open-source variation of this stack would be PostgreSQL, known as a LAPP.
00:15PostgreSQL is an object- relational database management system.
00:19MySQL is faster, but less full-featured, while PostgreSQL is most comparable to Oracle.
00:24MySQL is easier to use and manage in comparison.
00:28Given the popularity and ease of use, you'll use MySQL for your database.
Collapse this transcript
3. Setting Up the Virtual Machine
Preparing your workstation
00:00We are going to prepare your workstation to interact with a virtual server
00:03that it will be hosting.
00:05First, we're going to create a folder that will be shared between the host and guest systems.
00:09This is where your development files and projects are going to go.
00:12Throughout this course, I am going to refer to the development environment that
00:15we are making as a sandbox, which in computer science refers to a testing
00:19environment that isolates untested code changes from the public.
00:22It's also a good and short name that clearly indicates the purpose of what we're doing.
00:27Create a folder named sandbox in a convenient location, such as your desktop.
00:31As Linux is a case-sensitive operating system, take care to name it in lower-
00:36case to make your life easier down the road.
00:38Next, you will need to make a small change to your networking configuration,
00:42in particular, adding an entry for your local development server to your host's file.
00:47A host file is kind of like a networking address book;
00:49it's the first place that is checked to see what the IP address is for a
00:52particular domain name.
00:53The host file location is dependent on your operating system.
00:57For Windows, it's located in system root, System 32/drivers/et cetera/hosts.
01:03The easiest way to edit is to run Notepad as Administrator and to open the file.
01:07On a Mac the hosts file is located in the et cetera/hosts. Modifying it from the
01:12terminal using sudo nano will be the fastest route.
01:15sudo is a command that means super user do, which is a concept that you'll be
01:19using extensively on your Linux development server.
01:21I'll discuss sudo in greater detail in a bit.
01:24You will only need to add one line to your host file, and for both Mac and
01:28Windows the line is the same: the IP address 127.0.0.1, followed by a space, and
01:35then host name sandbox.dev. Save the file.
01:39In Notepad, go to File > Save; in nano, press Ctrl+X+Y to save.
Collapse this transcript
Creating the virtual machine
00:00If you haven't installed VirtualBox, please do so before proceeding.
00:04We're going to go to New to create a new VirtualBox.
00:07It'll open up a New Virtual Machine Wizard. Click Continue.
00:10We're going to enter a human readable name.
00:12We'll use Sandbox. And for the OS Type we'll select Linux for the operating
00:17system, and for the version we'll use Ubuntu 64 bit, and Continue.
00:23For the memory the default is half a gig of RAM.
00:26This is usually too little. I increase it to 2048, for two gigs of RAM, and click Continue.
00:34Next we're going to create a new start-up disk.
00:37The defaults are fine. We're going to create a new hard disk. Click Continue,
00:40which will open the new virtual disk creation wizard. The file type VDI is fine.
00:45The next question will be whether or not you'd like to have it fixed size or
00:49have it dynamically allocated.
00:51The advantage of using a dynamically allocated disk is that it will only use
00:55space in your drive as it fills up.
00:57It's a one-way path; once it's expanded it won't contract.
01:00And click Continue.
01:02Next, you can select the location where you want to put the virtual disk file.
01:06If you're happy with the default, just click Continue.
01:09You will get a summary of the new virtual disk creation. If you're
01:12satisfied, click Create.
01:14Finally, the New Virtual Machine Summary. Again, if you're happy, click Create.
01:19And now the Sandbox has been created.
Collapse this transcript
Configuring the virtual machine
00:00Next we're going to configure the virtual machine.
00:03Select Sandbox and click the Settings icon. Click Storage.
00:08You will need to specify the server installation medium, so click on the CD.
00:14And over by CD Drive we're going to choose the virtual image and go to Downloads
00:20where we saved image and click Open.
00:26Next we're going to configure the networking, so we're going to go over to
00:29Network, open up Advanced,
00:32and we're going to do port forwarding, which will allow you to access the local
00:35development server from your workstation.
00:38You're going to forward three ports between the guest and the host.
00:41Remember, the host is the operating system that you're in and the guest will be
00:45what is running within VirtualBox.
00:47So go to the Port Forwarding and click the plus icon to add a rule.
00:51The first rule will be for HTTP or Apache.
00:56This runs on port 8080 on your host and port 80 on the guest.
01:02This will allow you to access it using your web browser.
01:05Next, we'll add a rule for MySQL.
01:12The Host Port will use 9306 and for the Guest Port, 3306.
01:18And the final rule will be for SSH. This will allow you to connect to your local
01:23development server like a real server.
01:25Here is the Host Port 2222 and the Guest Port of 22.
01:33One important thing to note is that when you forward these ports to your local
01:36machine, even though they are nonstandard, the ports will be exposed unless you're
01:40firewall blocks them.
01:41Well there is a low probability of a security breach in the circumstance,
01:45especially given the prevalence of routers that do not forward ports to
01:48the outside by default,
01:49it's still important to know.
01:51Consider if you set up a virtual server on your laptop and disable the firewall,
01:55then went to an airport or another public place. Utilize best security practices
02:00and protect your work just like you would with any other program.
02:03Now you are all set. Click OK.
02:06Finally, we'll go to Shared Folders.
02:08I'm going to click the plus folders under the folders list. The Folder Path.
02:14I'll choose the folder, or in this case the Sandbox folder that we created on
02:18the desktop. Click Choose and we're going to select Auto-mount, so every time
02:25that the virtual operating system is booted it will mount this folder, and click OK and OK.
02:32The Sandbox is now configured.
Collapse this transcript
Installing Ubuntu Server 12.04
00:01Next we're going to install Ubuntu. Select Sandbox and click the Start icon.
00:06The first time you do this a warning will appear telling you that the keyboard
00:09has been captured. This means that whatever you would type will be in the virtual machine.
00:13To get out of this mode press the Host key. It will be displayed at the bottom
00:17of this message. By default on Mac this will be the left Command key.
00:20You can safely tell VirtualBox not to show that message again.
00:25The mounted server installation media will now boot.
00:29Select the language for the installer and select Install Ubuntu Server.
00:35Again, we will select the language for the installation and select the location.
00:41For Configure the Keyboard you don't have to detect the keyboard layout. Select
00:45the country of origin and the layout and continue.
00:50For the network configuration it'll ask you for the host name for the system.
00:53We can leave it on the default and continue.
00:56Next we're going to be setting up the first user and password.
00:59Enter your full name and the username for your account. Enter a password and
01:07again to verify. I chose a weak password because this is a development server
01:11and not forward facing, and I wanted something that was easy to remember.
01:15In a production context I would use a much stronger password.
01:19The next question will be whether or not I wish to encrypt my home directory.
01:22I do not wish to do this as this potentially degrades performance and since this
01:26is local to my development machine, it won't be a problem,
01:29so I'm not going to encrypt my home directory.
01:32It'll ask you if the detected time zone is correct. If so, select Yes.
01:37We're going to use Guided use entire disk for the partitioning method.
01:40There is only one choice for the disc to partition.
01:45It'll ask you if you wish to write the changes to the disk. Say Yes.
01:51Now that the base system has been installed, we're going to configure the package manager.
01:55Enter your proxy information for your network or blank for none.
02:01The next question will be how you wish to handle updates.
02:05As this system will not be running all the time, we'll select No automatic updates.
02:09We'll choose the packages that we wish to install now.
02:12We'll install OpenSSH server, which will allow us to remotely administer our
02:16development server, and LAMP server, which will install Apache, MySQL, and PHP.
02:21And go to Continue.
02:24The next step will be to enter a password for the root user for MySQL.
02:28I use root in the context of a local development server.
02:31In production it would be something much more secure.
02:37The next question regards the GRUB boot loader.
02:39It'll ask you if you wish to write it to the master boot record. This allows
02:42you to choose which operating system that you're going to boot on the virtual machine. Say Yes.
02:46On the completion of the installation, you're virtually mounted CD-ROM drive is
02:53ejected, and you can safely continue. This will reboot your machine.
02:59Now that the installation is completed, you can go up to Devices and select
03:04Install Guest Additions.
03:06This will mount the installation CD with the software that facilitates
03:09communication between the host and the guest operating system.
03:13You can minimize the window now.
03:16At this point we've completely configured VirtualBox and completed the
03:19installation of the operating system.
03:20The environment of your server is now ready for customization.
Collapse this transcript
4. Configuring the Server
Logging in using Secure Shell (SSH)
00:00While you can log in to your server using the terminal in VirtualBox, you won't be able
00:04to do things like copy and paste from the terminal.
00:06To get around that limitation we're going to connect to your local development server
00:09using Secure Shell, also known SSH.
00:12Not so coincidentally, this is the same technique that you would use to administer your remote
00:16server. By default SSH runs on port 22. As part of our VirtualBox configuration, you forwarded
00:22the port to 2222 to avoid any potential conflicts.
00:26On OS X, type the following commands from the terminal: ssh followed by -l for login, type
00:32the username that you specify during the installation, then -p for port 2222, and the hostname sandbox.dev.
00:40If you're using PuTTy or another SSH client connect, to sandbox.dev using the username
00:47that you specified on port 2222.
00:50The first time that you'll log in you will be asked if this is a known host.
00:54You will say Yes. And we'll type the password that you specify during installation.
00:59You will get a command prompt, and you're now logged in to local development server.
Collapse this transcript
Working with the command line
00:00Now that you've logged in, let's get acquainted with the Linux environment.
00:03Most commands are named relatively logically, after their usage in English.
00:07The first command I'll show you is man, which is short for manual.
00:11Most commands in Linux are documented in this manner.
00:13To read a manual, type man, then the name of the command.
00:16To navigate you can use the up and down keys, then press Q to quit.
00:20For example, you can use man man to read the documentation on the man command,
00:28and then press Q to quit.
00:31The next command you should learn is ls, which lists directory contents.
00:36By default the results are pretty bare- bones, but combined with the arguments
00:40- la, you will get a comprehensive look into a directory, which by default is
00:45the current directory.
00:47Now that we've seen how to get a directory listing, let's actually change to a directory.
00:51The command to change directories is cd.
00:54Let's change to the system's temporary directory, then list the contents.
00:58cd/var/tmp, ls -la to list the content.
01:05Not a lot to see right now, however, let's go to a more useful directory, the log
01:10files, cd /var/log and ls -la.
01:15This is where many log files live, including the web server and email logs.
01:20If you wish to see the contents of a file, you can use to Concatenate command on a file.
01:25Like the others, the command's name is representative of the use and is a
01:28shortened version, in this case just cat.
01:31One of the files in the log directory is dmesg, which stands for display message.
01:36It's the message bar from the core of the operating system known as the kernel.
01:39These should look vaguely familiar to you, as it was shown during boot.
01:45That's a lot to read in one sitting and often there is no need to see the whole
01:49file, only the beginning or the end.
01:51With log files, the end is usually the most important part.
01:54The beginning and end of a file can be accessed in a simple manner.
01:58The easiest way to remember the commands is to think of a cat again. A cat has a head and a tail.
02:03The head is at the start and the tail is at the end.
02:06Therefore, if you only want to see the first part of a file, you will use the head command.
02:10By default only the first ten lines are shown.
02:14This shows the very first messages that the kernel put out.
02:17Next, look at the end of the file.
02:21Similar to head, the last 10 lines are shown.
02:24Tail has one more trick;
02:25it can actually follow a file, always showing you the last 10 lines in real time.
02:29This is incredibly useful for watching the contents of a log file.
02:33Look at the end of another file, the dpkg log.
02:35This file shows log entries from installing software using the Package Manager,
02:40tail -f, for follow, then dpkg.log.
02:45As there's not a lot going on in the system right now, there is probably not a lot to see.
02:49Tail with a follow argument will be more useful with things like the web server log.
02:52I will get to that in a later chapter. Press Ctrl+C to exit.
02:57The more command is a simple method of allowing a console user to page through
03:01with the contents of a file one screen at a time.
03:04Take another look at dmesg, but this time using more.
03:09Now that you're looking at a file, there are some commands you should be aware of.
03:12Enter will go forward one line. Space will go to the next page. F will go
03:18forward one page. B will go backwards one page. And Q will quit.
03:23sudo is a program that allows you to run programs with the security privileges
03:27of another user. By default this user is root.
03:30The name sudo is the combination of the su command, which allows you to use the
03:34shell of another user, and do, meaning to take action.
03:38Think of sudo like trying to access the backstage of a concert.
03:41If you just try to walk in, the bouncer won't let you get past.
03:44However, if you show them your special sudo badge and say your secret
03:47word, he'll let you in.
03:49To use sudo, just type sudo, followed by the commands that you wish to execute.
03:54Most of the instructions in this chapter require sudo.
03:57Earlier, when I edited the host file on this workstation, elevated privileges
04:01were required, and the sudo command was invoked.
04:03If we try to edit that same file without sudo, it will appear as read only.
04:10Exit and edit the file using sudo for access, and you will have full
04:19write permissions.
Collapse this transcript
Upgrading and installing packages
00:00Ubuntu uses the Advanced Packaging tool known as APT to handle the installation
00:04and removal of software.
00:06Since the initial publication of Ubuntu 12.04, security updates, bug fixes, and
00:11enhancements have become available;
00:13therefore you'll update the packages that were on the installation CD using apt-get,
00:17the command line's tool in APT for managing packages.
00:20First you'll update the list of available software. sudo apt-get update.
00:30Next, you'll update all the currently installed packages.
00:33You'll pass the argument -y to the upgrade command, to automatically say yes to any prompt.
00:38If you want to get a chance to see what's going to happen before it
00:40executes, leave off the -y.
00:42sudo apt-get -y upgrade.
00:46While Ubuntu comes with a vast majority of the software that you'll need,
00:53there is a couple of extra tools that will need to be installed.
00:55You'll use the apt-get command again, this time passing both -y and -q as arguments.
01:00y will say yes to any prompt and q will minimize the amount of stuff displayed
01:04to you during the installation.
01:06The first four packages are required for VirtualBox Guest Additions,
01:09the connection between Linux, the guest operating system, and your host operating
01:13system, in particular the shared folder.
01:16The packages required for VirtualBox Guest Additions are build-essential, common
01:20tools used for compiling software; module-assistant, and a tool for managing
01:24kernel module packages; linux-headers, which are the Linux kernel headers--we'll
01:29use a shorthand to install the version currently installed using uname, which
01:32plans system information; and dkms, the Dynamic Kernel Module Support,
01:38a framework which allows kernel modules to be dynamically built for each kernel
01:42on your system in a simplified and organized fashion.
01:45Next, you'll also include the commands for dealing with a common file
01:48archive format, zip:
01:50zip, which packages and compresses or archives files, and unzip which lists tests
01:55and extracts compressed files in a zip archive.
01:58The final command will read as follows: sudo apt-get -q -y install
02:06build-essential module-assistant linux -headers-$(uname -r) dkms zip unzip.
02:23Occasionally, when you're typing a command, you might get something off by just a
02:26little bit. You can use the arrow key up to display the last command; use the
02:31arrow key left to move your cursor; and in my case I missed the letter S, so
02:37just type s and press Enter.
02:41The packages are now installed.
Collapse this transcript
Installing VirtualBox Guest Additions
00:00Now that you've installed all the requirements, you can install the guest additions.
00:04Earlier, you told VirtualBox to make the guest additions installation available
00:07on your guest operating system.
00:09These guest additions will set up a shared folder between the guest and
00:12host operating system.
00:13On your Linux server the folder will be /media/sf_sandbox.
00:18I'll go into greater detail about this directory later on.
00:21You'll use the command mount, which will attach the file system found on a
00:25particular device to the file tree.
00:27First you'll use sudo for the elevated privileges, give the mount command,
00:33followed by the device that you wish to mount, /dev/cdrom, and the destination in
00:41the file system, /media/cdrom.
00:45Next you'll execute the installer, including the arguments that indicates that
00:49the installation will take place from the command line and not in any Windows system.
00:53Despite this you get a warning about Windows system drivers.
00:56It's a long-standing minor bug that is safe to ignore.
00:59So sudo for elevated privileges, sh /media/cdrom/, and the next part is going to
01:09be a little bit long, but we're going to use a shortcut.
01:10When using a command line in Linux you can type the first couple letters,
01:15capital VB, lowercase ox, uppercase L and then press Tab and it'll
01:20complete the Command, space--nox11. nox11, that means don't install anything
01:30for the Windows system.
01:31Press Enter and it will complete the installation.
01:36As previously stated, the Windows system drivers are not applicable.
01:39This error message can be safely ignored.
01:42The VirtualBox Guest Additions have now been installed.
Collapse this transcript
Configuring the Apache web server
00:00To facilitate interactions between the host operating system, the web server, and
00:04your Linux user, you'll need a little glue.
00:06First add your user to the VirtualBox group, which will give you the same
00:10permissions as the VirtualBox Guest Additions, and in particular to any
00:13folders that are shared.
00:15To do that you'll use the usermod command, which modifies system account files.
00:19This is not something you'll be doing often.
00:21In this instance, you're adding the user jpeck to the group vboxsf. sudo usermod
00:28-a -G for the group, vboxsf and then jpeck, the user.
00:35Next, you'll add to the Apache web server user to the VirtualBox group.
00:39This will allow the web server to make changes to the shared files. sudo usermod
00:45-a -G vboxsf www-data.
00:51URL rewriting is an extremely common technique for improving the ease of use and
00:55search friendliness of an application.
00:58The Apache component, known as a module, is off by default.
01:01We'll execute the Apache command to enable the module. a2, short for Apache2;
01:08en, for enable; mod, for module; followed by a space and the module name, in this case rewrite.
01:16You'll also need to tell the web server where you shared folder is and
01:19what domain to use.
01:20To do that, you'll need to make a new site configuration.
01:23We're going to use the text editor nano to edit the file.
01:26There are many text editors available, but nano is, admittedly subjectively,
01:30the easiest to learn.
01:31You can move your cursor around using the arrow keys and to exit press Ctrl+X
01:35and follow the prompt.
01:37You'll pass an additional argument, -w, to disable wrapping of long lines. sudo
01:42nano -w /etc/apache2/sites-available/sandbox.
01:51You can copy and paste the contents of the free exercise file to save you time.
01:55Exit, Ctrl+X and save the file press Y. It will ask you which file to
02:00write. Press Enter. Then enable the site configuration using the Apache
02:04command, a2ensite, Apache2 enable site, and then the name of the site that
02:10you wish to enable, sandbox.
02:13Apache will give a minor error until you give it a proper name.
02:16While it can be safely ignored, it's best practice to properly configure your system.
02:20The solution is straightforward:
02:22specify the server name in the Apache web server configuration.
02:25We're going to create the Apache configuration with the following command: sudo
02:29nano -w/etc/apache2/httpd.conf.
02:37I'm going to specify the server name where this server name directive.
02:41You can name it anything you want, but development helps reinforce the idea that
02:44this is a development server and not intended for a production environment.
02:47ServerName development.
02:51Ctrl+X, and Y, and Enter.
02:56PHP does not log errors out of the box.
02:58To make the change, you'll need to edit the PHP configuration. Type sudo nano -w
03:04/etc/php5/apache2/php.ini.
03:12I'm going to press Ctrl+W to search.
03:14I'm going to look for error_reporting =.
03:21We're going to change the values for error_reporting from the production value
03:24by pressing Delete and switch it to the development value, E_ALL | E_STRICT.
03:35Next, we're going to search for display_ errors =, and we wish to switch it to On.
03:44Next we're going to look for log errors, log_errors =, verify that it is on.
03:52Next, we're going to look for log_errors_max_length. By default it is 1024.
03:57We'll change it to zero, which has no limit on it whatsoever.
04:01Finally, we'll look for error_log =.
04:06We'll add a new line here, error_log =, and we'll log to our share directory, so
04:13/media/sf_sandbox/php_errors.log.
04:21Hit Ctrl+X to exit, and save.
Collapse this transcript
Configuring the database server
00:00The configuration is almost complete.
00:02The final step is to tell the MySQL database server where to listen for connections.
00:06By default, it only listens to 127.0.0.1, which is the local machine.
00:12As you want to be able to access the database server from the host operating
00:15system for easy management and debugging, you'll allow connections from any IP.
00:20Remember, this configuration is for your local development server, so the only IP
00:23that we'll actually be connecting to it will be your own.
00:26Edit the MySQL configuration by issuing the following command: sudo nano
00:31-w /etc/mysql/my.cnf. And we're going to look for bind-address. Currently
00:41it's 127.0.0.1. We're going to change it to 0.0.0.0. Ctrl+X to save, and the database
00:51is now configured.
Collapse this transcript
Installing the Exim email server
00:00Many common transactions send emails, especially if you're working with a
00:03content management system or framework;
00:05therefore, you'll need to install a mail server.
00:08Exim is an open-source, lightweight mail transfer agent, or MTA.
00:12You don't need to set up a whole mail server; you just want to be able to send email.
00:15Since we're not sending any emails to the public, you can use any email account
00:20that has SMTP support.
00:22Gmail accounts support SMTP so I'll use Gmail as an example.
00:25This technique will also work with Google Apps for domains.
00:28First install Exim using apt-get. sudo apt-get -y install exim4.
00:37Next, you'll configure Exim.
00:39There are only two changes that you need to make. sudo
00:42dpkg-reconfigure exim4-config.
00:49For the general type of mail configuration, we wish to select mail sent by
00:53smarthost received via SMTP or fetchmail.
00:56For the System mail name we can leave ubuntu and over to Ok.
01:01For the next step for IP addresses to listen on for incoming SMTP connections,
01:06you can leave it as is.
01:08For the other destinations for which mail is accepted, you can leave it as is.
01:13Machines to relay mail for, again, leave it as is.
01:17The IP address or host name for the outgoing smarthost we're going to change to
01:21smtp.gmail.com::587.
01:29Do we wish to hide the mail name in outgoing mail?
01:32No we do not. And we do not wish to keep the number of DNS-queries minimal, and
01:37the delivery method we can keep as default.
01:39We do not wish to split the configuration.
01:43The email configuration is almost complete.
01:45The last step is to add your email username and password to the Exim
01:49configuration to allow the sending of email.
01:51So sudo nano -w /etc/exim4/passwd.client. And we're going to add the
02:02following name and save.
02:04*, that means an email, USERNAME, replace this with your actual username,
02:12@gmail.com, followed by PASSWORD, which will actually be your password.
02:18Hit Ctrl+X, Y to save, and now that we've made all our configuration changes,
02:24you'll need to reboot the server.
02:26Rebooting isn't necessary for the web server or database server;
02:29you can just reload the configurations without rebooting.
02:31With that said, VirtualBox Guest Additions does actually require it, so you can
02:36give the following command: sudo reboot.
Collapse this transcript
5. Building a Simple LAMP Web Site
Introducing phpMyAdmin
00:00Now that both the virtual machine and server have been configured, let's fully
00:03exercise the system to ensure that everything is working properly.
00:07The first thing you'll do is use phpMyAdmin, which utilizes every component of a LAMP stack.
00:11phpMyAdmin is a free and open-source PHP tool for facilitating MySQL management
00:17using a web browser. It's a very useful tool for debugging database-driven
00:21applications, writing queries, and managing databases.
00:24In a production environment, it can be a liability if not properly secured.
00:29As we're only going to be using it on a local development server,
00:32you could be much more lenient about the security.
00:34Install phpMyAdmin using apt-get. sudo apt-get -y install phpMyAdmin.
00:46As part of the installation, you'll be taken into a wizard.
00:49We're going to select Apache2 as the web server to reconfigure automatically
00:53because that's what we have installed.
00:57It's going to ask if we wish to configure the database for phpMyAdmin. Say
01:01Yes. The password for the database's administrative user is root, and we can leave this blank.
01:08It will generate a random password for phpMyAdmin's user.
01:13Next you'll configure phpMyAdmin to automatically log in.
01:16This is not something you should ever do in a production environment,
01:20but for local development server, it's safe.
01:23We'll edit the phpMyAdmin configuration, phpmyadmin/config.inc.php.
01:33We'll navigate to the line that reads Authentication type.
01:38Currently, it says cookie.
01:39We're going to change it to config.
01:42That means we're going to hard code the configuration.
01:44We're going to add two more lines: cfg Servers $i, the user is root, then cfg
01:59servers $i password = root. Exit and save.
02:06phpMyAdmin can be accessed with your web browser at the following address
02:11http://localhost:8080/phpmyadmin. You'll see a list of databases on the left.
02:23Click phpmyadmin to see the empty tables that were created as part of the
02:28installation process.
02:29You'll notice that the left side now shows the select list followed by table names.
02:33You can select a different database using that select list. Select mysql now.
02:39Let's write a raw query to see how phpMyAdmin formats results.
02:43Click the SQL tab and then type the following: Select * FROM mysql.user.
02:52Click Go to execute the query.
02:54phpMyAdmin will execute the query and show you the result in a nice HTML table,
02:59complete with controls to edit.
03:01Next click the table name db on the left.
03:04You'll see the contents of the db table formatted in a similar matter with
03:08different columns and contents.
Collapse this transcript
Creating a new database and a user
00:01You can use phpMyAdmin to create your first database and user.
00:04Click on localhost and click on the Privileges tab, then click Add a new User.
00:11Under Login Information, we'll put in user name sandbox.
00:15For the Host we'll leave as any host. For the Password sandbox and Re-type the Password.
00:24For the Database for user, we're going to create a database with the same name
00:27and Grant all privileges. Click Create User.
00:30You'll see the new user in the User overview.
00:34You can use these credentials in your application.
00:37One more change will be needed.
00:39We'll need to explicitly add localhost to the host that the user can log in from.
00:43Click on Edit Privileges. Then scroll down to the Change Login Information.
00:48Under Host we'll select Local, and we're going to keep the old one and just click Go.
00:56And we can close the window and you'll see that sandbox can log in from any
01:00host and localhost.
01:02Let's create a table in the newly created database. On the Databases tab, click on
01:09sandbox, and let's create a new table called test. And we are going to have two
01:16columns in this test table. The first column we'll call test ID.
01:22This will be AUTO INCREMENTING in a PRIMARY key.
01:26We'll add a second column called content, and we'll make this a Text type.
01:33Scroll down and Save.
01:35The table has now been created.
01:37Click on the table name.
01:39You'll see that MySQL returned an empty result set because there is no content.
01:43So let's create some test content now.
01:45Click on the Insert tab and in the first content text area we will type "Hello,
01:50lynda.com" and click Go.
01:55Now if you go back to the Browse tab, you'll see our new row.
Collapse this transcript
Connecting to a local database
00:00In your IDE, your text editor, create a new file in your Sandbox folder called index.php.
00:09This will be our first test script.
00:11Remember, this course is about teaching you how to set up a local development
00:15server, not how to program;
00:16therefore, this script will be very simple.
00:18It will connect to the test database, pull the content out, and display it to the user.
00:23On success, it'll display you an email.
00:25If there is a failure, it will display that failure to you.
00:28You can paste the script for the free exercise files.
00:34Next, open up your web browser.
00:36If you see the content displayed, the database connection was successful.
00:40If you do not, please refer to the later troubleshooting chapter.
Collapse this transcript
Installing WordPress
00:00WordPress is a free and open source blogging tool and content management system
00:04that uses PHP and MySQL.
00:06It's currently the most popular CMS in use on the Internet.
00:10Change directory to the shared folder.
00:15And to download WordPress, we're going to use wget.
00:23For more information on wget, use the man command.
00:30Now, extract the archive.
00:34That's all we need to do from the command line.
00:36Let's open the browser. Here in the browser we'll go to
00:40sandbox.dev:8080/wordpress/wp-admin/ install.php, and we're going to tell it to
00:52create a configuration file.
00:53We will click Let's go! The Database Name
00:58we'll change to sandbox; User Name, sandbox; Password, sandbox;
01:05the host, its local host; and the Table Prefix as wp can be kept. Click Submit
01:12and then Run the install.
01:13For the Site Title I'll type Sandbox. The Password will be admin, and repeat it
01:23again for confirmation.
01:24This is a weak password. This is not something that you should use in a
01:27production environment.
01:28Add your email and click Install WordPress.
01:36WordPress has been installed, click Log In, admin and admin, Remember Me, and Log In.
01:45And WordPress is now been installed.
01:47For more information on customizing WordPress, check out the WordPress courses
01:51here in the lynda.com online training library.
Collapse this transcript
Installing Drupal
00:00Drupal is a free and open source content management system and content
00:03management framework written in PHP.
00:06It can be configured to use MySQL and can be used to build many different
00:09kinds of web sites.
00:11Change directory to the shared folder.
00:16Download the installation archive using wget. We are using version 7.14.
00:25For more information on the wget command, type man wget.
00:30Extract the archive. Open up your web browser.
00:35We'll use the standard installation profile, and English is the language.
00:40The Database name, we'll use sandbox; the Database username, sandbox; and password
00:49sandbox. And click Save and Continue.
00:53Now we're going to configure the site. For the site email address, enter your
00:57username. For the site maintenance account we're going to use the username
01:03admin, the email address user@example.com, password admin, and we'll confirm the password, admin.
01:13Default country, we use United States. Default time zone was detected correctly.
01:19And we will hit Save and Continue.
01:23Drupal is now installed.
01:24We'll visit the newly installed site.
01:26Part of the Drupal installation will be to log you in as the administrator.
01:30For more information on customizing Drupal, check out the Drupal courses here in
01:34the lynda.com online training library.
Collapse this transcript
Installing Symfony
00:00Symfony is an MVC web application framework written in PHP, released under the MIT license.
00:06It can be used as a foundation to build anything from small programs to
00:09enterprise-grade applications.
00:11Change directory to the shared folder. cd /media/sf_sandbox. Download Symfony.
00:19We will use the wget command, Wget, space,
00:22http://symfony.com/download?v=Symfony_ Standard_Vendors_2.0.13.zip -O, for output,
00:42and then the file name, symfony.zip.
00:45If you are interested in learning more about wget, type man wget. Extract to the
00:51archive, unzip symfony.zip.
00:54We are going to need to make some PHP configuration changes for Symfony.
00:58First we'll disable short open tags.
01:00We will need to edit the PHP configuration, which is a core configuration file, so
01:04administrator privileges are needed.
01:07Type sudo nano -w /etc/php5/apache2/php.ini.
01:16We are going to press Ctrl+W to search within the file.
01:20We'll search for short_open_tag =.
01:26You see the default value is On.
01:28We wish to change it to Off.
01:30While you are in there, you will need to set the time zone with something from
01:33the list of PHP's supported time zones. Look for date.timezone.
01:38We will use America/Los_Angeles.
01:43I am going to save and exit.
01:46Next, we will need to install some software dependencies. sudo apt-get -y to say
01:52yes to any prompt, install php5-sqlite php5-intl php-apc.
02:04Ensure that the new configuration is loaded in Apache by restarting it. Type
02:08sudo service apache2 restart.
02:13If you were to execute nano now, you would see an error message about access
02:17denied to the nano history.
02:18This happens because the root user executed nano and the history was written
02:21with root user privileges.
02:23To prevent this from happening, we are going to execute two commands.
02:27The first command will change the file permission to allow anyone in the group
02:30to write to the file and anyone to read it.
02:32I am going to sudo chmod 755 ~ /.nano_history.
02:40The second command will change the ownership of the file back to your user. sudo
02:44chown jpeck:jpeck, replace that with your username, ~/.nano_history.
02:55Finally, you will need to make some configuration changes.
02:57By default, the configuration script will only allow access from the local host.
03:02As we are connecting from the guest operating system, you will need to comment
03:05out those lines to be able to continue. Type nano -w Symfony/web/config.php.
03:14We'll look for the header and exit lines and comment them out.
03:18Hit Ctrl+X, Y to save, Enter, and that file is complete.
03:24We are going to have to do the same to the Symfony web app dev file, so nano -w
03:31Symfony/web/app_dev.php.
03:37Look for the header and exit lines and comment them out.
03:40Ctrl+X, Y, Enter, and the file is now saved.
03:45From your web browser, click on Configure your Symfony Application online.
03:54The Driver is set correctly.
03:55We are going to want to change the Name to sandbox, the User to sandbox, the
04:01Password to sandbox, and the Password again to sandbox, and click Next Step.
04:09The Global Secret key is fine.
04:11It's already been generated. Click Next Step and the distribution is now Configured.
04:16Go to the Welcome page and run the demo. Hello World works, which verifies the
04:24Symfony configuration.
Collapse this transcript
Installing Zend Framework
00:00Zend Framework is an open source, object-oriented PHP5 web
00:04application framework.
00:05It can be used to rapidly develop applications, leveraging built-in cogeneration
00:09utilities and a flexible architecture.
00:12To install, change the directory to the shared folder. Sownload Zend Framework.
00:18We will use wget.
00:20http://framework.zend.com/releasses/ ZendFramework-1.11.11/ZendFramework-1.11.11-minimal.zip.
00:44For more information on the wget command, type man wget.
00:48Next, unzip the archive.
00:52In a production environment, you'd want to put the Zend Framework library out of the web root.
00:57For local development, it's helpful to have access to the library.
01:00Optionally, PHP unit can be installed at this time.
01:03PHP unit is a unit testing framework for writing automated PHP tests and
01:07analyzing the results.
01:09Zend Framework leverages that library and can generate test skeletons as part
01:13of project creation.
01:14To install PHP unit, you will use the PHP Extension and Application Repository
01:19installer, which is specific to PHP libraries.
01:22You will need to install the PEAR application first.
01:24Fortunately, apt supports it. sudo apt-get install php-pear.
01:31Next, allow PEAR to find and install any dependencies that it needs. sudo pear
01:36config-set auto_discover 1.
01:41Then update the list of available software. sudo pear
01:45channel-discover pear.phpunit.de.
01:50Finally, use PEAR to install PHP unit. sudo pear install
01:56pear.phpunit.de/PHPUnit.
02:02Next, use the ZF command line's tool to create the project.
02:06You use the command to create project and specify the relative path to the sandbox.
02:10The project will then be created. ZendFramework-1.11.11-minimal/bin/zf.sh
02:17create project zf-sandbox.
02:22You need to install the Zend Framework library in the newly created project.
02:25Unfortunately, you cannot create a symbolic link to the Zend Framework library
02:29due to a limitation of VirtualBox.
02:31Instead, you can make a recursive copy of the Zend library, cp -R
02:36/media/sf_sandbox/ZendFramework-1.11.11- minimal/library/Zend, and we are going to
02:46copy it to zf-sandbox/library.
02:51This completes the installation.
02:53You can now open your web browser. Fo to
02:55http://sandbox.dev:8080/zf-sandbox/public/.
Collapse this transcript
Installing CakePHP
00:00CakePHP is an open-source web application framework that is loosely modeled on
00:04Ruby on Rails, complete with code scaffolding and generation.
00:08It can be extremely useful for rapid prototyping.
00:11To install CakePHP, change directory to the shared folder.
00:17Next, download CakePHP.
00:19We will use the wget command, wget
00:21https://github.com/cakephp/cakephp/ zipball/2.1.2. We will use the -O to specify
00:38output to a particular file name.
00:40We will use cakephp.zip.
00:44For more information on the wget command, type man wget.
00:49Unzip the archive. Unzip cakephp.zip.
00:54Change to the directory.
00:55You can use tab completions so you don't have to type out the entire directory name.
01:00Copy the default database configuration to database.php, cp
01:04app/Config/database.php. default to app/Config/database.php.
01:15Next, we will edit the database configuration file.
01:20Config. We are going to look for public $default.
01:27We are going to change the login to sandbox, the password to sandbox, and the
01:39database to sandbox.
01:44Press Ctrl+X to save and exit.
01:47Next, make the security customizations to the application configuration. nano -w
01:52app/Config/core.php.
01:58You need to change both the Security.salt and the Security.cipherSeed.
02:03The salt can be a combination of letters and numbers, while the cipherSeed is digits only.
02:07You can make these anything you want, the longer the better.
02:13As this is a development environment, you can just use sandbox for the salt,
02:1712345 for the cipherSeed, which is the same password as my luggage.
02:23When you're complete, save and exit.
02:26Finally, you can open the application root in your web browser.
02:31CakePHP is now successfully installed.
Collapse this transcript
6. Troubleshooting
Troubleshooting Apache
00:00There are a number of ways that you can troubleshoot the Apache web server.
00:04For this demonstration, I am going to start off by intentionally disabling the
00:07web server using the following command, sudo service apache2 stop.
00:14When you attempt to access the sandbox with your web browser at
00:17http://sandbox.dev:8080/, you will not see anything.
00:27Start the web server again. sudo service apache2 start. Reload the page.
00:36You should see the same demonstration content from earlier.
00:39Next, try to access localhost at the same port: http://localhost:8080.
00:48You should see, It works!
00:50If you do, then your web server is running.
00:52If you don't see the test content that we created, but you can see the It works!
00:56page, the configuration is wrong.
00:59Take a look at the log files for Apache.
01:01From the command line, change directory. cd /var/log/apache2.
01:10Display all the files in the directory, then start the sandbox.
01:13We are going to specify the name sandbox.*, which will match any file that begins
01:18with sandbox. ls -la sandbox.*.
01:24You will see several logs. Of interest, sandbox.dev-access.log and
01:29sandbox.dev-error.log.
01:32You can tail -f any of these logs to watch them in real time. Tor page views,
01:37tail -f sandbox.dev-access.log.
01:43Now if we open up the web browser and go to sandbox.dev:8080, you will see, a new
01:51line has been added to the log.
01:53For Apache errors, we are going to tail -f sandbox.dev-error.log. And we are
02:03going to enter in an invalid URL. And again, we will see that an additional line
02:09has been added to the log.
02:11If you aren't sure that Apache is running, you can execute the following
02:15command: ps aux, which reports a snapshot of the current processes, pipe it to
02:21grep, grep apache, which matches text.
02:26You should see a number of Apache processes.
02:28If you don't, Apache isn't running.
02:31If there are configuration errors, they will be displayed when you attempt to
02:34restart the web server. Type sudo service apache2 restart.
02:41If Apache is running, make sure that it's listening for connections.
02:45We are going to use the netstat command. Type sudo netstat -nap and pipe
02:53again to grep apache.
02:57You should see that Apache is listening on any IP on port 80.
03:01If it isn't, then you can check to see if something is conflicting.
03:04Type sudo netstat -nap and pipe it to grep :80.
03:13If you see multiple lines then you can identify what the other process is
03:16listening on port 80, by looking in the right column.
03:20If you want any more information about the commands used in this part, use the
03:24man command to read their manuals.
Collapse this transcript
Troubleshooting MySQL
00:00By default, MySQL does not log transactions or problems.
00:04To enable logging, a configuration change is needed. Type sudo nano
00:10-w /etc/mysql/my.cnf.
00:14We are going to search for, in brackets, mysqld.
00:19Beneath that, add the following lines: log-error=/var/log/mysql/mysql-error.log.
00:32The next line for general logging will log every query that is made.
00:36This can potentially slow down the system and will get extremely large,
00:39so only do this if you need to. log=/var/log/mysql/mysql.log.
00:48Next, we are going to log slow queries.
00:50This is very useful when looking for performance bottlenecks.
00:53First, we will specify the threshold for long query duration, long_query_time=1.
01:01Next, log-slow-queries=/var/ log/mysql/slow-queries.log.
01:13You can optionally log queries that do not have indexes.
01:16This has the potential to log a large number of queries, so only do this if
01:20you are looking to do a lot of optimizing. log-queries-not-using-indexes. Save and exit.
01:29Now restart MySQL. sudo service mysql restart.
01:37Take a look at the general MySQL log and open a phpMyAdmin window. tail -f
01:42/var/log/mysql/mysql.log. http://localhost:8080/phpmyadmin.
01:57As you can see, every query is logged in a verbose format.
02:01If you're having database errors, take a look at the MySQL error log, tail -f
02:06/var/log/mysql/mysql-error.log.
02:15If you're not sure that MySQL is currently running, execute ps aux | grep mysql.
02:24If the service isn't running, try restarting it. sudo service mysql restart.
02:32Next, try connecting to MySQL from the command line. mysql -u for the
02:38username, which in this case is root, followed by a space, -p for password, which is also root.
02:47You should get a mysql command line.
02:49You can leave by typing exit.
02:51If you attempt to connect to a server that isn't running, you'll get a verbose
02:55error message. mysql asdf.
02:58If mysql is running but you can't connect to it, see if it's listening to port
03:023306. sudo netstat -nap | grep mysql.
03:10If you want any more information about the commands used in this part, use the
03:13man command to read their manuals.
Collapse this transcript
Troubleshooting PHP
00:00Often, most problems are not with PHP itself but with a web server.
00:04With that said, there are a number of steps that you can take to gain more
00:07introspection into your PHP configuration.
00:10You can check the version of PHP installed from the command line. Type php --version.
00:16Additionally, you can use the php --info command to see configuration details
00:22for your version of PHP.
00:24There are two distinct configurations: one for the version that Apache uses and
00:28one for the command line.
00:30If you wish to see the PHP configuration for the web server, use the phpinfo
00:34function call. Open up the test script, add phpinfo, followed by exit.
00:43Open your browser and navigate to http://sandbox.dev:8080.
00:49This is the web server's PHP configuration.
00:52Go back to your script, remove the phpinfo function call, and replace it with an
00:58artificially introduced error. Save the file, then open up the web browser, and
01:03reload the page. The error will be displayed to you.
01:07When you configure PHP, you set up the error log to log only PHP errors to the
01:11shared folder so any errors will be written to that file.
01:14Open up the terminal and watch the file from the command line, by typing tail -f
01:18/media/sf_sandbox/php_ errors.log. Reload the page.
01:27You'll see the new error appear in the log.
01:31This can be useful for postmortems, or if you get the infamous white page of
01:34death, which is usually a PHP fatal error.
Collapse this transcript
Troubleshooting Exim
00:00In this configuration, exim should be stable and not prone to errors.
00:04However, there are times when you want to see if there are any problems with the
00:07configuration or the server.
00:09First, check to see if the exim process exists. Type ps aux | grep exim.
00:17If it is not running, try restarting the process. Type sudo service exim4 restart.
00:25If it is running, check to see if exim4 is listening for connections. Type sudo
00:30netstat -nap | grep exim.
00:36You should see exim on port 25.
00:39The exim log files are located in /var/log/exim4.
00:42You can watch the main log file by using the following command: sudo tail -f
00:47/var/log/exim4/mainlog.
00:53If you send an email and you see that it's been sent in a log, but you are not
00:57receiving it, check your spam folder. Depending on the content or frequency of
01:00the email, it may have been filtered out.
01:02Let's send a test email now.
01:04Open up your web browser and navigate to http://sandbox.dev:8080.
01:10If you look at the exim log, you will see that an attempt to send an email to
01:16user@example.com has been made.
Collapse this transcript
7. Enhancing the Web Server
Installing Webmin to monitor your server
00:00The following segments contain instruction on how to set up optional enhancements
00:04for your development server.
00:05They include web-based system administration, logging in without a password, and
00:09remote database interaction with a graphical user interface.
00:12Webmin is a web-based system administration interface which will allow you to
00:16manage Apache, file sharing, user accounts, and more.
00:20It's extremely powerful and easy to use, but at the same time it can be
00:23considered a security liability.
00:25You should never use Webmin in a production context, as it allows root logins
00:29through a web browser.
00:31There are few software requirements that need to be met.
00:34You can use apt-get to install them.
00:36Type sudo apt-get install -y perl libnet -ssleay-perl openssl libauthen-pam-perl
00:50libpam-runtime libio-pty-perl apt-show-versions, and python.
01:03Next download the Webmin package using the wget command. wget
01:07http://prdownloads.sourceforge. net/webadmin/webmin_1.580_all.deb.
01:23For more details on wget, type man wget.
01:27Next, install the Webmin package. sudo dpkg --install webmin, and press Enter.
01:37A small configuration change is needed. By default webmin uses SSL.
01:41However, as the certificate provided by Webmin is self-signed, some browsers
01:46will not accept it.
01:47As a workaround, you can connect over an unencrypted connection. Type sudo nano
01:52Space -w /etc/webmin/miniserve.conf.
02:00We're going to look for SSL and change it from 1 to 0. Save and exit.
02:06You'll have to restart Webmin for the configuration change to take effect. sudo
02:11/etc/init.d/webmin restart.
02:16Webmin runs on a nonstandard port.
02:18You'll have to forward the port to be able to access it.
02:21Open up VirtualBox, select Sandbox and go to Settings. Go to Network > Port
02:28Forwarding, and we'll add a new rule.
02:30Click Insert a new rule, Webmin, Host Port, 10,000, and same for the Guest
02:39Port, 10,000. Click OK.
02:43That's known bug. Click OK and OK.
02:47Open up your browser and navigate to http://local host:10,000.
02:56It'll ask you for your username and password. Enter them now. Check Remember
03:02login permanently if you'd like and log in.
03:05Feel free to explore. For additional documentation see webmin.com.
Collapse this transcript
Using SSH without a password on Windows
00:00Instead of using a password, you can use the key file to log directly into your system.
00:05For Windows you can use free utilities to facilitate this process.
00:08Download puttygen.exe from the PuTTY homepage. Then run it.
00:14In the Parameters section, choose SSH-2 DSA. Then click Generate to create a
00:20public-private key pair.
00:22Generate some entropy by moving your mouse back and forth.
00:25If you wish to enter a pass phrase, do so now.
00:28Click Save public key, public_key, and click Save private key. Are you sure?
00:35Yes, private_key. Then copy the content of the public key, load up PuTTy, and
00:45connect to the Sandbox.
00:47Type your password, now create the SSH directory, mkdir Space -p .ssh.
00:56Next, edit the contents of the authorized keys file. nano -w .ssh/authorized_keys.
01:06Paste the contents of the file Ctrl+X, Y to save, and enter, and log out.
01:13Download and run pageant. By default it runs in the system tray. Right-click on
01:18it and go to Add Key. Select your private key. It makes the key available to any
01:24other PuTTY process. Double-click putty and let's go to the Sandbox again.
01:30And you see that it does not ask for a password anymore.
01:33Now when you run PuTTY you'll be able to log directly into your system.
Collapse this transcript
Using SSH without a password on Mac
00:00Instead of using a password, you can use the key file to log directly into your system.
00:05For Mac OS this is a fairly straightforward process.
00:08From the local terminal--not within your development server--type the following.
00:13Type ssh-keygen -t rsa -C, and then in quotation marks your email address.
00:24It'll ask you to enter a file. Use the default.
00:32The next section about a pass phrase begs a bigger question: Are you going to be
00:36using key to authentication for any server other than your local development
00:39server? If no, then you can leave the passphrase blank.
00:43Next, you'll want to copy the public key to your development server. ssh -p2222,
00:51then your username @sandbox.dev, then the command mkdir -p.ssh.
01:02It'll ask you for your password.
01:05Now we're going to copy the contents of your public key to the development
01:09server, cat ~/.ssh/id_rsa.pub. We're going to pipe it to SSH, ssh -p2222. For the
01:23port, your username @sandbox.dev. Then in single quotes 'cat
01:29>>.ssh/authorized_keys' end quote.
01:38It will ask me for my password again.
01:41You can now log directly into your server, ssh -p2222 jpeck@sandbox.dev.
01:51If you're tired, like me, of specifying the port from the command line there is a better way.
01:55We can create configuration for SSH. Type nano -w ~/.ssh/config.
02:05I'm going to create a new host, Host sandbox, two spaces, HostName sandbox.dev
02:12space, space, Port 2222, User and then your username. Save and exit.
02:21You can now just type ssh sandbox.
Collapse this transcript
Using a MySQL client with your database
00:00One of the ports that you forwarded during the VirtualBox configuration was for MySQL.
00:05If you use a MySQL client, you can connect to your virtual development server
00:08using that forwarded port.
00:10As a demonstration, I've selected Sequel Pro from sequelpro.com.
00:14It's a free MySQL database management tool for Macintoshes.
00:17For Windows, the free MySQL and Microsoft SQL client HeidiSQL, from heidisql.com,
00:25will allow you to manage your database.
00:27In particular, the information that you need to connect to your database
00:30remotely is, for the Host, sandbox.dev; for the Username, sandbox; and the Password, sandbox.
00:38For the Port, we'll use the forwarded port, 9306, and click Connect.
00:46You can select a database and see the contents.
00:51I find it convenient to use a database client for importing and exporting data
00:54rather than using the command line.
Collapse this transcript
Conclusion
Managing the server
00:00As your local development server is virtualized, it's running like a program.
00:04As such, it's not going to automatically start or shut itself down.
00:08There's a couple of different ways you can do that.
00:10You can shut down the server using SSH.
00:12This is the preferred manner, as it ensures that everything shuts down properly,
00:15especially the database.
00:17Type the following command: sudo shutdown -h now.
00:22It'll ask for the password.
00:25This will shut down the server gracefully.
00:27Now you can restart it from the VirtualBox Manager by double-clicking on the
00:30name. And you can log back in.
00:36If you needed to reboot in order to allow for a program installation or resolve
00:40an issue, you can use the reboot command. sudo reboot.
00:44It will ask for the password and the machine will gracefully reboot.
00:51You can also suspend the VM, which is a very nice feature.
00:54It saves the state, allowing you to resume from exactly from where you left off.
00:58This can be shorter than doing a full boot, and you can also revert to
01:01a particular state.
01:02To suspend a VM, open the VirtualBox window containing the VM and click the Close button.
01:09You'll be prompted for an action. Choose Save the machine state. The VM will be
01:13listed as saved, in the list of boxes, and you can resume by double-clicking.
01:19How do you maintain the server?
01:21When you log in, sometimes you'll be prompted if new packages are available.
01:25Once a week, run the following commands: sudo apt-get update.
01:30It'll ask for the password, and what it will do is check to see what the latest
01:34versions of the packages that you have installed are.
01:37To upgrade the packages, type sudo apt-get upgrade.
01:42That will ensure that you have the latest stable versions of the server
01:45software installed.
01:46As we are already up to date, nothing needs to be upgraded.
01:50What about server security?
01:51As you forwarded ports, when the server is running, its services will be
01:55exposed to the outside world unless you have a Firewall in place to prevent those connections.
01:59Alternatively, if you're behind a router that does not forward ports, then your
02:03development server cannot be accessed from the outside.
02:06Finally, a best practice is to turn off the virtual server when you are not using it.
02:10This way your host machine will consume less resources, and there will no
02:14chance of compromise.
Collapse this transcript
Where to go from here
00:00We've come a long way.
00:01I've shown you how to configure a virtual machine, install and configure a
00:05fully functioning Linux web application server, demonstrated the basics of
00:09database administration, and installed the common CMS, CMF, and framework.
00:14While some of the configurations are intentionally insecure, many of these
00:18techniques can be scaled up, and, with a layer of security added, be ready for
00:22usage in a public facing context.
00:24You can use many of these base skills to manage your own virtual private server, or VPS.
00:29Alternatively, you can stop right here.
00:31You've got a fully functioning local development server optimized for your needs.
00:35You can work from any coffee shop or cabin in the woods that you want to,
00:39untethered by the need of an Internet connection or external hardware.
00:42Whatever the case may be, thank you for watching.
Collapse this transcript


Suggested courses to watch next:

Unix for Mac OS X Users (6h 35m)
Kevin Skoglund

PHP with MySQL Beyond the Basics (10h 27m)
Kevin Skoglund


MySQL Essential Training (2h 46m)
Bill Weinman


Are you sure you want to delete this bookmark?

cancel

Bookmark this Tutorial

Name

Description

{0} characters left

Tags

Separate tags with a space. Use quotes around multi-word tags. Suggested Tags:
loading
cancel

bookmark this course

{0} characters left Separate tags with a space. Use quotes around multi-word tags. Suggested Tags:
loading

Error:

go to playlists »

Create new playlist

name:
description:
save cancel

You must be a lynda.com member to watch this video.

Every course in the lynda.com library contains free videos that let you assess the quality of our tutorials before you subscribe—just click on the blue links to watch them. Become a member to access all 104,141 instructional videos.

get started learn more

If you are already an active lynda.com member, please log in to access the lynda.com library.

Get access to all lynda.com videos

You are currently signed into your admin account, which doesn't let you view lynda.com videos. For full access to the lynda.com library, log in through iplogin.lynda.com, or sign in through your organization's portal. You may also request a user account by calling 1 1 (888) 335-9632 or emailing us at cs@lynda.com.

Get access to all lynda.com videos

You are currently signed into your admin account, which doesn't let you view lynda.com videos. For full access to the lynda.com library, log in through iplogin.lynda.com, or sign in through your organization's portal. You may also request a user account by calling 1 1 (888) 335-9632 or emailing us at cs@lynda.com.

Access to lynda.com videos

Your organization has a limited access membership to the lynda.com library that allows access to only a specific, limited selection of courses.

You don't have access to this video.

You're logged in as an account administrator, but your membership is not active.

Contact a Training Solutions Advisor at 1 (888) 335-9632.

How to access this video.

If this course is one of your five classes, then your class currently isn't in session.

If you want to watch this video and it is not part of your class, upgrade your membership for unlimited access to the full library of 2,025 courses anytime, anywhere.

learn more upgrade

You can always watch the free content included in every course.

Questions? Call Customer Service at 1 1 (888) 335-9632 or email cs@lynda.com.

You don't have access to this video.

You're logged in as an account administrator, but your membership is no longer active. You can still access reports and account information.

To reactivate your account, contact a Training Solutions Advisor at 1 1 (888) 335-9632.

Need help accessing this video?

You can't access this video from your master administrator account.

Call Customer Service at 1 1 (888) 335-9632 or email cs@lynda.com for help accessing this video.

preview image of new course page

Try our new course pages

Explore our redesigned course pages, and tell us about your experience.

If you want to switch back to the old view, change your site preferences from the my account menu.

Try the new pages No, thanks

site feedback

Thanks for signing up.

We’ll send you a confirmation email shortly.


By signing up, you’ll receive about four emails per month, including

We’ll only use your email address to send you these mailings.

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

By signing up, you’ll receive about four emails per month, including

We’ll only use your email address to send you these mailings.

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked