Showing posts with label LAMP. Show all posts
Showing posts with label LAMP. Show all posts

Friday, February 4, 2011

How to Turn Your Home Ubuntu PC Into a LAMP Web Server

banner

Got a Linux PC you want to put to work? Maybe you’re not comfortable with the command-line only version of Ubuntu Server Edition. Here’s how to keep the standard Ubuntu desktop and add web-serving capabilities to it.

Whether you’re not comfortable with a command-line only system, you’re using your Ubuntu desktop for other things, or you just need it installed for a few particular apps, you can add Apache, MySQL, and PHP to any standard desktop installation of Ubuntu very quickly and easily.

The Simple Command

Let’s start installation with the use of a very clever command:

sudo apt-get install lamp-server^

It will NOT work without the caret at the end. Once you’ve got that entered, you’ll see that it auto-selects all of the necessary packages and will ask you to confirm the “large” amount of data to be downloaded.

02 confirm

Just sit back and let it do its thing until you get a blue screen pop up.

03 mysql root password

Enter a password for the MySQL root account, which is what you’ll need to create other users and manage databases, then hit Enter to continue. You’ll be prompted to re-enter your password, so do that and hit Enter again.

That’s it for installation!

Testing Apache and PHP

Let’s test Apache to see if it’s serving properly. Open up a browser and direct it the following URL:

http://localhost/

You should see something like this appear if everything installed correctly:

05 testing apache

Next up, we’ll test to see if PHP is working. In terminal, enter the following command to create a new document:

sudo nano /var/www/testing.php

Then, copy the following code:

<?php phpinfo(); ?>

Right-click in your terminal and hit paste.

07 phpinfo

08 nano write-out

Hit CTRL+O to “write-out” or save the file, and then hit CTRL+X to quit.

Next, restart Apache with the following command:

sudo service apache2 restart

And load up the following page in your web browser:

http://localhost/testing.php

And you should see something like this:

10 php success

Checking MySQL Bind Address

MySQL has a bind address that should match your system’s. To check your system’s bind address, we can use a quick command:

cat /etc/hosts | grep localhost

That’s a “pipe” or a “stem” in the middle, which is shared with the \ key. You’ll get a couple of results, one of which will show you an IP address.

11 find localhost bind address

You can see from the screenshot above that my bind address is 127.0.0.1.

Next, let’s open up the MySQL config file to see what’s listed there.

sudo nano /etc/mysql/my.cnf

Scroll down until you see a line beginning with “bind-address” like below.

12 my.cnf bind address good

As you can see, the bind-address is the same, so we’re good. If yours is different, just change it so it matches what you found above.

Installing phpMyAdmin

If you’re not familiar with MySQL and its commands, then you may have some trouble managing databases and tables. phpMyAdmin helps you tackle that by providing a PHP interface for MySQL administration. It’s easy to install and can really come in handy, so let’s get to it.

sudo apt-get install phpmyadmin

If this command doesn’t work, you may need to enable additional repositories.

14 installing phpmyadmin

You’ll get another blue screen come up asking you to choose which web server to configure. Make sure the red block is next to “apache2” and be SURE to hit the Space bar. This will mark it with an asterisk, and then you can hit Enter.

15 select apache2 for phpmyadmin

You’ll be asked if phpmyadmin should configure a default database for its own use. Choose Yes.

16 yes to default db

Next, you’ll be asked to enter the password of the admin account used to create this database and user. Since we haven’t created any other MySQL users, enter your MySQL root password.

17 enter mysql root password

Lastly, you’ll create a password to use with phpmyadmin, and you’ll have to confirm it again.

18 password for phpmyadmin

Once you’re done, restart Apache.

You can log in to phpMyAdmin by going to the following URL:

http://localhost/phpmyadmin/

20 phpmyadmin success

Use “root” as the username and then enter the root MySQL password.

21 login success

There’s more than a few important passwords here, and you’ll be tempted to use the same password as your root account. If you choose to do this, be sure that it’s a very secure password, something with mixed character classes and a good length. Remember, you are giving others access to your computer by installing this software, so take proper precautions.

If this is your first time playing with a web server, you may be wondering where the files you want to host go. They’re in /var/www/ be default, and will need elevated privileges to access that directory. One idea is to mount a separate partition to that point to be used solely for serving web stuff. Check out our other article, What is the Linux fstab and How Does It Work?, to get some more information for that.

And, now that you have your own web server, why not learn How To Archive, Search, and View Your Tweet Statistics with ThinkUp?

Posted via email from ://allthings-bare

Tuesday, August 10, 2010

Installing Apache2 With PHP5 And MySQL Support On OpenSUSE 11.3 (LAMP)

Installing Apache2 With PHP5 And MySQL Support On OpenSUSE 11.3 (LAMP)

Version 1.0
Author: Falko Timme <ft [at] falkotimme [dot] com>

Follow me on Twitter
Last edited 07/30/2010

LAMP is short for Linux, Apache, MySQL, PHP. This tutorial shows how you can install an Apache2 webserver on an OpenSUSE 11.3 server with PHP5 support (mod_php) and MySQL support.

I do not issue any guarantee that this will work for you!

 

1 Preliminary Note

In this tutorial I use the hostname server1.example.com with the IP address 192.168.0.100. These settings might differ for you, so you have to replace them where appropriate.

 

2 Installing MySQL 5

First we install MySQL 5 like this:

yast2 -i mysql mysql-client mysql-community-server

Then we create the system startup links for MySQL (so that MySQL starts automatically whenever the system boots) and start the MySQL server:

chkconfig --add mysql
/etc/init.d/mysql start

To secure the MySQL installation, run:

mysql_secure_installation

Now you will be asked several questions:

server1:~ # mysql_secure_installation


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.

Enter current password for root (enter for none): <-- ENTER
OK, successfully used password, moving on...

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: <-- fill in your desired MySQL root password
Re-enter new password: <-- confirm that password
Password updated successfully!
Reloading privilege tables..
 ... Success!


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 a
production environment.

Remove anonymous users? [Y/n] <-- Y
 ... Success!

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!

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!

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...

All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!


server1:~ #

Now your MySQL setup should be secured.

 

3 Installing Apache2

Apache2 is available as an OpenSUSE package, therefore we can install it like this:

yast2 -i apache2

Now configure your system to start Apache at boot time...

chkconfig --add apache2

... and start Apache:

/etc/init.d/apache2 start

Now direct your browser to http://192.168.0.100, and you should see the Apache2 placeholder page (don't worry about the 403 error, this happens because there's no index file (e.g. index.html) in the document root directory):

Click to enlarge
(JavaScript must be enabled in your browser to view the large image as an image overlay.)

Apache's default document root is /srv/www/htdocs/ on OpenSUSE, and the configuration file is /etc/apache2/httpd.conf. Additional configurations are stored in the /etc/apache2/conf.d/ directory.

 

4 Installing PHP5

We can install PHP5 and the Apache PHP5 module as follows:

yast2 -i apache2-mod_php5

We must restart Apache afterwards:

/etc/init.d/apache2 restart

Installing Apache2 With PHP5 And MySQL Support On OpenSUSE 11.3 (LAMP) - Page 2

Copyright © 2010 Falko Timme
All Rights Reserved.

Posted via email from ://allthings-bare