Showing posts with label Ubuntu. Show all posts
Showing posts with label Ubuntu. Show all posts

Wednesday, January 7, 2015

Tutorial: How to Install Apache PHP and MySQL on Ubuntu 12.10 Quantal Quetzal

Due to be released October 18th, Ubuntu 12.10 (”Quantal Quetzal”) looks like it’s going to be a pretty decent operating system. Most of the changes are minor, but in testing it I’ve found it to be very stable. I’ve whipped up some tutorials in preparation of the release for those folks looking to get their machines going.
Most web developers prefer a local webserver when doing development. If you can work this way it’s more convienient especially when going solo. Today’s tutorial will show you how to set up Apache, PHP and MySQL on your Quantal Quetzal machine so you can get rolling.

Install Apache

First you install Apache, and it’s as easy as it ever was:
1
sudo apt-get install apache2
After a quick install it will come up automatically. Load up a browser and point it http://localhost and you should see this:
This is your bare Apache server. Next we’ll add PHP.

Install PHP

You’ll want to install the latest version of PHP 5, to do that type:
1
sudo apt-get install libapache2-mod-php5 php5
This will install PHP5 plus the libraries to interface with Apache.
You’ll want to restart the server
1
sudo etc/init.d/apache2 restart
To test it out, create a file called test.php:
1
sudo nano /var/www/test.php
Let’s use the phpinfo() function so we can check out our installation:
/var/www/test.phpphpInfo() Documentation
1
<?php phpinfo(); ?>
It should look like this:
You can inspect your options and if you want to change anything, your php location is here:
1
/etc/php5/apache2/php.ini

Install MySQL

Next you’ll need to install the MySQL server. This is also super easy:
1
sudo apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql
MySQL will ask you for a password. You really shouldn’t leave this blank, even if it is just going to be on your local machine. It only takes a second to do and some applications will require a password of some type on the server.
Test your server to make sure it’s working properly.
1
2
3
mysql -u root -p
<Enter Password>
show databases;
It should look something like this:
Now you’re up and running!
You may want something to manage your MySQL data, I realize not everyone is as crazy about the prompt as I am. PHPMyAdmin is great:
1
sudo apt-get install phpmyadmin
or you could download something like MySQL Workbench and work with your database that way.

Optional Publishing Method

Publishing can be kind of a pain because when you install Apache it makes the document root of the webserver /var/www that is owned by root. So this causes a problem. Here is one solution.
1
2
sudo mkdir /srv/www
sudo cp -r /var/www/* /srv/www/
then, open up your config file:
1
sudo nano /etc/apache2/sites-available/default
And change your DocumentRoot. There will be a section that says:
1
2
3
4
5
6
7
8
Change 
DocumentRoot /var/www
to 
DocumentRoot /srv/www
and 
<Directory /var/www>
to
<Directory /srv/www>
then restart your server:
1
sudo etc/init.d/apache2 restart
I created a folder in my home directory called “web” and then created a symbolic link:
1
sudo ln -s /srv/www/ /home/jeremy/web/
so I can work in a folder in my home directory ( I actually do most work in VIM ). Of course there’s a little permissions issue still, so run the following commands, but be sure to subsitute your user name.
1
2
3
sudo usermod -g www-data jeremy
sudo chown -R jeremy:www-data /srv/www
sudo chmod -R 775 /srv/www/
Now I can create files or entire an entire website in my own folder ( /home/jeremy/web ) and view it thru localhost.

Conclusion

So it turns out setting up Apache, PHP and MySQL is no different in Quantal Quetzal than in recent Ubuntu versions. Using apt-get for management takes a lot of hassle out of software management. I hope this helps you in setting up a local webserver, so you can start building some awesome stuff.
I will whip out a few more Quantal Quetzal tutorials in the coming days for those early adopters who like to try out the newest stuff. Questions? Leave me a comment!

How to Install Octopress on Ubuntu Linux 12.10 (Quantal Quetzal)

So, you’ve discovered Octopress and want to set it up, welcome to the club! Octopress is an awesome system, I love it.
Today’s tutorial is going to show you how to set it up in Ubuntu Linux. The idea being if you’re using Ubuntu for development you can build and generate your pages on your dev machine, and push them to your site. Let’s get started.
I’m using Ubuntu 12.10 Quantal Quetzal in this demo, but it should be relatively the same for most Ubuntu versions.

Step 1: Install Some Dependencies

First you need to install Git, and rbenv. You should already have Ruby installed but if not it will come up as a dependency.
1
$ sudo apt-get install build-essential git rbenv
Rbenv is a program that allows you to switch between versions. Start it up by typing:
1
$ rbenv init
If you want it to start automatically, add this line to your ~/.bashrc file
1
eval "$(rbenv init -)"
Now you can install Ruby:
1
2
3
$ rbenv install 1.9.3-p194
$ ruby -v
ruby 1.9.3p194 (2012-04-20 revision 35410) [i686-linux]
You may also need to install Ruby Build (different from Ruby Builder) to get this working:
1
2
3
4
5
$ mkdir -p ~/.rbenv/plugins
$ cd ~/.rbenv/plugins
$ git clone git://github.com/sstephenson/ruby-build.git
$ cd /ruby-build
$ ./install.sh

Step 2: Get Octopress

Now that you have your dependencies installed, you will want to clone Octopress into a folder.
1
2
3
$ mkdir octopress
$ git clone git://github.com/imathis/octopress.git octopress
$ cd octopress
This gives you a fresh version of Octopress right from Github.

Step 3: Install Octopress

Now that your depencies are met and you’re ready to go, you install it just as it shows on the Octopress site:
1
2
3
4
$ cd ~/octopress
$ sudo gem install bundler
$ rbenv rehash    # If you use rbenv, rehash to be able to run the bundle command
$ bundle install
Build a test post, just to be sure there are no errors:
1
2
$ rake new_post["hello world!"]
$ rake generate
And that’s it! Getting up and running in Ubuntu Linux is pretty simple if you follow the steps exactly. I will also be posting a tutorial on here for installing in Windows, including Windows 8, very soon.
Enjoy it, and if you have any questions leave them in the comments!