Tuesday, August 21, 2012

Set up Ubuntu virtualbox to edit client site locally


Set up Ubuntu virtualbox to edit client site locally

aka

Pull .git repo to virtualbox and install LAMPP in Ubuntu 12.04



~~~~~~~~~~~~~~~~~~~~~~~~~~

Pull .git repository


Step 1

Create Development folder under /home/your_Ubuntu_username/Documents/Development.


Step 2

Open terminal (in virtualbox) and install git:

> sudo apt-get install git


Step 3

Go to bitbucket and navigate to repository you want to pull.


Step 4

In the open terminal,enter the clone command from the bitbucket site. For example:

git clone https://bitbucket_email_address/folder/site_folder.git

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Install LAMPP


Step 1

Login as root, type this command in the terminal and enter your Ubuntu password. You can launch the terminal command line by pressing Control- ALT- T:
> sudo -s -H

Step 2

The first thing to install is the MySQL server. Enter this command:
> apt-get install mysql-server mysql-client
It will start downloading packages, so you have to wait. Then you will be required to enter your MySQL root password. Make sure you will remember this as you will be using this during WordPress installation. The username will default to “root”.

Step 3

The next thing to install will be Apache. This is your web server. Type the command below:
> apt-get install apache2

Step 4

You will then need to install PHP. This is the server scripting language used by WordPress. Enter this command:
> apt-get install php5 libapache2-mod-php5

Step 5

After installing PHP, you need to restart the Apache server by entering this command:
> /etc/init.d/apache2 restart

Step 6

In the command prompt, navigate to your Ubuntu home directory by entering the command:
> cd /home/your_Ubuntu_username/Documents/Development
Replace “your_Ubuntu_username” with your correct username. To make sure you are now in your Ubuntu home directory, type this command:
> pwd
It should return:
/home/your_Ubuntu_username/Documents/Development

Step 7

Confirm that your site folder is in your Development folder.

Step 8

It is time to assign proper file permissions to document root folder that will be used by Apache and WordPress. First, change the CHMOD of your site folder folder to 755:
> chmod -R 755 site_folder
This will make the www folder readable/writable by Apache which is important. The additional parameter -R means that all files/folders inside the folder (e.g. your WordPress files) will get that permission as well.

Step 9

Next, you need to ensure that Apache has permissions to read and write your home directory. Enter this command:
chmod 755 /home/your_Ubuntu_username/Documents/Development
and:
chmod 755 /home/your_Ubuntu_username/Documents/
and:
chmod 755 /home/your_Ubuntu_username/
and:
chmod 755 /home/
The main purpose of doing this is to prevent 403 forbidden errors in Apache when accessing your WordPress website or any HTML/PHP files after changing your document root in Step10.

Step 10

Confirm that you have correctly set permissions by running the following set of commands:
a.) Check if your site folder directory is now using 755 as the permission:
stat -c '%a' /home/your_Ubuntu_username/Documents/Development/site_folder
You should see 755 as the return value.
b.) Check the rest of your directories using 755:
stat -c '%a' /path/you/are/checking

Step 11

By default (after Apache installation in Step3); the document root of Apache accessible by the web browser is found in this path:
/var/www
In the previous steps, you have changed it to use your Ubuntu home directory such that the new path will be:
/home/your_Ubuntu_username/Documents/Development/site_folder
This new path is now configured with proper file permissions that Apache can access. Finally, you need to configure your Apache configuration to use this new path. Follow the steps below carefully and make sure you are still logged-in as root:
a.) Open the enabled sites configuration in Apache using the terminal:
pico /etc/apache2/sites-enabled/000-default
The text editor should look like this:
b.) Change the two instances of /var/www to use your new document root path found in your Ubuntu home directory. For example this is the edited version:

You need to be careful not to change any of the existing lines or code. To save the changes; press Control – Othen press enter. To exit the editor, press Control – X.

Step 12

Restart Apache:
/etc/init.d/apache2 restart

Step 13

WordPress will be using a lot of PHP modules for proper operation. You should also install these modules. Copy and paste the command below to the terminal:
apt-get install php5-mysql php5-curl php5-gd php5-intl php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl

Step 14

Restart Apache again:
/etc/init.d/apache2 restart

Step 15

Using your favorite code editor (gedit will do), create a PHP file called as info.php containing the following code to test your Apache and MySQL installation:
<?php
phpinfo();
?>
Save info.php to your document root folder path:
/home/your_Ubuntu_username/Documents/Development/site_folder

Step 16

Now access info.php in the web browser by typing this in the address bar:
http://localhost/info.php
You should be able to see the details of your PHP configuration settings without any errors.


Step 17

Installing phpMyadmin
phpMyAdmin is a free software tool written in PHP intended to handle the administration of MySQL over the World Wide Web.
Open Terminall. And type the below code in terminal and hit enter.
sudo apt-get install phpmyadmin
Type your ubuntu password if needed.
Type y and hit enter to confirm phpMyadmin installation.
During the installation you will be prompted for a webserver configuration.
Select
apache2
(already selected)
press enter.

Now you will be promped for phpmyadmin configuration
Select
No
and press enter.

Type below command in terminal
sudo cp /etc/phpmyadmin/apache.conf /etc/apache2/conf.d
restart your apache server using
sudo /etc/init.d/apache2 restart
Open your browser and type
http://localhost/phpmyadmin/
in the address bar and press enter.
Type your mysql root  username and password to login.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Upload database to phpMyAdmin

Step 1

Open wp-config.php file in site folder.
Comment out the line that says define('DB_HOST', 'host_name'); by putting // in front of it.
Add a new line that says define('DB_HOST', 'localhost');

Step 2

Open a browser and type in http://localhost/phpmyadmin.
Login using the credentials found in the wp-config.php file.
Click on Databases - the first tab along the top.
Under create new database, paste the name of the database from the wp-config.php file and click Create.
Click on the database you just created from the list on the left.
Click on Privileges - the last tab along the top.
Click on Add a new User link and add the user, using the username and password from the wp-config.php file and granting the user all (global) privileges.

Step 4

Click on your database from the list at the left.
Click on import and select your database file (.sql). Zip it if necessary. Import it into your new database.

Step 5

Go back to the browser and type in http://localhost. Your site should now load in the browser window.

No comments: