Set up a LAMP Server on Ubuntu 10.04 LTS (Lucid)
This guide provides step by step instructions for installing a full featured LAMP stack on an Ubuntu 10.04 LTS (Lucid) system. The 10.04 release is the most current release of the Ubuntu operating system, and will be supported with security updates until April of 2015.
In this guide, you will be instructed on setting up Apache, MySQL, and PHP. If you don't feel that you will need MySQL or PHP, please don't feel obligated to install them.
These instructions work with the Linode platform. If you don't have a Linode yet, sign up for a Linux VPS and get started today.
System Configuration
It is important to make sure that your system is properly configured before installing Apache. In particular, you need to make sure that your system is up to date and that you have set the correct timezone, hostname, and hosts in your hosts file. If you haven't configured these, you should follow the directions in the getting started guide. Be sure to modify your /etc/hosts file to set a fully qualified domain name (FQDN) for your Linode. This guide assumes that you are logged in as the root superuser on your VPS.
Install and Configure the Apache Web Server
The Apache Web Server is a very popular choice for serving web pages. While many alternatives have appeared in the last few years, Apache remains a powerful option that we recommend for most uses.
Make sure your package repositories and installed programs are up to date by issuing the following commands:
sudo apt-get update
sudo apt-get upgrade --show-upgraded
To install the current version of the Apache web server (in the 2.x series) on an Ubuntu system use the following command:
sudo apt-get install apache2
Now we'll configure virtual hosting so that we can host multiple domains (or subdomains) with the server. These websites can be controlled by different users, or by a single user, as you prefer.
Configure Virtual Hosting
There are different ways to set up virtual hosts, however we recommend the method below. By default, Apache listens on all IP addresses available to it. We must configure it to listen only on addresses we specify. Even if you only have one IP, it is still a good idea to tell Apache what IP address to listen on in case you decide to add more.
Begin by modifying the NameVirtualHost entry in /etc/apache2/ports.conf as follows:
File excerpt:
sudo vi /etc/apache2/ports.conf
NameVirtualHost 12.34.56.78:80
Be sure to replace "12.34.56.78" with your Linode's public IP address.
Now, modify the default site's virtual hosting in the file /etc/apache2/sites-available/default so that the
File excerpt:
sudo vi /etc/apache2/sites-available/default
Install and Configure the MySQL Database Server
MySQL is a relational database management system (RDBMS) and is a popular component in contemporary web development tool-chains. It is used to store data for many popular applications, including Wordpress and Drupal.
Install MySQL
The first step is to install the mysql-server package, which is accomplished by the following command:
sudo apt-get install mysql-server
During the installation you will be prompted for a password. Choose something secure (use letters, numbers, and non-alphanumeric characters) and record it for future reference.
At this point MySQL should be ready to configure and run. While you shouldn't need to change the configuration file, note that it is located at /etc/mysql/my.cnf for future reference.
Configure MySQL and Set Up Databases
After installing MySQL, it's recommended that you run mysql_secure_installation, a program that helps secure MySQL. While running mysql_secure_installation, you will be presented with the opportunity to change the MySQL root password, remove anonymous user accounts, disable root logins outside of localhost, and remove test databases. It is recommended that you answer yes to these options. If you are prompted to reload the privilege tables, select yes. Run the following command to execute the program:
mysql_secure_installation
Next, we'll create a database and grant your users permissions to use databases. First, log in to MySQL:
mysql -u root -p
Enter MySQL's root password, and you'll be presented with a MySQL prompt where you can issue SQL statements to interact with the database.
To create a database and grant your users permissions on it, issue the following command. Note, the semi-colons (;) at the end of the lines are crucial for ending the commands. Your command should look like this:
create database lollipop;
grant all on lollipop.* to 'foreman' identified by '5t1ck';
flush privileges;
In the example above, lollipop is the name of the database, foreman is the username, and 5t1ck password. Note that database user names and passwords are only used by scripts connecting to the database, and that database user account names need not (and perhaps should not) represent actual user accounts on the system.
With that completed you've successfully configured MySQL and you may now pass these database credentials on to your users. To exit the MySQL database administration utility issue the following command:
quit
With Apache and MySQL installed you are now ready to move on to installing PHP to provide scripting support for your web pages.
Install and Configure PHP
PHP makes it possible to produce dynamic and interactive pages using your own scripts and popular web development frameworks. Furthermore, many popular web applications like WordPress are written in PHP. If you want to be able to develop your websites using PHP, you must first install it.
Ubuntu includes packages for installing PHP from the terminal. Issue the following command:
sudo apt-get install php5 php-pear
Once PHP5 is installed we'll need to tune the configuration file located in /etc/php5/apache2/php.ini to enable more descriptive errors, logging, and better performance. These modifications provide a good starting point if you're unfamiliar with PHP configuration.
Make sure that the following values are set, and relevant lines are uncommented (comments are lines beginning with a semi-colon (;)):
File excerpt: /etc/php5/apache2/php.ini
max_execution_time = 30
memory_limit = 64M
error_reporting = E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR
display_errors = Off
log_errors = On
error_log = /var/log/php.log
register_globals = Off
After making changes to the PHP configuration file, restart Apache by issuing the following command:
sudo /etc/init.d/apache2 restart
If you need support for MySQL in PHP, then you must install the php5-mysql package with the following command:
sudo apt-get install php5-mysql
To install the php5-suhosin package, which provides additional security for PHP 5 applications (recommended), you must add the "universe" software repositories. Uncomment the following lines from /etc/apt/sources.list:
File excerpt:
sudo vi /etc/apt/sources.list
deb http://us.archive.ubuntu.com/ubuntu/ lucid universe
deb-src http://us.archive.ubuntu.com/ubuntu/ lucid universe
deb http://us.archive.ubuntu.com/ubuntu/ lucid-updates universe
deb-src http://us.archive.ubuntu.com/ubuntu/ lucid-updates universe
deb http://security.ubuntu.com/ubuntu lucid-security universe
deb-src http://security.ubuntu.com/ubuntu lucid-security universe
Now run the following command to update the package archive:
sudo apt-get update
Finally, install the suhosin package by issuing:
sudo apt-get install php5-suhosin
Restart Apache to make sure everything is loaded correctly:
sudo /etc/init.d/apache2 restart
Congratulations! You've set up a LAMP server on Ubuntu 10.04 LTS. Happy serving!
No comments:
Post a Comment