Home > Web Development > Fedora 12 Installation Guide for PHP Developers

Fedora 12 Installation Guide for PHP Developers

April 14th, 2010

This guide provides step-by-step instructions for installing a Fedora 12 web server suited for PHP and MySQL development. The guide is command-line only, which means you can do everything after the initial installation using SSH.

  1. Download the installation ISO.

    You can download ISOs for a variety of platforms at http://fedoraproject.org/en/get-fedora

  2. Run the installation.

    Partition your drives as needed, and run the installation. When prompted, set the server’s intended use to be a web server. Set your root password, and create an administrative user account. For this guide, we’ll call the administrative user someuser.

  3. Set the hostname.

    When prompted to enter a hostname, enter a fully-qualified domain name you own. I don’t like to use www as the subdomain for my server’s hostname. Instead, I like to give the server a subdomain like server1 or server2. For instance, if you registered the domain name awesomewebsite.com, you might want to use the hostname server1.awesomewebsite.com.

    Why do I do it this way? In the future, your website may grow, forcing you to move different components of your web service to different servers or virtual servers. You might, for instance, put your Apache server and memcached cache on one machine, and your MySQL database on another machine. Those machines could be server1.awesomewebsite.com and server2.awesomewebsite.com, respectively. Those are machine-specific domain names. You might have function-specific domain names like www.awesomewebsite.com for Apache and db.awesomewebsite.com for MySQL.

  4. Login for the first time.

    Once the installation is finished, you can login for the first time! Use the administrative account you created above.

  5. Make your administrative account a sudoer.

    A sudoer is a user who can perform the tasks usually reserved for root. These users can prepend any command with sudo to perform that command as root.

    su
    echo 'someuser ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
    exit
    
  6. Setup the network interface.

    Your Fedora installation will use DHCP to get a dynamic IP address and DNS information by default. To host a website, you’ll most likely have a static IP address and specific DNS information. To set these pieces of information, you’ll need to edit the network script for your primary Ethernet card. The network script is read by your Fedora server on startup.

    sudo nano /etc/sysconfig/network-scripts/ifcfg-eth0
    

    Edit the file, paying special attention to the following lines:

    IPADDR=XXX.XXX.XXX.XXX
    GATEWAY=XXX.XXX.XXX.XXX
    NETMASK=XXX.XXX.XXX.XXX
    DNS1=XXX.XXX.XXX.XXX
    DNS2=XXX.XXX.XXX.XXX
    BOOTPROTO=none
    

    Once you’ve finished editing this file, you should restart the network service. The network service will restart and load the above settings. If you’re connected to your server via SSH, you will probably lose your connection at this point. Just reconnect using the new IP address.

    sudo service network restart
    

    Other Ways to Manage Network Interfaces

    There are multiple ways to manage network interfaces. The above method is the most foundational. You should definitely learn how to edit Linux configuration files directly to gain a better understanding of the operating system. But, once you’ve become a seasoned Linux admin, you can try one of the following methods.

    If you want to use a textual user interface (TUI) to manage your network interfaces, use the following command.

    sudo system-config-network-tui
    

    If you want to use the GUI network configuration application use the command below. If you’re managing your Linux system from a remote Windows desktop, you might also be interested in reading my guide on Using X11 over SSH with PuTTY and Xming.

    sudo system-config-network
    

  7. Optional: Make Fedora startup in a command-line only environment.

    You can make your web server more efficient and less error-prone by bypassing the Gnome or KDE desktop. The Linux operating system has a few built-in “run-levels” that enable you to start up in a command-line only environment or a graphical environment. We’re going to set Fedora to boot into run-level 3. Think of this as Windows Safe Mode, command-line only. All we’re doing is bypassing the GUI. Every other service and and function of the server will run normally. This is optional. If you have powerful server hardware, you can benefit from leaving the desktop turned on.

    Edit the inittab configuration file to tell Fedora to start in run-level 3.

    sudo nano /etc/inittab
    

    By default, the initdefault variable in inittab is set to 5. Change the following line to set it to 3:

    id:3:initdefault:
    

    To see if your change worked, restart the server.

    sudo shutdown -r now
    
  8. Install screen.

    Screen is a command-line utility that saves your terminal session. I advise starting screen before doing any task via SSH that may take a long time to complete. If the SSH connection is closed unexpectedly, you can reconnect to it if you are using screen. You can also start a tast on one terminal, disconnect from it, then reconnect on another terminal. You can have multiple screen sessions active at one time. To install screen:

    sudo yum install screen
    
  9. Update all system software using Yum.

    Yum is a package manager. It allows you to search for, install, update, and remove software packages for your Fedora server. Package managers (and the people behind the scenes who maintain the packages) make Linux awesome. We’re going to use Yum to update every package currently installed on our server. This task will take a few minutes, so it’s a good candidate for screen.

    screen
    sudo yum update
    
  10. Install packages related to PHP.

    We want to install packages related to PHP. You can easily find a list of available packages that start with PHP using Yum:

    sudo yum list php*
    

    I will install several PHP packages at once:

    sudo yum install php php-gd php-pear
    
  11. Install packages related to MySQL.

    We’ll install the server and client tools for MySQL using Yum.

    sudo yum install mysql mysql-server mysql-gui-tools mysqltuner mysqlreport
    
  12. Install other packages.

    Below is a sampling of packages I find useful for web development. Research and install these at your discretion.

    sudo yum install memcached php-pecl-memcached
    
  13. Make the httpd (web) and mysqld services start automatically.

    Services in Fedora work similarly to services in Windows. You can specify which services start automatically when the server boots. You can even specify which run-levels the services should run on. Fedora provides a simple command-line utility called chkconfig to manage services. We want our web server and database server to start automatically, so we’ll configure them using chkconfig.

    sudo chkconfig mysqld on
    sudo chkconfig httpd on
    

    If you want to see a list of the services currently scheduled to run automatically, just call chkconfig by itself.

    chkconfig
    
  14. Start the httpd (web) and mysqld services.

    You could restart your entire Fedora server to start the httpd and mysqld services, but there is a quicker way. Let’s just start those services manually.

    sudo service httpd start
    sudo service mysqld start
    
  15. Open the firewall for web traffic.

    By default, your website visitors will be blocked by your server’s firewall. We want to allow users to connect to ports 80 (WWW), 443 (SSL), and 21 (FTP). To do this, Fedora provides a nice command-line firewall editor.

    sudo system-config-firewall-tui
    

    Once you launch the firewall editor, press the configure button. After you’ve added the services you wish to allow, click the close button. system-config-firewall-tui writes its configuration to /etc/sysconfig/iptables.

That’s it! You should now have a working Fedora 12 web server. If you want to test it, why not have it display the PHP Info page?

nano /var/www/html/index.php

Put the following PHP code in that file:

<?php
    phpinfo();
?>

You can test your work by opening a web browser and navigating to server1.awesomewebsite.com.

Nate Smith Web Development , , ,

  1. | #1

    If you are trying to get Fedora running on Hyper-V, take a look at this blog:

    http://blogs.technet.com/b/seanearp/archive/2008/06/29/linux-on-hyper-v.aspx

  1. No trackbacks yet.