(ve):Install LAMP on Ubuntu 9.10
- This page was last modified on October 3, 2011, at 16:42.
From (mt) Community Wiki
Contents |
INCOMPLETE ARTICLE
It is very easy to install a LAMP environment on Ubuntu 9.10. LAMP is short for Linux, Apache, MySQL, PHP. After following this quick guide, you will be able to serve dynamic database-driven content for your website(s).
Install
- Log in to your (ve) Server as root or another user with sudo privileges:
ssh root@example.com - Make sure your server is up to date:
apt-get update apt-get upgrade
- Now, use apt-get to install your LAMP environment:
apt-get install apache2 php5 libapache2-mod-php5 mysql-server mysql-client php5-mysql
You will be asked to set the root MySQL password. Please choose a strong one.
Configure your Website(s)
Now that you have your LAMP install, we need to add some websites using virtual entries. This will allow you to host multiple sites using the one IP address that comes with your (ve) Server.
- Change to the apache directory and edit the file "ports.conf":
cd /etc/apache2 sudo vi ports.conf
Alternately, if you find the vi editor difficult to use, edit the same "ports.conf" file with nano:
cd /etc/apache2 sudo nano ports.conf
In this file, we want to change the NameVirtualHost line to include your IP address which you can easily find in your AccountCenter Server Guide. Make sure you are listening on port 80 as well.
/etc/apache2/ports.conf# If you just change the port or add more ports here, you will likely also # have to change the VirtualHost statement in # /etc/apache2/sites-enabled/000-default # This is also true if you have upgraded from before 2.2.9-3 (i.e. from # Debian etch). See /usr/share/doc/apache2.2-common/NEWS.Debian.gz and # README.Debian.gz NameVirtualHost 12.34.56.78:80 Listen 80 <IfModule mod_ssl.c> # SSL name based virtual hosts are not yet supported, therefore no # NameVirtualHost statement here Listen 443 </IfModule> - We now need to change the "default" file in the "sites-available" directory to allow us to configure multiple sites. The sites-available directory is where we will create all our virtual sites.
First, we're going to specify the IP address for the default site, and add a ServerName directive so the default site doesn't override the other sites you'll be adding to the server:
sudo vi /etc/apache2/sites-available/default
/etc/apache2/sites-available/default<VirtualHost 12.34.56.78:80> ServerName default.ve-server1.com ServerAdmin webmaster@localhost DocumentRoot /var/www <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /var/www/> Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all </Directory> ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ <Directory "/usr/lib/cgi-bin"> AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all </Directory> ErrorLog /var/log/apache2/error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog /var/log/apache2/access.log combined Alias /doc/ "/usr/share/doc/" <Directory "/usr/share/doc/"> Options Indexes MultiViews FollowSymLinks AllowOverride None Order deny,allow Deny from all Allow from 127.0.0.0/255.0.0.0 ::1/128 </Directory> </VirtualHost>- You can use any domain or subdomain that resolves to the server as the ServerName. In this example, if someone visits http://default.ve-server1.com, OR any domain that resolves to this server but is not specified in its own VirtualHost file, they will be directed to the contents of /var/www/ (which shows a default Apache page by default, but you can upload a custom page).
- If you have a specific domain that you want to be the default for your server, you can specify that as the ServerName here instead, and change the DocumentRoot directive to your desired path for that site.
- If you don't like having a default domain, disable it by running the following command:
sudo a2dissite default
If you disable the default website and then want to enable it use 'sudo a2ensite default' as detailed in step 3 below.
Skip the next three steps if you chose to disable the default domain.
- Using the command a2ensite, we will tell apache to serve the contents of the default site. It should be enabled by default, but run this command just in case (unless you disabled the default site in the previous step):
sudo a2ensite default
-
We also need to reload apache:
sudo /etc/init.d/apache2 reload
We should now be able to point our browser to the IP address to see the default "It Works" page:
This won't work if you disabled the default site.
- Now that we know our install is working, it's time to add some of our own websites. We will use ve-server1.com and ve-server2.com as our examples. Simply create two files named ve-server1.com and ve-server2.com in the sites-available directory:
sudo vi /etc/apache2/sites-available/ve-server1.com
with the following content:
/etc/apache2/sites-available/ve-server1.com<VirtualHost 12.34.56.78:80> ServerAdmin webmaster@ve-server1.com ServerName ve-server1.com ServerAlias www.ve-server1.com DocumentRoot /var/www/ve-server1.com/html/ ErrorLog /var/www/ve-server1.com/logs/error.log CustomLog /var/www/ve-server1.com/logs/access.log combined </VirtualHost>Now do the same for your other domain.
- If you noticed we have some paths in those files that don't exist yet. Let's create them:
sudo mkdir -p /var/www/ve-server{1,2}.com/{html,logs}Then let's create some index.html files in those directories:
sudo touch /var/www/ve-server1.com/html/index.html sudo touch /var/www/ve-server2.com/html/index.html
Then put some content in those index.html files:
sudo echo -e '<html>\n<head>\n<title>Welcome to apache!</title>\n</head>\n<body bgcolor="white" text="black">\n<center><h1>ve-server1.com is working!</h1></center>\n</body>\n</html>' > /var/www/ve-server1.com/html/index.html sudo echo -e '<html>\n<head>\n<title>Welcome to apache!</title>\n</head>\n<body bgcolor="white" text="black">\n<center><h1>ve-server2.com is working!</h1></center>\n</body>\n</html>' > /var/www/ve-server2.com/html/index.html
You will now have html directories for each of your domains, including log directories and default index.html files.
- Now all that is left to do is enabling each domain and reloading Apache:
sudo a2ensite ve-server1.com sudo a2ensite ve-server2.com /etc/init.d/apache2 reload
Please note: You can disable any of your sites using the "a2dissite" command similar to how you used the "a2ensite" command.
Test PHP 5
The document root for your site is /var/www/ve-server1.com/html/. A simple phpinfo page will provide useful details about your PHP installation.
vi /var/www/ve-server1.com/html/info.php
- Create the document with the following:
<?php phpinfo(); ?>
Connect to MySQL
With MySQL installed, we recommend you run the following program to secure MySQL:
mysql_secure_installation
Options available: - Change the MySQL root password - Remove anonymous user accounts - Disable root logins outside of 'localhost' - Remove test databases
- Next, we'll connect to MySQL to create a database and user.
Log in to MySQL:
mysql -u root -p
For this example, we will create the database 'woot', grant the user 'meh' read/write privileges and assign the password 'DBF5f3'.
create database woot; grant all on woot.* to 'meh' identified by 'DBF5f3';
Security
Follow these articles to make your server more secure:
- Securing your (ve) Server
- VE:Secure Apache configuration
- (mt) Security Resources (browse for applicable articles)
