3 articles Tag ubuntu

Setting up a complete PHP development environment on ubuntu 12.04+

ubuntu

Last week, I had do reinstall my laptop and setup the complete php development environment. This includes the apache2 web server, php5, mysql, phpmyadmin, git, and a good php editor. Thought that this setup could be useful for other php developers who want to use Ubuntu, so I’m sharing a step by step guide here :)

Before going any further, lets get something clear: this is for local / development environments, not for production servers! :)

First things first

Do you already have Ubuntu installed, right? I will not give advice on this, but you may find everything you need do install Ubuntu here: http://www.ubuntu.com/download

I’m currently using the 12.04, the LTS (long-term support) version. I downgraded from 12.10 after getting a lot of weird problems with my audio, and It solved the problem. This instructions will work fine for other Ubuntu recent versions, though.

I don’t like Unity, so I installed Gnome 3 which is amazing for me. Of course everybody has its own tastes, so feel free to use whatever you want as a desktop environment. But if you want to try Gnome 3, installing it is a piece of cake:

sudo add-apt-repository ppa:gnome3-team/gnome3
sudo apt-get update
sudo apt-get install gnome-shell

Web Server

This 3 commands will install the local server, in this order: Apache 2, MySQL*, PHP 5.

sudo apt-get install apache2
sudo apt-get install mysql-server php5-mysql
sudo apt-get install php5 libapache2-mod-php5

Ps* When installing MySQL, you will be prompted to provide a password for the root mysql account.

Now your webserver shall be installed and running. Point your browser to http://localhost and you will get this:

Screenshot from 2013-03-27 20:46:33

 

The Apache’s Document Root, by default, is located at /var/www on Ubuntu. You can easily change this to a directory which best suits your needs. Just edit the file /etc/apache2/sites-enabled/000-default with an editor of your choice (just remember you need to use sudo).

Change all “/var/www” to your desired path – there are 2 places (lines 4 and 9).

Screenshot from 2013-03-27 22:57:56

You will probably want to have URL rewriting enabled, so I recommend you also edit line 11 and change “None” for “All” (AllowOverride All).

After doing this, you need to restart Apache for your changes take effect.

sudo apache2ctl restart

Now, if you reload http://localhost you will get your new document root, which can be a directory structure (easy to navigate between different projects without any extra effort, but may be a problem to some project implementations).

You can also create a VirtualHost for a specific project, so you can access it with a url like this: http://myfakedomain.local. This scenario makes your environment more similar to what you have at production servers, and it’s not hard to set up.

Setting up an Apache VirtualHost

You just need to edit 2 files. First, create an entry inside your /etc/hosts file (use sudo to open the file otherwise you cannot save it). Add your desired fake local domain name, like this:

127.0.0.1        myfakedomain.local

Now, edit the same file you opened before – /etc/apache2/sites-enabled/000-default . You need to add a VirtualHost entry. As we are going to use name-based virtualhost, we also need to add this at the top of the file:

NameVirtualHost *:80

Then, add the VirtualHost section:

<VirtualHost *:80>
 ServerAdmin your@email.com
 DocumentRoot "/path/to/your/project"
 ServerName myfakedomain.local
</VirtualHost>

Now, just restart Apache and try http://myfakedomain.local in your browser.

We have our server running, and now let’s get some extras.

PhpMyAdmin

Installing:

sudo apt-get install phpmyadmin

You will be prompted to choose the web server (apache) and to provide the mysql root password.

After  this, PhpMyAdmin will be available in http://localhost/phpmyadmin , and you will be able to access it directly (without providing password).

GIT

Installing is quite straightforward:

sudo apt-get install git

Now configure your git user:

git config --global user.name "Your Name Here"
git config --global user.email "your_email@example.com"

And run this to have a colored git (like code highlighting – way better to read).

git config --global color.ui true

Sublime Text 2

Sublime is probably the best complete (and lightweight… and awesome) editor available for free nowadays. They gentle ask that you buy a license, but there aren’t any restrictions or limitations in the version we download for free. Sometimes it will show a silent popup to remember you about the license stuff, and that’s all.

sudo add-apt-repository ppa:webupd8team/sublime-text-2
sudo apt-get install sublime-text

Did I forget something?

If you want to suggest something, please leave a comment! Keep in mind that this is a *very* generic starting point for a php development environment, really the basics for getting started.

 

How to fix ubuntu apt-get connection problems

Today I tried to install LAMP on my notebook and got a lot of errors from Ubuntu apt-get, related to connection problems – the server (br server) from which it was trying to download the updates was apparently down. If you ever get these kind of errors on apt-get:

Err http://br.archive.ubuntu.com/ubuntu/ precise/main libapr1 amd64 1.4.6-1
Something wicked happened resolving 'br.archive.ubuntu.com:http' (-5 - No address associated with hostname)

And your internet seems to be ok (in a nutshell, the archive server is offline), there’s a super easy way to fix it: just go to Ubuntu Software Center, then select the “Edit  -> Software Sources…”.

Screenshot-from-2013-01-09-112435

You can change it to “Server for United States” or another location which suits you better. Then, run a

sudo apt-get update

And that’s all. You can try to install your software again and it will be okay (unless you’re facing internet problems).

Solving VirtualBox problem in Ubuntu Gnome Remix 12.10

imgvirtualbox1Recently, I installed in my new notebook the Ubuntu Gnome Remix 12.10. Its a fantastic remix from Ubuntu, I am completely in love with this version – although sometimes I get some weird bugs related to package installations.

The most recent problem I had was related to Virtualbox. I installed it from apt-get and it looked ok, but when I tried to start the newly created VM I got this error:

Kernel driver not installed (rc=-1908)
The VirtualBox Linux kernel driver (vboxdrv) is either not loaded or there is a permission problem with /dev/vboxdrv. Please reinstall the kernel module by executing ‘/etc/init.d/vboxdrv setup’ as root. If it is available in your distribution, you should install the DKMS package first. This package keeps track of Linux kernel changes and recompiles the vboxdrv kernel module if necessary.

I did some Googling but nothing seemed to work… This “/etc/init.d/vboxdrv” file didn’t exist. I found just a “virtualbox” script inside init.d folder, so after trying to execute it, I got this message:

erika@velvet:/etc/init.d$ sudo virtualbox setup
WARNING: The character device /dev/vboxdrv does not exist.
Please install the virtualbox-ose-dkms package and the appropriate headers, most likely linux-headers-generic.

You will not be able to start VMs until this problem is fixed.

What I did:

sudo apt-get install linux-headers-generic virtualbox-ose-dkms

So, after this, I ran:

sudo dpkg-reconfigure virtualbox-dkms

sudo dpkg-reconfigure virtualbox

And the problem was solved. Hope this can help someone out there!