Showing posts with label SSH. Show all posts
Showing posts with label SSH. Show all posts

Lamp install on Ubuntu with few clicks

Easiest way to install Lamp Server. I have found after googling for two hours. I thought to share with you so you can also get benefit from it.

sudo apt-get install tasksel 
sudo tasksel install lamp-server 

After you will be prompted to enter mysql root password . Enter the root password for Mysql and press enter. It will install most rexommended php modules.

If you want to install phpmyadmin run below command:

sudo apt-get install libapache2-mod-auth-mysql php5-mysql phpmyadmin

Mysql- How can I access the MySQL command line with XAMPP for Windows?

Follow the following steps-

Step 1:
Open command prompt














Step 2:
cd c:\xampp\mysql\bin
Step 3:
mysql.exe -u root 

SSH- How to export/import a MySQL database via SSH

Question: How can we export/import a MySQL database via SSH commands?

Answer: we can export/import a MySQL database using below commands.

USERNAME - the MySQL user assigned to your database.

DATABASE - the name of your MySQL database.

1. Exporting a MySQL database

mysqldump -uUSERNAME -p DATABASE > backup.sql 

2. Importing a MySQL database

mysql -uUSERNAME -p DATABASE < backup.sql 

SSH- List of Basic SSH Commands

SSH CommandExplanation
lsShow directory contents (list the names of files).
cdChange Directory.
mkdirCreate a new folder (directory).
touchCreate a new file.
rmRemove a file.
catShow contents of a file.
pwdShow current directory (full path to where you are right now).
cpCopy file/folder.
mvMove file/folder.
grepSearch for a specific phrase in file/lines.
findSearch files and directories.
vi/nanoText editors.
historyShow last 50 used commands.
clearClear the terminal screen.
tarCreate & Unpack compressed archives.
wgetDownload files from the internet.
duGet file size.

SSH- How to create php files in /var/www folder?

Question:  How can we create php files in /var/www folder using SSH command?
Answer:
-Create the file

sudo touch hello.php

-Open the file

sudo vi hello.php

Enter write mode (we were in command mode initially) by pressing  a  (note that    vi   is case sensitive)

After that, press Esc (to change to command mode) and type :wq Check if everything is fine with
cat hello.php

However, it's probably a better idea to use editors such as vim or nano as work with them is a lot simpler than that.

SSH- Change all files and folders permissions of a directory to 644/755

SSH- Change all files and folders permissions of a directory to 644/755
 
find * -type d -print0 | xargs -0 chmod 0755 # for directories
find . -type f -print0 | xargs -0 chmod 0644 # for files
For WordPress -
All files should be 664.
All folders should be 775.
wp-config.php should be 660.

SSH- Useful SSH commands

SSH- Useful SSH commands

1. Access monitor

 mysql -u [username] -p; (will prompt for password)

2. Show all databases:

 show databases;

3. Access database:

 mysql -u [username] -p [database] (will prompt for password)

4.Create new database:

 create database [database];

5.Select database:

 use [database];

6. Determine what database is in use:

 select database();

7. Show all tables:

 show tables;

8. Show table structure:

 describe [table];

9. List all indexes on a table:

 show index from [table];

10. Create new table with columns:

 CREATE TABLE [table] ([column] VARCHAR(120), [another-column] DATETIME);

11. Adding a column:

 ALTER TABLE [table] ADD COLUMN [column] VARCHAR(120);

12. Adding a column with an unique, auto-incrementing ID:

 ALTER TABLE [table] ADD COLUMN [column] int NOT NULL AUTO_INCREMENT PRIMARY KEY;

13. Inserting a record:

 INSERT INTO [table] ([column], [column]) VALUES ('[value]', [value]');

14. MySQL function for datetime input:

 NOW()

15. Selecting records:

 SELECT * FROM [table];

16.Explain records:

 EXPLAIN SELECT * FROM [table];

17. Selecting parts of records:

 SELECT [column], [another-column] FROM [table];

18. Counting records:

 SELECT COUNT([column]) FROM [table];

19.Counting and selecting grouped records:

 SELECT *, (SELECT COUNT([column]) FROM [table]) AS count FROM [table] GROUP BY [column];

20. Delete all records in a table:

 truncate table [table];

21. Removing table columns:

 ALTER TABLE [table] DROP COLUMN [column];

22. Deleting tables:

 DROP TABLE [table];

23.Deleting databases:

 DROP DATABASE [database];

24. Custom column output names:

 SELECT [column] AS [custom-column] FROM [table];

25. Export a database dump:

 mysqldump -u [username] -p [database] > db_backup.sql

26. Import a database dump (more info here):

 mysql -u [username] -p -h localhost [database] < db_backup.sql

27. Logout:

 exit;