LAMP stands for Linux Apache MySQL and PHP. It is one of the most popular server configuration. This post explains how to set up a LAMP server on Ubuntu and then install commonly used development aids like phpMyAdmin for database, vsftpd for FTP access and then securing sensitive areas using .htaccess. The Steps below requires Root Privileges
- Install Ubuntu on the Intended System
- Access the terminal from GUI(Applications > Accessories > Terminal) or SSH
Install Apache by typing :
sudo apt-get updateConfirm the installation by typing in your server's IP address in your browser's address bar (eg: http://123.456.78.90), you should get a page saying "It Works!"
sudo apt-get install apache2
Install MySQL with the following command
sudo apt-get install mysql-server libapache2-mod-auth-mysql php5-mysqlIt may prompt you to set root password first and then prompt you to enter it again while setting up the configurations. Enter it as an when required. During the configuration, answer yes to all the yes/no prompts.
Install PHP by typing in the following command
sudo apt-get install php5After installing PHP5 you may want to install additional features like curl. You may see the available packages by typing in
apt-cache search php5-This will give you a list of available packages. You may use sudo apt-get install [package-name] to install the required packages
Voila! You have successfully set up a lamp server. Your php/html files may be put into /var/www/ folder. You may have to restart apache for the changs to take effect. You may do that by typing in
sudo service apache2 restartTo test your installation
cd /var/www/Now type in
sudo nano test.php
<?php phpinfo(); ?>save,exit (CTRL+O to save CTRL+X to exit) and type in http://your server address/test.php (eg: http://123.456.78.9/test.php) and you will get a php info page.
Now you may optionally want to install phpMyAdmin, set up an FTP Server and Secure Sensitive areas(eg Admin panel and phpMyAdmin page) using .htaccess.
phpMyAdmin installation may be done in two ways. Either you may use
sudo wget [url]to download the zip file to your /var/www/ folder and unzip it using the unzip command, then use it by typing in http://server.address/[phpMyAdmin]( PS :[ ] should contain the folder name to which you unzipped the contents of the zip file downloaded, and you may have to install unzip using the sudo apt-get install command.), or you may install it as following
sudo apt-get install phpmyadminSelect apache2 as server and answer YES when prompted on whether to Configure the database for phpmyadmin with dbconfig-common. You will also have to enter the MySQL root password and a login password.
After the installation, add the following lines to /etc/apache2/apache2.conf (sudo nano /etc/apache2/apache2.conf)
Include /etc/phpmyadmin/apache.confand restart apache with sudo service apache2 restart .
- Access phpMyAdmin by typing in http://server.address/phpmyadmin
To Setup FTP server, you have to install and configure vsftpd.
Install vsftpd with the following command
sudo apt-get install vsftpd
Configure vsftpd by editing /etc/vsftpd.conf
sudo nano /etc/vsftpd.confNow set the following values(Omit the ones after //)
anonymous_enable=NO //IMPORTANTSave and Exit (CTRL+O CTRL+X). Sometimes(In case of errors) you may have to create a directory within the users home directory( mkdir /home/[username]/ftpFiles) and change the ownership to root(chown root:root /home/[username]) and do your changes in the ftpFiles directory.
chroot_local_user=YES //This one restricts the local users to their chroot and denies access to other parts of server
- Now restart vsftpd
sudo service vsftpd restart
Configuring .htaccess :
htaccess file may be used to restrict access to sensitive folders/files in your web server
To enable .htaccess, you need to edit /etc/apache2/sites-available/default.
sudo nano /etc/apache2/sites-available/default
<Directory /var/www/>and Change AllowOverride None to AllowOverride All
Options Indexes FollowSymLinks MultiViews
allow from all
# Uncomment this directive is you want to see apache2's
# default start page (in /apache2-default) when you go to /
#RedirectMatch ^/$ /apache2-default/
sudo /etc/init.d/apache2 reload
Now create a file named .htaccess in the directory that is to be secured
sudo nano /path/to/directory/.htaccessand write
AuthUserFile /your/path/to/.htpasswdTo protect a single file, you may add the following to .htaccess file
AuthName "Authorization Required"
<Files "mypage.html"> Require valid-user </Files>
The .htpasswd file will contain the authorized users list. It is advised to save it outside the www folder. To create a new .htpasswd file
htpasswd -c /path/to/your/.htpasswd user1and enter the password. -c is used to create a new file, omit it to add new users to an existing .htpasswd file.
Finally, add these to /etc/apache2/apache2.conf (sudo nano /etc/apache2/apache2.conf)
<Directory /var/www> AllowOverride All </Directory>/var/www may be replaced with whatever path you wish to enable .htaccess, this will enable .htaccess for your whole website
Restart apache server
sudo /etc/init.d/apache2 restart
- Read More on .htaccess file