This is part of a series of posts on creating your own LAMP virtual machine for development purposes. In this final article of the series I will cover several things you may need, such as configuring FTP for easily transferring files and explaining some of the basics of how to make use of your new VM.
Estimated time (this post only): 15 minutes
Presumably you will be doing your development on your host system or some other machine, so you need an easy way to transfer files to your new server. You could use the built-in SFTP file-transfer program in Bitvise as I mentioned previously, but FTP makes things easier, especially if you are using something like Dreamweaver. Webmin makes this extremely easy since it comes pre-configured with the powerful ProFTPD Server module. Find it under “Un-used Modules.” After clicking on it, you will see a link that let’s you install ProFTPD automatically, so click that.
Assuming that went well, click the link at the bottom to return to the module. Now click the “Default server” and change settings as desired, but here are the ones most important for our purposes:
- Allow login by root?—set to No.
- Deny users in /etc/ftpusers file?—set to Yes.
- Files and Directories
- Limit users to directories—set to “Home directory” only if you are using individual users per site. If you are using a single user to manage all sites, you need to set this manually to “/home/” instead.
- Denied FTP Users (in Global Configuration)
- This file already contains many usernames which should be denied. You should add any others used for services (such as the “php” user we created earlier).
Set other options as desired, but this is the minimum you need to enable FTP access to your sites. Click the button to “Start Server” or if it is already started, “Apply Changes.”
If you are using a single user to access all sites, the default SELinux policy will cause problems when trying to list files in directories outside your own home directory. To fix this, in SSH/Terminal, do:
sudo setsebool -P ftp_home_dir on sudo setsebool -P ftpd_full_access on
Now you also need to open up the port in the firewall. In Webmin, under the “Networking” section click “FirewallD.” Choose the correct zone from the drop-down list (“Work” in this example). Then click “Add allowed service” and select “FTP” from the drop-down list before clicking the “Create” button. Then click the “Apply Configuration” button.
Now you can make your connection from any FTP client just as you would to any web server by just using the static IP address assigned to your VM. Following are two typical configurations in Dreamweaver using the example site from the previous article. The first is with a single user who has access to all sites and the second is a user who has access to just a single home directory (site).
Directives are the options you put into your Apache configuration files. Up until now I haven’t really covered what they all do. You really should read more about them for yourself. The Apache HTTP Server Documentation is a good place to start, especially this quick reference. But let’s touch on a couple of the basics.
Directory-related directives can be set in override files named “.htaccess” (the leading period is important). Read more about them here. As the documentation says, this isn’t the most efficient way to set directives, but it is the fastest, especially if you just want to quickly test what a change will do. Basically you can put anything in an .htaccess file that you could put inside a Directory directive.
Let’s consider the site in the images above, where the full path to the htdocs folder is “/home/site1.test.local/htdocs” (the file system path isn’t the same as that viewed in your FTP client as you’ve seen). Now, let’s say you have a folder inside there named “myfolder” and you want to change the options for just this sub-folder to allow the listing of directory contents. You could create an .htaccess file in “myfolder” containing the following:
This would be the same as if you added the following to one of your Apache config files:
<Directory "/home/site1.test.local/htdocs/myfolder"> Options Indexes </Directory>
Modifying vs. Overriding Directory Directives
In the previous example, regardless of where you set the option, it would override the “Options” directive of any higher-level directory and replace them with the options set here for this directory and any under it. For instance, if you had something like the following in your configuration…
<Directory "/home/site1.test.local/htdocs"> Options FollowSymLinks </Directory>
… symbolic links would be disabled for “myfolder”, since you overrode the existing options. If you only want to modify existing options, prepend the options you want to add/remove with +/- like so:
Setting Default PHP Handler
For our purposes, one of the most beneficial uses of the Directory directives and/or .htaccess files is the ability to change the default PHP handler per directory. This way you can quickly test your project against every installed version of PHP. Assuming all your PHP files have the extension PHP, here are some examples:
<FilesMatch \.php$> SetHandler application/x-httpd-php </FilesMatch>
<FilesMatch \.php$> SetHandler "proxy:unix:/opt/php-5.4.43/var/run/php.sock|fcgi://localhost" </FilesMatch>
<FilesMatch \.php$> SetHandler "proxy:unix:/opt/php-5.5.27/var/run/php.sock|fcgi://localhost" </FilesMatch>
<FilesMatch \.php$> SetHandler "proxy:unix:/opt/php-5.6.11/var/run/php.sock|fcgi://localhost" </FilesMatch>
<FilesMatch \.php$> SetHandler "proxy:unix:/opt/php-7.0.0beta2/var/run/php.sock|fcgi://localhost" </FilesMatch>
There are so many more things I could cover. But this series of articles has gone on long enough. This is all you need to get a fully functional LAMP server that you can configure however you wish. If you need help configuring your Apache server or PHP, there is extensive documentation on this. I just thought there was a lack of a full step-by-step guide on how to do this. So here you are. Good luck.
Yes, at times I made things more complicated than they needed to be. But this was intentional. As I said from the start, this guide is geared toward the Linux noobs. So I tried to cover as many ways of performing common tasks as possible.
In writing this guide I came up with at least a dozen other articles I could write. Look for more posts that expand on some of these topics in the future.