Setting Up a Lamp Server on Ubuntu
by joshwoldstad in Circuits > Computers
2876 Views, 40 Favorites, 0 Comments
Setting Up a Lamp Server on Ubuntu
Now that we have Ubuntu set up on our computer, we want to get our LAMP Server set up. LAMP stands for Linux Apache MySQL Php. We want this because it allows us to write and test web code on a localhost.
Install Apache
Apache is a widely-used web server that is open-source and free. This is the "web server" portion of LAMP, but we still have to install the other portions of LAMP as well.
To install Apache, open a terminal (ctr+alt+t) and enter the command
sudo apt-get install apache2
Each install won't take very long on a reasonable internet connection. (Less than 5 minutes).
Install MySQL
After Apache is installed, we want to install MySQL. Like Apache, MySQL is an open-source product, it is used as an "open-source relational data-base management system". MySQL is used as the Database portion of LAMP.
MySQL installation is similar to Apache, in the terminal enter the command
sudo apt-get install mysql-server
After installation, a purple screen called "package installation" will pop up, you can chooose a password, or leave it blank. This happens multiple times during installation, so don't worry when it pops up again.
Install PHP
Now we need to install the "P" of LAMP, or PHP. Other "P"s can include Perl or Python, but for our case, we are going to use PHP. PHP is a server-side scripting langauge for web-development, it can also be used for other types of programming if you prefer PHP over other programming languages.
Just like the other two installations, we go into a terminal to install. We are going to enter the command
sudo apt-get install php5 libapache2-mod-php5
to install PHP.
Make /var/www Writable
Now that we have all our libraries downloaded, we need to make the "www" folder writable.
This will take three seperate commands in the terminal, but none are extremely complicated.
- "sudo adduser www-data"
- "sudo chown -R www-data:www-data /var/www"
- "sudo chmod -R g+rw /var/www"
After you enter these, save your work and log-out, log back in and go to the "www" folder:
- Open up files.
- Click "Computer" in the devices section.
- Open up "var" (folders are sorted alphabetically, so should be near the end).
- Open "www".
- Right click inside "www" section, and the options "New folder" and "New Document" should be available!
MySQL Secure Installation
Before we can finish up everything we need to run the MySQL Secure installation.
In the terminal enter:
sudo mysql_secure_installation
Installation will ask sever questions, first we must enter the password (if you didn't enter a password just hit enter). The following are what options I chose, but of course you can pick others.
- Set root password? (No)
- Remove anonymous users? (Yes)
- Disallow root login remotely? (Yes)
- Remove test database and access to it? (Yes)
- Reload privilege tables now? (Yes)
After installation has finished you can run the commands:
sudo service mysql start
sudo service mysql stop
to start and stop MySQL.
Configuration and Status
If you want to check the configuration of PHP, MySQL, and Apache: you can go back to the Computer and etc file.
Each are in different folders etc, here are the three config files (and their locations)
- etc/apache2/apache2.config (Apache)
- etc/mysql/my.cnf (MySQL)
- etc/php5/apache2/php.ini
If you want to check the status of the "services", which includes more than just the items we've been working on, enter the command:
service --status-all
Finishing Up
Now for us to test to make sure everything installed correctly, open up your favorite web-browser and type
"localhost" as the address. A page titled "Apache 2 Ubuntu Default" should load.
We want to check one more thing before we're finished.
- Go back to the var/www folder in Computer.
- Create a new file (by right-clicking) inside of the html folder.
- Name it info.php
- In info.php, copy the script:
phpinfo();
?>
Go back to your browser and enter localhost/info.php, a page containing info about the current PHP version should come up!