LAMP Server Installation Guide on Fedora 16 Verne

From Acenet Knowledgebase
Jump to navigation Jump to 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.

<syntaxhighlight lang="bash">yum update</syntaxhighlight>

Install the Apache Web Server and PHP 5.3

Install the "Web Server" package using yum groupinstall. <syntaxhighlight lang="bash">yum groupinstall "Web Server"</syntaxhighlight> 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 <syntaxhighlight lang="bash">systemctl enable httpd.service</syntaxhighlight> Start the Apache Web Server (httpd) <syntaxhighlight lang="bash">systemctl start httpd.service</syntaxhighlight> 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. <syntaxhighlight lang="bash">nano /etc/httpd/conf/httpd.conf</syntaxhighlight> 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. <syntaxhighlight lang="bash">ServerName 169.254.1.2:80</syntaxhighlight>

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. <syntaxhighlight lang="bash">Listen 169.254.1.2:80</syntaxhighlight>

Anytime the Apache configuration file is modified, the Apache service needs to be restarted for the changes to take effect. Let's restart Apache: <syntaxhighlight lang="bash">systemctl restart httpd.service</syntaxhighlight> 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. <syntaxhighlight lang="bash">chown apache.apache /var/www/html</syntaxhighlight>

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 <syntaxhighlight lang="bash">yum groupinstall "MySQL Database"</syntaxhighlight> Configure the MySQL service to start on boot <syntaxhighlight lang="bash">systemctl enable mysqld.service</syntaxhighlight> Start the MySQL service <syntaxhighlight lang="bash">systemctl start mysqld.service</syntaxhighlight> Secure your new MySQL service with mysql_secure_installation <syntaxhighlight lang="bash">mysql_secure_installation</syntaxhighlight> This will prompt you to answer several questions about your MySQL service. <syntaxhighlight lang="bash">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.</syntaxhighlight> Since we just installed the MySQL service, there is no MySQL root password. As the message indicates, simply press ENTER at the following prompt. <syntaxhighlight lang="bash">Enter current password for root (enter for none):

OK, successfully used password, moving on...</syntaxhighlight>

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. <syntaxhighlight lang="bash">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!</syntaxhighlight>

Remove the anonymous MySQL user which is intended for testing only <syntaxhighlight lang="bash">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!</syntaxhighlight>

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. <syntaxhighlight lang="bash">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!</syntaxhighlight>

Remove the the 'test' databaes from MYSQL <syntaxhighlight lang="bash">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!</syntaxhighlight>

Now reload the privilege tables to have our changes take effect. <syntaxhighlight lang="bash">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...</syntaxhighlight>

We're finished securing MySQL <syntaxhighlight lang="bash">All done! If you've completed all of the above steps, your MySQL

installation should now be secure.
Thanks for using MySQL!</syntaxhighlight>