Categories
MySQL PHP

Getting started with AMP stack on Mac OS X Lion

The other day, I got myself a Macbook Pro which runs OS X Lion. Coming from the Linux world where everything is available at finger tips via package managers, I was at first lost. I tried MAMP and Zend Server CE. I had some issues with Zend Server CE and custom virtual hosts – mostly because I couldn’t figure out which bits to be changed. MAMP worked out pretty well. But I wanted to use the native builds of the AMP stack. I know about macports and homebrew but wanted to do things myself!

(1) Mac OS X ships with built in apache. I enabled “Web Sharing” from System Preference > Sharing. It turned on viewing of my ~/Sites directory at http://localhost/~masnun/. It works but not pretty helpful.

(2) I edited /etc/apache2/httpd.conf to change the document root to ~/Sites. Now I could see my home page on localhost.

(3) I tried creating virtual hosts at ~/VirtualHosts – this worked with MAMP but with the built in Apache, it can not load the virtualhosts from that location because of permission issues. So instead, I reinstated the default location for vhosts inside the “extra” directory. I appended all my virtualhosts in one file. It works!

(4) “NameVirtualHosts *” and a separate virtual host for localhost is must.

(5) Mac OS X has a built in PHP. I just created the default php configuration file at /etc/php.ini

(6) I downloaded MySQL from their website. Installed the packages and imported my existing databases.

(7) PHP by default expects the mysql unix socket to be in /var/mysql/mysql.sock but the package from mysql creates the socket at /tmp/mysql.sock. So I had to edit the socket for mysql, pdo-mysql and mysqli. I needed to change them all because WP uses mysql, phpmyadmin uses mysqli and ZF uses pdo.

(8) I ran the pear installer (as a phar file inside /usr/lib/php) to install pear and pecl.

(9) To install mcrypt extension, I downloaded libmcrypt and source of PHP 5.3.10. I changed directory to PHP’s mcrypt extension directory. Ran “phpize”, “make” and “sudo make install”. Copied the generated extension to my custom extensions directory.

(10) Restarted apache at every step. It’s now working fine 🙂

Categories
Linux MySQL

Import SQL Script to MySQL using the Command Line

Summary: We have acquired a large databse dump which we need to import into our local system. Since the database size is large, phpmyadmin can’t help. MySQL command line tool comes to our rescue 🙂


Change directory to where our SQL script is:

First login to mysql:

Change database to our target database:

Execute the SQL Script:

Categories
Linux

Configuring Amazon EC2 Instance with Ubuntu: Enabling remote root access

The other day, I was setting up an amazon EC2 instance for Leevio. It is a rare experience since we do not setup a new instance everyday! 😀 So, I am gonna share what I did to do what.

First, Hasin vai gave me a secret email address and a password which I used to login to the Amazon backend. There are quite a number of tabs for different services. I chose the EC2 tab. There was no instance created, so I went ahead and created a new instance. While creating it I was driven through a simple configuration wizard. It asked me to select the instance type, create some tags for the instance and choose a operating system image and finally I created network access permission. I chose Ubuntu 11.10 (the then latest one). The permission set dictates which IPs shall get access to which ports. I opened up port 80 for http connection and port 22 for SSH and SFTP. There are preset settings to open all TCP ports, UDP ports and All ports etc. You can choose the access level manually or pick one of this presets. I did manually since I wanted to learn how it worked.

Then I saved the ssh keys and secured them in a secret place on my HDD 😀 I also noted the public DNS of the instance. I typed in the following command to login to the ubuntu machine running on the instance:

The first problem I got is the “too open permission” for the key file. In fact if your key file has such a permission that other users on the same machine can access it, you can not use the key. Keys are meant to be private and make them private by issuing the following command:

Now I issued the previous command and I got in! Yay! 😀

My default username is “ubuntu”. To configure stuff, I need to be “root”. So I hit:

By default the root username doesn’t have a password. When prompted for a password, just press enter. I logged in as root. But wait, I am using a Linux machine and the root user has no password? I can’t stand that! So I decided to change the password of root account first. The process is simple:

I was asked twice the password and upon confirmation, the root account now had a super secret password which is known to only me in the whole universe 😀

The second issue we still have is that root user still can’t login via ssh. To do so, we have to enable PasswordAuthentication on the server. With my mighty root power, I installed vim on the fly and edited the heart of ssh daemon:

I navigated to the “PasswordAuthentication” section and changed it’s value from “no” to “yes”. Then I reloaded the daemon by typing:

Then I typed in these commands to exit the root shell and logout from the remote shell:

I then assigned an IP address to the instance from the IP management section and reloaded the instance. Now I can login to the server from my laptop using the command:

PS: Using the key pair to login is a more secured and recommended way of doing the stuff. But it’s easier to do stuff using remote root login.