LAMP Server Installation Guide on Fedora 16 Verne

From Acenet Knowledgebase
Jump to: navigation, search

If you've ever installed a LAMP server on RedHat Enterprise Linux or CentOS Linux this process will look pretty familiar to you. Fedora 16, RHEL, and CentOS all use yum to manage packages so setting up a LAMP server is a breeze.

One thing you may notice that differs in this guide from RHEL and CentOS is the lack of 'service' and 'chkconfig' commands. The Linux commands 'service' and 'chkconfig' are part of the init daemon SysVinit. Fedora is moving away from SysVinit and is instead using systemd. Although most commands from SysVinit are supported in systemd, this guide will use systemd-style commands exclusively.

In this example, our server's hostname is vps.example.com and resolves to the IP address 169.254.1.2.


Update your System

Connect to your server via SSH as the root user. Ensure your system is up to date using yum.

yum update

Install the Apache Web Server and PHP 5.3

Install the "Web Server" package using yum groupinstall.

yum groupinstall "Web Server"

Like CentOS, this will install PHP as well. The "Web Server" group also installs PHP 5.3.14. Configure the Apache Web Server (httpd) to start automatically on reboot

systemctl enable httpd.service

Start the Apache Web Server (httpd)

systemctl start httpd.service

The web server is now installed, but requires some configuration. Open the Apache configuration file with your favorite text editor. We'll use nano in this example.

nano /etc/httpd/conf/httpd.conf

Let's first change the ServerName directive. If your hostname has a properly resolving DNS entry, you can use your server's hostname. Otherwise, you can use the IP address for your server.

ServerName 169.254.1.2:80

The DocumentRoot directive defines where Apache will serve documents. By default, this path is set to /var/www/html. If you prefer to have your documents served from a different directory, you can adjust this as desired. The Listen directive defines which IP addresses and ports Apache will bind to. The default value *:80 will cause Apache to bind to all IP addresses which is often unnecessary. Unless you know you need a certain IP to be bound to port 80 for Apache, it will usually suffice to list only your server's main IP.

Listen 169.254.1.2:80

Anytime the Apache configuration file is modified, the Apache service needs to be restarted for the changes to take effect. Let's restart Apache:

systemctl restart httpd.service

For additional safety, let's set the user and group ownership of /var/www/html/ to the apache user. This will prevent PHP scripts from being executed as root and performing potentially harmful actions.

chown apache.apache /var/www/html

Apache can be customized far beyond the few directives we've covered here. However, these few changes are all that's required to get a working installation. We can now upload our HTML and PHP files to /var/www/html/ and visit our site in a web browser.

Install MySQL

Install the MySQL database server using yum groupinstall

yum groupinstall "MySQL Database"

Configure the MySQL service to start on boot

systemctl enable mysqld.service

Start the MySQL service

systemctl start mysqld.service

Secure your new MySQL service with mysql_secure_installation

mysql_secure_installation

This will prompt you to answer several questions about your MySQL service.

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Since we just installed the MySQL service, there is no MySQL root password. As the message indicates, simply press ENTER at the following prompt.

Enter current password for root (enter for none):
 OK, successfully used password, moving on...

You'll next be prompted to configure a new MySQL root password. At the prompt, enter "Y" and then provide a secure password for the root MySQL user. Remember that secure passwords should contain a mix of letters and numbers and should not be words contained within a dictionary.

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
 Set root password? [Y/n] Y
New password:
Re-enter new password:
 Password updated successfully!
Reloading privilege tables..
 ... Success!

Remove the anonymous MySQL user which is intended for testing only

By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into aproduction environment.

Remove anonymous users? [Y/n] Y
 ... Success!

We'll now disable remote logins for the root user. This will prevent brute force attacks against the root MySQL user's password. If you don't plan to have outside servers connect to your database, you could take this one step further and block MySQL's port 3306 in your firewall. This is beyond the scope of this guide.

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] Y
 ... Success!

Remove the the 'test' databaes from MYSQL

By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] Y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Now reload the privilege tables to have our changes take effect.

Reloading the privilege tables will ensure that all changes made so far
 will take effect immediately.

 Reload privilege tables now? [Y/n] Y
 ... Success!

 Cleaning up...

We're finished securing MySQL

All done!  If you've completed all of the above steps, your MySQL
 installation should now be secure.

 Thanks for using MySQL!