Setting up a LAMP stack
The so-called LAMP stack is one of the most compelling reasons to install Linux in the first place and probably the one primary purpose for many Fedora server-based installations. The combination of Linux/Apache/MySQL/PHP (or Perl, or even Python) allows webmasters to build websites and run complex applications such as a webmail interface or a wiki.
Requirements
The requirements for a server running Fedora Core can range
somewhat more widely than those recommended in the release notes,
depending on the use case. A small, private server with light use
can easily handle its expected load with even less
memory/storage/speed than the release notes necessarily call for.
On the other hand, a server designed to withstand huge amounts of
traffic can benefit from multiple processors, several gigabytes of
RAM, and large arrays of disk drives. As a server administrator,
you'll need to use your best judgment for your use case.
Hardware aside, this article assumes nothing more than a fresh
Fedora Core installation and shell access as root (all commands
listed here assume you execute them as root). Configuring for
specific uses (setting up Virtual Hosts, installing web
applications or creating websites, or learning PHP) are beyond the
scope of this article, which only covers setup.
Doing the work
The best way to install a LAMP stack is to install each letter in sequence; to spell out the word LAMP, in effect.
Linux
If you've already got Fedora Core installed, then you've accomplished this step. If you haven't, check out Install Solutions for more details on installing and configuring Fedora Core.
Apache
- Installing Apache means installing the program which will handle requests to your web server. For most people, Apache itself is the web server, terminologically speaking. In your Fedora Core installation, depending on the choices you made during the install process, you may or may not have Apache already installed. Just use the following command to check:
- If it tells you a version number, then it's installed and we can progress to the next step. Otherwise, we need to install it:
- After installation, the service must be configured to start automatically.
- To start the server process immediately:
- Finally, it's important to make sure that port 80 is remotely accessible, by configuring iptables to open the port (and to leave it open by default from the outside). The following commands will remember the rule for you across reboots and apply it immediately:
# rpm -q httpd
# yum install httpd
# /sbin/chkconfig httpd on
# /sbin/service httpd start
# echo '-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT' >> /etc/sysconfig/iptablesYou can put in the hostname or IP address of the server in the address bar of a web browser (whether on the same host or elsewhere in the network) to test the installation. You'll see a welcome page if everything was successful. Otherwise, refer to troubleshooting.
# /sbin/service iptables restart
MySQL
- Installing and running the database component of the LAMP stack, called MySQL, is at least as easy. The following command will install the database and the server process.
- The server process must likewise be running and accessible.
- To test that everything is working okay so far, run this command to print out some information and check its status:
# yum install mysql mysql-server
# /sbin/chkconfig mysqld on
# echo '-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT' >> /etc/sysconfig/iptables
# /sbin/service iptables restart
# /sbin/service mysqld start
# mysqladmin version status
PHP (or Perl or Python)
- The following command will install PHP, along with the needed stuff to glue it together with the web server and the database.
- PHP is pretty much ready to run after that, although you may need to restart the web server to make sure it loads the PHP module.
- To run Python on your web server, run the following. (Python is already installed on all Fedora Core installations, so it's not needed to install that as well.)
- For Perl, the following will get you started:
PHP interprets the scripts of your favorite web site or application, running on top of the other parts of the LAMP stack.
# yum install php php-mysql
# /sbin/service httpd restartIf you'd like to use another 'P' in the place of PHP (or install alongside), the steps are pretty similar. Both Perl and Python come with ways to access MySQL and modules to allow them to run smoothly and quickly inside of Apache.
# yum install mod_python MySQL-python
# yum install perl mod_perl perl-DBD-mysqlDon't forget to restart the web server after either (or both) of these commands to make sure the relevant modules will be loaded by Apache.
Troubleshooting
Definitively testing the whole thing is pretty easy. You can create a small test PHP file and try to access it.
- Create the test script:
- If all this is successful, you should delete the script you just created.
# echo "<?php phpinfo(); ?>" > /var/www/html/index.phpThen access the web server by putting the address in any web browser that can access the server. If your server's IP address is 192.168.1.100, put that in the address bar. By going to that address, you should see a long detailed page describing PHP's configuration and status in detail.
You can skip down to the MySQL section by putting a jump in the address bar to it. (If you used http://192.168.1.100/ to access the page, use http://192.168.1.100/#module_mysql to skip down to the relevant part.) You should see various options about MySQL enumerated.
# rm -f /var/www/html/index.phpNow it's time to install your favorite web application (phpBB, mediawiki, squirrelmail/roundcube) or learn PHP.
Bugs
Since I don't personally use Perl for web development, I'm not sure what exactly is needed to use it with a database.Disclaimer
We test this stuff on our own machines, really we do. But you may run into problems, if you do, come to #fedora on irc.freenode.net

