Page not found – ShopingServer Wiki http://wiki.shopingserver.com Tutorials and Articles About Technology and Gadgets Wed, 02 Sep 2020 02:26:11 +0000 en-US hourly 1 https://wordpress.org/?v=5.5.14 http://wiki.shopingserver.com/wp-content/uploads/2018/07/cropped-favicon-150x150.png Page not found – ShopingServer Wiki http://wiki.shopingserver.com 32 32 WordPress MySql Statement To Delete All Pending Comments http://wiki.shopingserver.com/wordpress-mysql-statement-delete-pending-comments/ http://wiki.shopingserver.com/wordpress-mysql-statement-delete-pending-comments/#respond Sat, 06 Jan 2018 09:19:18 +0000 http://wiki.shopingserver.com/?p=18521 I

have over 1800+ pending comments and most of them are spams in WordPress based blog. How do I delete all (mass delete) the pending comments using sql statements?

 

You can delete all pending comments from your database. WordPress has wp_comments table. This table can be used to store, retrieve, modify and delete comments.

Procedure to delete all the pending comments from your database

First, login to your remote or local server over the ssh based sesson.

Next, type the following command to login into your mysql database:

Warning: Before you get started with the following commands, it’s a good idea to back up your database. This means if there are any issues you can easily restore your database. See how to backup your database for more information.

mysql -u Your-DB-User-Name-Here -p Your-DB-Name-Here

OR

mysql -u Your-DB-User-Name-Here -h Db-Server-IP-Or-HostName -p Your-DB-Name-Here

In this example, login to db called blog as foo user on localhost:

mysql -u foo -p db

OR

mysql -u foo -h localhost -p db

Once logged in type the following desc wp_comments; command to see wp_comments structure:

mysql> desc wp_comments;

Sample outputs:

+———————-+———————+——+—–+———————+—————-+

| Field                | Type                | Null | Key | Default             | Extra          |

+———————-+———————+——+—–+———————+—————-+

| comment_ID           | bigint(20) unsigned | NO   | PRI | NULL                | auto_increment |

| comment_post_ID      | bigint(20) unsigned | NO   | MUL | 0                   |                |

| comment_author       | tinytext            | NO   |     | NULL                |                |

| comment_author_email | varchar(100)        | NO   |     |                     |                |

| comment_author_url   | varchar(200)        | NO   |     |                     |                |

| comment_author_IP    | varchar(100)        | NO   |     |                     |                |

| comment_date         | datetime            | NO   |     | 0000-00-00 00:00:00 |                |

| comment_date_gmt     | datetime            | NO   | MUL | 0000-00-00 00:00:00 |                |

| comment_content      | text                | NO   |     | NULL                |                |

| comment_karma        | int(11)             | NO   |     | 0                   |                |

| comment_approved     | varchar(20)         | NO   | MUL | 1                   |                |

| comment_agent        | varchar(255)        | NO   |     |                     |                |

| comment_type         | varchar(20)         | NO   |     |                     |                |

| comment_parent       | bigint(20) unsigned | NO   | MUL | 0                   |                |

| user_id              | bigint(20) unsigned | NO   |     | 0                   |                |

+———————-+———————+——+—–+———————+—————-+

15 rows in set (0.00 sec)

To see all the pending comments, type:

mysql> select * from wp_comments where comment_approved =  0 ;

Or better just show all the pending comment count, enter:

mysql> select count(*) from wp_comments where comment_approved =  0 ;

Sample outputs:

+———-+

| count(*) |

+———-+

|       18 |

+———-+

1 row in set (0.01 sec)

Sql statement to delete all pending comments

Type the following command at mysql> prompt>

mysql> delete from wp_comments where comment_approved =  0 ;

Sample outputs:

Query OK, 18 rows affected (0.09 sec)

To quite from mysql session, enter:

mysql> quit;

 

 

]]>
http://wiki.shopingserver.com/wordpress-mysql-statement-delete-pending-comments/feed/ 0
HowTo: Reinstall MySQL v5.x On Linux http://wiki.shopingserver.com/howto-reinstall-mysql-v5-x-linux/ http://wiki.shopingserver.com/howto-reinstall-mysql-v5-x-linux/#respond Sat, 06 Jan 2018 08:59:01 +0000 http://wiki.shopingserver.com/?p=18497 M

y MySQL database installation has been corrupted. I would like to delete old mysql server. How do I reinstall MySQL database server version 5.x on Linux or Unix-like oses? A software upgrade broke my system. How can I uninstall and re-install mysql again to get fresh full mysql again?

 

You can easily reinstall mysql server on Linux or Unix-like operating system. The steps are as follows:

Backup database and all config files

Erase/uninstall existing mysql server/client.

Delete all files data directory.

Delete all mysql config files.

Completely reinstall mysql server.

Restore config files and database.

Step #1: Backup backup backup

Make a backup – it cannot be stressed enough how important it is to make a backup of your system before you do this. You need to backup

MySQL database data directory (e.g. /var/lib/mysql/.

MySQL databases using mysqldump command.

Mysql config files /etc/my.cnf, /etc/logrotate.d/mysqld, and other files.

Mysql log files (e.g. /var/log/mysqld.log.

In this example, I am backing up all important files on CentOS/RHEL 6.x based server:

# mkdir /root/mysql-files/

# tar zcvf /root/mysql-files/mysql.config-files.dd-mm-yyyy.tar.gz /etc/logrotate.d/mysqld /var/log/mysqld.log /etc/my.cnf /root/my.cnf /var/lib/mysql/

 

In this example, I am backing up all databases using a shell script called mysql-backup.sh:

#!/bin/sh

# mysql-backup.sh: Dump MySQL databases.

# Note: Test only on RHEL/CentOS/Debian/Ubuntu Linux.

# Author: nixCraft <www.cyberciti.biz> Under GPL v2.0+

# —————————————————–

NOW=$(date + %d-%m-%Y )

BAK= /root/mysql-files/$NOW

 

############

SET ME FIRST ##

############

MUSER= root

MPASS= YOUR-ROOT-PASSWORD-HERE

MHOST= localhost

 

MYSQL= $(which mysql)

MYSQLDUMP= $(which mysqldump)

GZIP= $(which gzip)

 

if [ ! -d $BAK ]; then

mkdir -p $BAK

else

:

fi

 

DBS= $($MYSQL -u $MUSER -h $MHOST -p$MPASS -Bse  show databases )

echo -n  Dumping…${THISDB}…

for db in $DBS

do

echo -n  $db

FILE=$BAK/mysql-$db.$NOW-$(date + %T ).gz

$MYSQLDUMP -u $MUSER -h $MHOST -p$MPASS $db | $GZIP -9 > $FILE

done

echo -n   …Done @ ${BAK} directory.

echo

Run it as follows

$ ./mysql-backup.sh

 

Sample outputs:

Dumping……blog cyberciti mysql…Done @ /root/mysql-files/08-12-2013 directory.

Verify backups:

# ls -l /root/mysql-files/08-12-2013

 

Sample outputs:

-rw-r–r–. 1 root root  1836687 Dec  8 04:00 mysql-blog.08-12-2013-04:00:18.gz

-rw-r–r–. 1 root root  7152648 Dec  8 04:00 mysql-cyberciti.08-12-2013-04:00:25.gz

-rw-r–r–. 1 root root   135530 Dec  8 04:00 mysql-mysql.08-12-2013-04:00:41.gz

I suggest that you read our previous guide “HowTo: Migrate / Move MySQL Database And Users To New Server” for more information.

Step #2: Erase/Delete MySQL server

If you are using Debian/Ubuntu Linux type the following apt-get command:

$ sudo apt-get purge mysql-server mysql-common mysql-client

 

Sample outputs:

Reading package lists… Done

Building dependency tree

Reading state information… Done

Package mysql-client is not installed, so not removed

The following packages were automatically installed and are no longer required:

libnet-daemon-perl libdbi-perl libterm-readkey-perl mysql-server-core-5.5 mysql-client-core-5.5

libplrpc-perl

Use  apt-get autoremove  to remove them.

The following packages will be REMOVED:

libdbd-mysql-perl* libmysqlclient18* mysql-client-5.5* mysql-common* mysql-server*

mysql-server-5.5*

0 upgraded, 0 newly installed, 6 to remove and 2 not upgraded.

After this operation, 67.3 MB disk space will be freed.

Do you want to continue [Y/n]? y

(Reading database … 82128 files and directories currently installed.)

Removing mysql-server …

Removing mysql-server-5.5 …

mysql stop/waiting

Purging configuration files for mysql-server-5.5 …

Removing mysql-client-5.5 …

Removing libdbd-mysql-perl …

Removing libmysqlclient18 …

Purging configuration files for libmysqlclient18 …

Removing mysql-common …

Purging configuration files for mysql-common …

dpkg: warning: while removing mysql-common, directory  /etc/mysql  not empty so not removed.

Processing triggers for man-db …

Processing triggers for ureadahead …

Processing triggers for libc-bin …

ldconfig deferred processing now taking place

Delete config/database/log files using rm command:

$ sudo rm -rvfi /var/lib/mysql /etc/mysql/ /var/log/mysql*

If you are using CentOS/RHEL/Fedora/Red Hat/Scientific Linux type the following yum command to uninstall mysql:

# yum remove mysql mysql-server

 

Sample outputs:

Loaded plugins: product-id, rhnplugin, security, subscription-manager

This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.

This system is receiving updates from RHN Classic or RHN Satellite.

Setting up Remove Process

Resolving Dependencies

–> Running transaction check

—> Package mysql.x86_64 0:5.1.71-1.el6 will be erased

—> Package mysql-server.x86_64 0:5.1.71-1.el6 will be erased

–> Finished Dependency Resolution

 

Dependencies Resolved

 

======================================================================================================

Package                Arch             Version                Repository                       Size

======================================================================================================

Removing:

mysql                  x86_64           5.1.71-1.el6           @rhel-x86_64-server-6           2.4 M

mysql-server           x86_64           5.1.71-1.el6           @rhel-x86_64-server-6            25 M

 

Transaction Summary

======================================================================================================

Remove        2 Package(s)

 

Installed size: 27 M

Is this ok [y/N]: y

Downloading Packages:

Running rpm_check_debug

Running Transaction Test

Transaction Test Succeeded

Running Transaction

Erasing    : mysql-server-5.1.71-1.el6.x86_64                                                   1/2

Erasing    : mysql-5.1.71-1.el6.x86_64                                                          2/2

Verifying  : mysql-server-5.1.71-1.el6.x86_64                                                   1/2

Verifying  : mysql-5.1.71-1.el6.x86_64                                                          2/2

 

Removed:

mysql.x86_64 0:5.1.71-1.el6                    mysql-server.x86_64 0:5.1.71-1.el6

 

Complete!

Delete config/database/log files using rm command:

[code]# rm -rfvi /etc/my.cnf /var/lib/mysql/ /var/log/mysqld.log[/code]

Step #3: Reinstall mysql database server

If you are using CentOS/RHEL/Fedora/Red Hat/Scientific Linux type the following yum command to install mysql:

# yum install mysql mysql-server

If you are using Debian/Ubuntu Linux type the following apt-get command:

$ sudo apt-get install mysql-client mysql-server mysql-common

Step #4: Restore config files and databases

Restore all config files and databases as demonstrated in step #1. See how to restore a backup of a mysql database:

$ gunzip mysql-blog.08-12-2013-04:00:18.gz

$ mysql -u root -p mysql -e  CREATE DATABASE blog;

$ mysql -u root -p blog < mysql-blog.08-12-2013-04\:00\:18

 

Restore mysql config file as follows:

# tar xvf /root/mysql-files/mysql.config-files.dd-mm-yyyy.tar.gz -C /root/backups/

# cp /root/backups/etc/my.cnf /etc

# service mysqld restart

 

This entry is 5 of 5 in the CentOS Linux MySQL Server Tutorial series. Keep reading the rest of the series:

CentOS install Mysql database server

CentOS install MySQL client only

MySQL Create a user accounts

MySQL Create a database & tables and data

Reinstall MySQL On Linux

 

 

]]>
http://wiki.shopingserver.com/howto-reinstall-mysql-v5-x-linux/feed/ 0
HowTo: Uninstall MySQL Server in Ubuntu Linux http://wiki.shopingserver.com/howto-uninstall-mysql-server-ubuntu-linux/ http://wiki.shopingserver.com/howto-uninstall-mysql-server-ubuntu-linux/#respond Sat, 06 Jan 2018 08:09:03 +0000 http://wiki.shopingserver.com/?p=18439 I

‘m a new Ubuntu Linux user and my cloud hosting company installed MySQL server by default. I need to remove it and delete it from my server as I have no use of MySQL server. How can I uninstall MySQL on a Ubuntu based systems?

 

Typically following Mysql packages are installed on the Debian or Ubuntu Linux systems:

mysql-client – The latest version of MySQL database client.

mysql-server – The latest version of MySQL database server.

mysql-common – MySQL database common files.

How do I uninstall Mysql server?

Just use the apt-get command as follows remove both MySQL server and client in Ubuntu Linux:

sudo apt-get –purge remove mysql-client mysql-server mysql-common

sudo apt-get autoremove

Sample outputs (pay attention to package names):

Reading package lists… Done

Building dependency tree

Reading state information… Done

The following packages were automatically installed and are no longer required:

linux-headers-3.2.0-31-virtual linux-headers-3.2.0-31

Use  apt-get autoremove  to remove them.

The following packages will be REMOVED:

libdbd-mysql-perl* libmysqlclient18* mysql-client* mysql-client-5.5* mysql-common* mysql-server*

mysql-server-5.5*

0 upgraded, 0 newly installed, 7 to remove and 0 not upgraded.

After this operation, 67.5 MB disk space will be freed.

Do you want to continue [Y/n]? y

(Reading database … 105097 files and directories currently installed.)

Removing mysql-server …

Removing mysql-server-5.5 …

mysql stop/waiting

Purging configuration files for mysql-server-5.5 …

Removing mysql-client …

Removing mysql-client-5.5 …

Removing libdbd-mysql-perl …

Removing libmysqlclient18 …

Purging configuration files for libmysqlclient18 …

Removing mysql-common …

Purging configuration files for mysql-common …

dpkg: warning: while removing mysql-common, directory  /etc/mysql  not empty so not removed.

Processing triggers for ureadahead …

Processing triggers for man-db …

Processing triggers for libc-bin …

ldconfig deferred processing now taking place

Delete /etc/mysql/ directory using rm command:

$ sudo rm -rf /etc/mysql/

Understanding apt-get command options

–purge : Remove given packages and config files.

remove : Uninstall packages.

autoremove : Force to remove packages that were automatically installed to satisfy dependencies for other packages and are now no longer needed.

See also

Ubuntu Linux: Install MySQL Server Version 5

 

 

]]>
http://wiki.shopingserver.com/howto-uninstall-mysql-server-ubuntu-linux/feed/ 0
CentOS and RHEL 7: Install Linux, Apache, MariaDB, PHP (LAMP) Stack http://wiki.shopingserver.com/centos-rhel-7-install-linux-apache-mariadb-php-lamp-stack/ http://wiki.shopingserver.com/centos-rhel-7-install-linux-apache-mariadb-php-lamp-stack/#respond Sat, 06 Jan 2018 07:45:08 +0000 http://wiki.shopingserver.com/?p=18407 I

am new Red Hat Enterprise Linux version 7 user/sysadmin/developer. This version made the big number change for RHEL 7/CentOS 7. How can I install LAMP (Linux, Apache, MariaDB, PHP) stack on a RHEL version 7 or CentOS Linux version 7 using CLI or over ssh based session?

 

RHEL 7 has been released and CentOS Linux 7 is on its way with many notable changes. This guide explains how to install LAMP server.

More about LAMP

LAMP is nothing but a software bundle or a platform consisting of Linux operating system, Apache web-server, MySQL database server and PHP (or Perl/Python)scripting language. The LAMP stack is used for building heavy-duty dynamic web sites entirely out of free and open-source software. In this tutorial, I’m going to explain how to Linux, Apache, MySQL/MariaDB (drop in replacement for MySQL), PHP (LAMP) stack On CentOS 7 or RHEL 7.

Assumptions

I’m assuming that you’ve installed basic RHEL 7 or CentOS 7 server. Open the Terminal app and type the following command as root user.

You must be familiar with the yum command

You must know your Server’s IP address. Use the following command to find your server’s ip address for eth0 interface:

ifconfig eth0

OR

ip a show eth0

OR

ip addr list eth0 | awk  /inet /{sub(/\/[0-9]+/,  ,$2); print $2}

OR

ifconfig eth0 | awk  /inet /{print $2}

10.41.143.156

I’m going to use IP address 10.41.143.156 for testing purpose. Feel free to replace this IP address with your actual private or public IP address.

Enough talk, let’s set up LAMP stack.

Step #1: Install Apache on a CentOS 7 / RHEL 7 server

Type the following yum command to install Apache web-server:

sudo yum install httpd

 

Sample outputs:

Loaded plugins: amazon-id, rhui-lb

Resolving Dependencies

–> Running transaction check

—> Package httpd.x86_64 0:2.4.6-17.el7 will be installed

–> Processing Dependency: httpd-tools = 2.4.6-17.el7 for package: httpd-2.4.6-17.el7.x86_64

–> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-17.el7.x86_64

–> Running transaction check

—> Package httpd-tools.x86_64 0:2.4.6-17.el7 will be installed

—> Package mailcap.noarch 0:2.1.41-2.el7 will be installed

–> Finished Dependency Resolution

 

Dependencies Resolved

 

======================================================================================================

Package            Arch          Version               Repository                               Size

======================================================================================================

Installing:

httpd              x86_64        2.4.6-17.el7          rhui-REGION-rhel-server-releases        1.2 M

Installing for dependencies:

httpd-tools        x86_64        2.4.6-17.el7          rhui-REGION-rhel-server-releases         77 k

mailcap            noarch        2.1.41-2.el7          rhui-REGION-rhel-server-releases         31 k

 

Transaction Summary

======================================================================================================

Install  1 Package (+2 Dependent packages)

 

Total download size: 1.3 M

Installed size: 3.9 M

Is this ok [y/d/N]: y

Downloading packages:

(1/3): httpd-tools-2.4.6-17.el7.x86_64.rpm                                     |  77 kB  00:00:00

(2/3): httpd-2.4.6-17.el7.x86_64.rpm                                           | 1.2 MB  00:00:00

(3/3): mailcap-2.1.41-2.el7.noarch.rpm                                         |  31 kB  00:00:00


Total                                                                 2.0 MB/s | 1.3 MB  00:00:00

Running transaction check

Running transaction test

Transaction test succeeded

Running transaction

Installing : httpd-tools-2.4.6-17.el7.x86_64                                                    1/3

Installing : mailcap-2.1.41-2.el7.noarch                                                        2/3

Installing : httpd-2.4.6-17.el7.x86_64                                                          3/3

Verifying  : mailcap-2.1.41-2.el7.noarch                                                        1/3

Verifying  : httpd-tools-2.4.6-17.el7.x86_64                                                    2/3

Verifying  : httpd-2.4.6-17.el7.x86_64                                                          3/3

 

Installed:

httpd.x86_64 0:2.4.6-17.el7

 

Dependency Installed:

httpd-tools.x86_64 0:2.4.6-17.el7                   mailcap.noarch 0:2.1.41-2.el7

 

Complete!

Enable the httpd service at boot time

To make sure the httpd service start automatically at the boot time, enter:

sudo systemctl enable httpd.service

 

Sample outputs:

ln -s  /usr/lib/systemd/system/httpd.service   /etc/systemd/system/multi-user.target.wants/httpd.service

The following command will disable the httpd service at the boot time:

sudo systemctl disable httpd.service

 

Sample outputs:

rm  /etc/systemd/system/multi-user.target.wants/httpd.service

Start the httpd service on a CentOS/RHEL v7.x

sudo systemctl start httpd.service

 

At this stage, you can point your web-browser to your server’s IP address such as http://10.41.143.156). The following page should display on screen:

Fig.01: Check if Apache is Running on CentOS/RHEL 7 server

Stop the httpd service on a CentOS/RHEL v7.x

sudo systemctl stop httpd.service

Restart the httpd service on a CentOS/RHEL v7.x

sudo systemctl restart httpd.service

Finding the httpd service status on a CentOS/RHEL v7.x

To verify that the httpd service is running, enter:

systemctl is-active httpd.service

 

Sample outputs:

active

Gracefully restart the httpd service on a CentOS/RHEL v7.x

sudo apachectl graceful

Test httpd/Apache configuration file for errors on a CentOS/RHEL v7.x

sudo apachectl configtest

 

Sample outputs:

Syntax OK

httpd service default configuration

Default config file: /etc/httpd/conf/httpd.conf

Configuration files which load modules : /etc/httpd/conf.modules.d/ directory (e.g. PHP)

Select MPMs (Processing Model) as loadable modules [worker, prefork (default)] and event: /etc/httpd/conf.modules.d/00-mpm.conf

Default ports: 80 and 443 (SSL)

Default log files: /var/log/httpd/{access_log,error_log}

Step #2: Install MariaDB on a CentOS 7 / RHEL 7 server

MariaDB An enhanced, drop-in replacement for MySQL server. RHEL/CentOS v7.x shifts from MySQL to MariaDB for its database management system needs. Type the following yum command to install MariaDB server:

sudo yum install mariadb-server mariadb

 

To start mariadb, type:

sudo systemctl start mariadb.service

 

To make sure the mariadb service start automatically at the boot time, enter:

sudo systemctl enable mariadb.service

 

Sample outputs:

ln -s  /usr/lib/systemd/system/mariadb.service   /etc/systemd/system/multi-user.target.wants/mariadb.service

To stop/restart and disable mariadb service use the following commands:

sudo systemctl stop mariadb.service #<– Stop mariadb server

sudo systemctl restart mariadb.service #<– Restart mariadb server

sudo systemctl disable mariadb.service #<– Disable mariadb server

sudo systemctl is-active mariadb.service   #<– Is mariadb server running?

Securing MariaDB

Type the following command:

sudo /usr/bin/mysql_secure_installation

 

Sample outputs:

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB

SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

 

In order to log into MariaDB to secure it, we ll need the current

password for the root user.  If you ve just installed MariaDB, and

you haven t set the root password yet, the password will be blank,

so you should just press enter here.

 

Enter current password for root (enter for none): PRESS-ENTER-KEY

OK, successfully used password, moving on…

 

Setting the root password ensures that nobody can log into the MariaDB

root user without the proper authorisation.

 

Set root password? [Y/n] Y

New password: YOUR-NEW-PASSWORD-HERE

Re-enter new password: YOUR-NEW-PASSWORD-HERE

Password updated successfully!

Reloading privilege tables..

… Success!

 

 

By default, a MariaDB installation has an anonymous user, allowing anyone

to log into MariaDB without having to have a user account created for

them.  This is intended only for testing, and to make the installation

go a bit smoother.  You should remove them before moving into a

production environment.

 

Remove anonymous users? [Y/n] Y

… Success!

 

Normally, root should only be allowed to connect from  localhost .  This

ensures that someone cannot guess at the root password from the network.

 

Disallow root login remotely? [Y/n] Y

… Success!

 

By default, MariaDB comes with a database named  test  that anyone can

access.  This is also intended only for testing, and should be removed

before moving into a production environment.

 

Remove test database and access to it? [Y/n] Y

– Dropping test database…

… Success!

– Removing privileges on test database…

… Success!

 

Reloading the privilege tables will ensure that all changes made so far

will take effect immediately.

 

Reload privilege tables now? [Y/n] Y

… Success!

 

Cleaning up…

 

All done!  If you ve completed all of the above steps, your MariaDB

installation should now be secure.

 

Thanks for using MariaDB!

Test MariaDB installation

Type the following command

mysql -u root -p

 

Sample outputs:

Fig.02: Mariadb test connection on a CentOS / RHEL Linux v7.x

Step #3: Install PHP on a CentOS/RHEL v7.x

To install PHP and modules such as gd/msyql type the following yum command:

sudo yum install php php-mysql php-gd php-pear

 

You must restart the httpd (Apache) service, enter:

sudo systemctl restart httpd.service

 

To search all other php modules, type:

sudo yum search php-

 

Sample outputs:

php-cli.x86_64 : Command-line interface for PHP

php-common.x86_64 : Common files for PHP

php-gd.x86_64 : A module for PHP applications for using the gd graphics library

php-ldap.x86_64 : A module for PHP applications that use LDAP

php-mysql.x86_64 : A module for PHP applications that use MySQL databases

php-odbc.x86_64 : A module for PHP applications that use ODBC databases

php-pdo.x86_64 : A database access abstraction module for PHP applications

php-pear.noarch : PHP Extension and Application Repository framework

php-pecl-memcache.x86_64 : Extension to work with the Memcached caching daemon

php-pgsql.x86_64 : A PostgreSQL database module for PHP

php-process.x86_64 : Modules for PHP script using system process interfaces

php-recode.x86_64 : A module for PHP applications for using the recode library

php-soap.x86_64 : A module for PHP applications that use the SOAP protocol

php-xml.x86_64 : A module for PHP applications which use XML

php-xmlrpc.x86_64 : A module for PHP applications which use the XML-RPC protocol

To find more info about a module type:

sudo yum info php-pgsql

 

To install php module called php-pgsql type:

sudo yum install php-pgsql

Test PHP on your server

Create a file called /var/www/html/test.php as follows:

sudo vi /var/www/html/test.php

 

Append the following code:

<?php

phpinfo(INFO_GENERAL);

?>

Save and close the file. Point your web-browser to your server’s IP address such as http://10.41.143.156/test.php (feel free to replace the 10.41.143.156 with your actual IP address):

http://10.41.143.156/test.php

Sample outputs:

Fig.03: Test Apache+PHP with phpinfo() On a CentOS/RHEL v7.x server

In next part, I will cover the following topics (rss feed for RHEL7 or rss for CentOS7 tutorials):

Apache configuration

Virtual hosting

Apache security

mod_ssl

Perl

Firewall configuration

 

 

]]>
http://wiki.shopingserver.com/centos-rhel-7-install-linux-apache-mariadb-php-lamp-stack/feed/ 0
Install LEMP (Linux, Nginx, MySQL and PHP) Stack on Ubuntu Linux 14.04 LTS http://wiki.shopingserver.com/install-lemp-linux-nginx-mysql-php-stack-ubuntu-linux-14-04-lts/ http://wiki.shopingserver.com/install-lemp-linux-nginx-mysql-php-stack-ubuntu-linux-14-04-lts/#respond Fri, 05 Jan 2018 16:15:55 +0000 http://wiki.shopingserver.com/?p=18381 I

‘m a new Ubuntu Linux user. How do I install the LEMP stack on an Ubuntu Linux 14.04 LTS server using command line options to serve dynamic web apps?

 

As one of the most popular Linux distribution in the world, Ubuntu has released the latest version on April 17, 2014. The latest version is 14.04 with code name Trusty Tahr. Ubunt 14.04 is a LTS (Long Term Support) version. This means that Ubuntu 14.04 will be supported for the next 5 years from the release date. In this tutorial we will cover Nginx, MySQL and PHP installation on Ubuntu Linux v14.04.

What is new in Ubuntu 14.04 (Trusty Tahr) version?

You may see it on cyberciti.biz or visit the Ubuntu home page at ubuntu.com.

Nginx Installation

Nginx is one of the robust web server in Linux world. Nginx is a free, open source, high performance HTTP server and reverse proxy, as weell as an IMAP/POP3 proxy server. Now, we are going to install Nginx web server.

First, make sure system is upto date:

$ sudo apt-get update

$ sudo apt-get upgrade

#1 – Download and Install Nginx

The easiest way to download and install Nginx is using apt-get command. Here is the command:

$ sudo apt-get install nginx

 

Fig.01: Download and Install Nginx on Ubuntu Linux

 

Just wait until installation is get done on the system.

#2 – Test Nginx

Once it get done, you can open your browser and type url http://localhost or http://your_ip_address to test it. If everything goes normal, you will see Nginx welcome page:

Fig.02: Welcome nginx page on Ubuntu Linux

MySQL Installation On Ubuntu

MySQL is one of the most powerful database management system in Linux world. Next, we are going to install it with PHP support.

#1 – Install MySQL and PHP support

Type the following command:

$ sudo apt-get install mysql-server php5-mysql

 

Fig.03: Ubuntu Linux Install MySQL to Manage Site Data with PHP

 

During the installation, MySQL will ask you to enter MySQL root password, other wise the installation will not continue. Type the password you want, then press OK to continue the installation.

#2 – Test MySQL

Once mysql installation finished, we can test it. Open your console and type the following command:

$ mysql -u root -p

 

Fig.04: Ubuntu test Mysql installation

 

If you type your password correctly, the you will see the mysql prompt.

#3 – Securing access to MySQL

If we are going to use MySQL as a production database, we may want to secure it. MySQL provides a shell script to help us securing it. Just type the following command on your console:

$ sudo mysql_secure_installation

 

Here are the steps to do it.

  1. ENTER YOUR ROOT PASSWORD
  2. Enter your current root password to continue to the next step.
  3. Fig.05: MySQL enter your root db password
  4. 2.CHANGE THE ROOT PASSWORD
  5. If you want to change it, press Y. Otherwise, press N.
  6. Fig.06: MySQL security
  7. 3.REMOVE ANONYMOUS USER
  8. It is recommended to remove anonymous user to mitigate risk who can log in into your database.
  9. Fig.07: MySQL security
  10. 4.DISALLOW ROOT LOGIN REMOTELY
  11. To make sure that no one remote your database as root from another machines, we need to disallow root login remotely.
  12. Fig.08: MySQL security
  13. 5.REMOVE TEST DATABASE
  14. Sometimes some MySQL installation will create a database named ëtestí for testing purpose. We can remove it if we donít use it.
  15. Fig.09: MySQL security
  16. 6.RELOAD PRIVILEGE TABLES
  17. Then we need to reloading the privilege tables to ensure all changes made so far will take effect immediately.
  18. Fig.10: MySQL security
  19. 7.DONE
  20. Fig.11: MySQL security
  21. PHP Installation For Server Side Scripting
  22. Since PHP is popular, a lot of websites is built using PHP language. As of January 2013, PHP was installed on more than 240 millions websites. Now we are going to install PHP on Ubuntu 14.04
  23. #1 – Download and install PHP
  24. As usual, we can download and install PHP using apt-get command. Just type the following command on your Ubuntu console or over the ssh based session:
  25. $ sudo apt-get install php5-fpm

Fig.12: Install PHP for Server Side Processing on Ubuntu

 

And wait for the installation to complete.

Configure Nginx to work with PHP and MySQL Server on Ubuntu

Now we have all components installed. The next step is we need to configure Nginx with PHP and MySQL. Let’s start to configure them.

#1 – Configure PHP5-FPM

PHP5-FPM configuration file is located at /etc/php5/fpm/php.ini. Open it with your text editor

$ sudo vi /etc/php5/fpm/php.ini

 

Change this parameter, from:

cgi.fix_pathinfo=1

 

to:

cgi.fix_pathinfo=0

 

Save and close the file and then restart php5-fpm service, type:

$ sudo service php5-fpm restart

#2 – Configure Nginx

Nginx configuration file is located at /etc/nginx/nginx.conf. But basically, we don’t need to touch it. The configuration of nginx website is located in /etc/nginx/sites-available/default file.

Open it, and uncomment lines:

location ~ \.php$ {

fastcgi_split_path_info ^(.+\.php)(/.+)$;

#       # NOTE: You should have  cgi.fix_pathinfo = 0;  in php.ini

#

#       # With php5-cgi alone:

#        fastcgi_pass 127.0.0.1:9000;

#       # With php5-fpm:

fastcgi_pass unix:/var/run/php5-fpm.sock;

fastcgi_index index.php;

include fastcgi_params;

}

Then restart the services.

$ sudo service nginx restart

 

Please make sure, on Ubuntu 14.04, we cannot use fastcgi_pass 127.0.0.1:9000. So make sure that the line is commented. Otherwise, on my machine, I got this error :

$ tail /var/log/nginx/error.log

2014/11/04 16:57:04 [emerg] 3216#0:  fastcgi_pass  directive is not allowed here in /etc/nginx/sites-enabled/default:59

2014/11/04 16:58:21 [emerg] 3256#0:  fastcgi_pass  directive is not allowed here in /etc/nginx/sites-enabled/default:59

 

On Ubuntu 14.04, I use the following line:

fastcgi_pass unix:/var/run/php5-fpm.sock

 

When I restart the Nginx and I still got the following error message:

 

2014/11/04 17:02:05 [emerg] 3295#0:  fastcgi_pass  directive is not allowed here in /etc/nginx/sites-enabled/default:61

2014/11/04 17:04:58 [emerg] 3410#0:  fastcgi_pass  directive is not allowed here in /etc/nginx/sites-enabled/default:61

 

Please make sure that you already uncomment this line:

location ~ \.php$ {

#3 – Configure MySQL

After the configuration section is done, now we need to test them to make sure that our configuration is working as required. On Ubuntu 14.04 the root document folder is located in /usr/share/nginx/html. So create a file called /usr/share/nginx/html/phpinfo.php with the following code:

<? phpinfo(); ?>

After restarting PHP-FPM and Nginx, open the browser and browse to the php file, we got only a blank screen. No error message on the screen. No error message on PHP-FPM and Nginx log file.

 

Then we changed /usr/share/nginx/html/phpinfo.php file code on the root document of Nginx, as follows:

<?php phpinfo(); ?>

And then open the browser again and type url http://your_ip_address/phpinfo.php

 

It seem that by default, we can not use short php-tag like this:

<? … your code … ?>

To enable short php tag, we need to change the value of short_open_tag parameter on php.ini file:

 

Change the value from Off to On. Then restart your php5-fpm :

sudo service php5-fpm restart

 

Then try again to test your phpinfo file. Next, we will see if the MySQL support is enabled or not. Scroll down the php configuration screen on your browser, if you see MySQL block there, then MySQL support already enabled.

 

You are now ready to use Nginx, PHP5 and MySQL on Ubuntu server. I hope this quick article help anyone who wish to install Linux, Nginx, PHP and MySQL on Ubuntu 14.04.

This quick tutorial was contributed by Pungki Arianto. You can too contribute to nixCraft.

 

 

]]>
http://wiki.shopingserver.com/install-lemp-linux-nginx-mysql-php-stack-ubuntu-linux-14-04-lts/feed/ 0
Check The Number Of MySQL Open Database Connections on Linux Or Unix-like Server http://wiki.shopingserver.com/check-number-mysql-open-database-connections-linux-unix-like-server/ http://wiki.shopingserver.com/check-number-mysql-open-database-connections-linux-unix-like-server/#respond Fri, 05 Jan 2018 16:11:37 +0000 http://wiki.shopingserver.com/?p=18377 I

‘m a new MySQL server user. My server is running on a CentOS Linux. How can I check the number of active MySQL connections on Linux based system?

 

You can use the following commands on Linux or Unix-like systems:

a) mysqladmin status command

b) MySQL show status command

c) netstat or ss commands

mysqladmin status command example

Open the terminal App or login to the remote server using ssh:

ssh vivek@server1.cyberciti.biz

Type the following command to get a short status message from the MySQL server:

mysqladmin status

OR ##

mysqladmin status -u root -p

OR ##

mysqladmin status -h db1.cyberciti.biz -u root -p

Sample outputs:

Uptime: 691356  Threads: 5  Questions: 83237956  Slow queries: 102736  Opens: 3585  Flush tables: 1  Open tables: 1019  Queries per second avg: 120.398

MySQL show status command to see open database connections example

First, connect to the your mysql server:

mysql -u root -p

Type the following sql query to see the number of connection attempts to the MySQL server includes both failed and successful connection attempts:

mysql> show status like  Conn% ;

Sample outputs:

Fig.01: “show status like ‘Conn%’;” in action

 

You can use the following sql command to see the number of currently open connections at mysql> prompt:

mysql> show status like  %onn% ;

+————————–+———+

| Variable_name            | Value   |

+————————–+———+

| Aborted_connects         | 7       |

| Connections              | 6304067 |

| Max_used_connections     | 85      |

| Ssl_client_connects      | 0       |

| Ssl_connect_renegotiates | 0       |

| Ssl_finished_connects    | 0       |

| Threads_connected        | 7       | <—- No of currently open connections

+————————–+———+

7 rows in set (0.00 sec)

Use show processlist sql command to see the number of open connections

Type the following sql command at mysql> prompt to see the number of currently open connections:

mysql> show processlist;

+———+————+——————-+————+———+——+——-+——————+

| Id      | User       | Host              | db         | Command | Time | State | Info             |

+———+————+——————-+————+———+——+——-+——————+

| 6297128 | root       | localhost         | NULL       | Query   |    0 | NULL  | show processlist |

| 6308321 | faqwpblogu | 10.10.29.66:42945 | lesaibkfaq | Sleep   |    1 |       | NULL             |

| 6308323 | faqwpblogu | 10.10.29.74:46993 | lesaibkfaq | Sleep   |    0 |       | NULL             |

| 6308325 | faqwpblogu | 10.10.29.74:46995 | lesaibkfaq | Sleep   |    1 |       | NULL             |

| 6308326 | faqwpblogu | 10.10.29.74:46996 | lesaibkfaq | Sleep   |    0 |       | NULL             |

+———+————+——————-+————+———+——+——-+——————+

5 rows in set (0.00 sec)

The above output indicates four currently open connection for user called  faqwpblogu  from app server located at 10.10.29.66 and 10.10.29.74.

MySQL show status sql command summary

I suggest that you read the following pages for more info:

SHOW STATUS Syntax

Server Status Variables

Use netstat or ss (Linux only) command to list open database connections

The syntax is as follows for netstat command or ss command:

netstat -nat | grep 10.10.29.68:3306

This will just give you an overview. I suggest that you use above sql commands only.

 

 

]]>
http://wiki.shopingserver.com/check-number-mysql-open-database-connections-linux-unix-like-server/feed/ 0
How To Install Apache, MySQL, PHP stack on FreeBSD Unix Server http://wiki.shopingserver.com/install-apache-mysql-php-stack-freebsd-unix-server/ http://wiki.shopingserver.com/install-apache-mysql-php-stack-freebsd-unix-server/#respond Fri, 05 Jan 2018 16:10:08 +0000 http://wiki.shopingserver.com/?p=18375 I

‘m a new FreeBSD Unix system users. How can I setup and install Apache, MySQL, PHP stack on a FreeBSD 10 based Unix server?

 

FAMP stack is nothing but group of source software to run php based apps. Our sample setup includes:

FreeBSD 10.1-RELEASE amd64

Apache v2.4

PHP v5.6

MySQL v5.6

This tutorial explains how to install and configure FAMP stack.

Update your ports

Like always make sure everything is up to date before starting. I like to do:

# portsnap fetch update && portupgrade -a

 

Sample outputs:

Looking up portsnap.FreeBSD.org mirrors… 7 mirrors found.

Fetching public key from your-org.portsnap.freebsd.org… done.

Fetching snapshot tag from your-org.portsnap.freebsd.org… done.

Fetching snapshot metadata… done.

Fetching snapshot generated at Fri Jan  2 00:09:16 UTC 2015:

4955cbbaee76bcad21123666d1c7eee0d55bc059e2ea04100% of   70 MB 5735 kBps 00m13s

Extracting snapshot… done.

Verifying snapshot integrity… done.

Fetching snapshot tag from your-org.portsnap.freebsd.org… done.

Fetching snapshot metadata… done.

Updating from Fri Jan  2 00:09:16 UTC 2015 to Fri Jan  2 11:42:26 UTC 2015.

Fetching 4 metadata patches… done.

Applying metadata patches… done.

Fetching 0 metadata files… done.

Fetching 8 patches.

….

..

See FreeBSD Update All Installed Ports / Applications tutorial for more information.

Install Apache server

To install the port:

# cd /usr/ports/www/apache24/ && make install clean

 

Or, to add the package:

# pkg install www/apache24

 

Sample outputs:

Fig. 01: Install apache

Starting up Apache service on boot

Add following to the end of “/etc/rc.conf” file to launch Apache at start up:

echo  apache24_enable= YES   >> /etc/rc.conf

STARTING / STOPPING / RESTARTING APACHE SERVER

To start Apache to make sure it works:

# /usr/local/etc/rc.d/apache24 start

 

To restart Apache server:

# /usr/local/etc/rc.d/apache24 restart

 

To stop Apache server:

# /usr/local/etc/rc.d/apache24 stop

 

You can also use the service command for starting/stoping/restarting Apache server on FreeBSD:

service command to control Apache server ##

service apache24 start

service apache24 restart

service apache24 stop

service apache24 status

Sample outputs:

Fig.02: Starting/Stopping Apache

Note: If you are getting this error “Could not reliably determine the server s fully qualified domain name, using 127.0.0.1.” Set the ‘ServerName’ directive globally to suppress this message:

Add next line to /usr/local/ect/apache24/httpd.conf file:

ServerName localhost

Replace localhost with the server’s domain name which can be obtained with:

# hostname -f

Setting up MySQL server

The package or port to be installed will depend on available MySQL version. As of this writing, the maximum available version is 5.6.

Install MySQL server

To install the port:

# cd /usr/ports/databases/mysql56-server/ && make install clean

 

or, to add the package:

# pkg install databases/mysql56-server

 

Fig.03: Installing mysql database server

Install MySQL client

To install the port:

# cd /usr/ports/databases/mysql56-client/ && make install clean

 

or, to add the package:

# pkg install databases/mysql56-client

Starting up Mysql server service on boot

Finally, /etc/rc.conf must contain the following line to allow the MySQL server to start:

echo  mysql_enable= YES   >> /etc/rc.conf

Starting / stopping / restarting Mysql server

To start the Mysql server type:

# /usr/local/etc/rc.d/mysql-server start

 

To restart the Mysql server type:

# /usr/local/etc/rc.d/mysql-server restart

 

To stop the Mysql server type:

# /usr/local/etc/rc.d/mysql-server stop

 

You can also use the service command for starting/stoping/restarting mysql server on FreeBSD:

command to start/stop mysql servers on a FreeBSD 10 ##

service mysql-server start

service mysql-server restart

service mysql-server stop

service mysql-server status

Sample outputs:

Fig.04: Starting/Stopping mysql server

Setting up Mysql server passwords

The default is set to allow anyone to have full access. It’s very important that you set up passwords. To set a password on the anonymous accounts use:

# mysql -u root

 

Run the following sql queries at mysql> prompt (replace host_name with actual system host name which can be obtained with hostname -f command:

mysql> SET PASSWORD FOR   @ localhost  = PASSWORD( newpwd-here );

mysql> SET PASSWORD FOR   @ host_name  = PASSWORD( newpwd-here );

mysql> quit

Bye

To set a password for the root account use:

# mysql -u root

 

Run the following sql queries at mysql> prompt:

mysql> SET PASSWORD FOR  root @ localhost  = PASSWORD( newpwd-here );

mysql> SET PASSWORD FOR  root @ host_name  = PASSWORD( newpwd-here );

mysql>  quit

Bye

NOTE: An alternative method to set a password for the MySQL root user is to run the following command:

/usr/local/bin/mysqladmin -u root password  PASSWORD-HERE

See “MySQL Change root Password” tutorial for more information.

After setting the password, here is how you shutdown mysqld server:

# mysqladmin -u root -p shutdown

 

Sample outputs:

Enter password:

TIP: IF YOU “FORGET” THE ROOT PASSWORD, HERE IS HOW YOU CAN RESET IT

Stop mysqld with this command:

# /usr/local/etc/rc.d/mysql-server.sh stop

 

Modify the start command to add this option to the command line. Do not leave this option on for long. Only for when you need it. It bypasses all usual mysql security:

-Sg|–skip-grant-tables

This option causes the server not to use the privilege system at all. This gives everyone full access to all databases! (You can tell a running server to start using the grant tables again by executing mysqladmin flush-privileges or mysqladmin reload.)

Modify it in /usr/local/etc/rc.d/mysql-server.sh:

/usr/local/bin/safe_mysqld –user=mysql –skip-grant-tables > /dev/null & && echo -n   mysqld

Start mysqld:

# /usr/local/etc/rc.d/mysql-server.sh start

 

Connect to mysql:

# mysql

 

Look out because this next step will reset the passwords for all root users. Make sure that’s what you want to do. You may wish to restrict this SQL by including an “and host = ‘something ” clause. Inspect existing users with “SELECT host, user from user;“. Select the mysql database and reset the password:

mysql> use mysql

mysql> update user set password = PASSWORD( secret ) where user =  root ;

mysql> quit

=> Do not forget to undo that mysql bypass i.e. Stop mysqld with: /usr/local/etc/rc.d/mysql-server.sh stop

=> Remove the option from the vi /usr/local/etc/rc.d/mysql-server.sh and remove –skip-grant-tables options.

=> Restart mysqld with: /usr/local/etc/rc.d/mysql-server.sh start

=> See “Recover MySQL root Password” tutorial for more information.

Install PHP

When you build PHP, you need to add the configuration option so that PHP build includes support for the Apache server. Type the following commands:

# cd /usr/ports/lang/php56

# make config

 

When the menu comes up to select/deselect various build options. You should select:

Fig.05: Build PHP using ports collection

 

Now you will do the make clean command. I normally do these commands all in one but to get the configuration menu, I do them apart.

# make install clean

Install mod_php for Apache

Type the following commands to build mod_php for Apache:

# cd /usr/ports/www/mod_php56

# make install clean

 

Sample outputs:

Fig.06: Install mod_php for Apache

Install php extensions

If you aren’t sure if it’s or you didn’t check it with your MySQL install, you will do it the commands the same way so you get the menus to configure to add support for both MySQL and MySQLi to communicate with the MySQL server.

# cd /usr/ports/lang/php56-extensions/

# make config

 

Fig.07: Install popular extensions for Apache

 

You may also select other extensions as per your PHP apps requirements. Then finish up with:

# make install clean

Configure mod_php

To configure it you will type the following command that just makes a copy of a file:

# cp /usr/local/etc/php.ini-development /usr/local/etc/php.ini

To configure Apache and open the file:

# ee /usr/local/etc/apache24/httpd.conf

 

I use ee (feel free to use vi or Emacs) text editor for simple edits, look for this line:

DirectoryIndex index.html

And change it so it reads as follows:

DirectoryIndex index.html index.htm index.php

Find and set the following values as per your domain, IP, and port number:

ServerAdmin webmaster@cyberciti.biz

ServerName www.cyberciti.biz:80

Listen :80

Save and close the file. Create a file called /usr/local/etc/apache24/modules.d/001_mod_php.conf as follows:

# cat /usr/local/etc/apache24/modules.d/001_mod_php.conf

<FilesMatch  \.php$ >

SetHandler application/x-httpd-php

</FilesMatch>

<FilesMatch  \.phps$ >

SetHandler application/x-httpd-php-source

</FilesMatch>

Now restart Apache server:

# /usr/local/etc/rc.d/apache24 restart

 

OR

# service apache24 restart

Test your setup

Create a file called /usr/local/www/apache24/data/test.php:

# vi /usr/local/www/apache24/data/test.php

Append the following code:

<?php

phpinfo();

?>

Save and close the file. Fire a web-browser and type the url:

http://your-domain-name/test.php

http://your-ip-address/test.php

Sample outputs:

Fig.08: Apache + PHP server ready on FreeBSD

How do I secure PHP?

See our 25 PHP Security Best Practices For Sys Admins for more info.

Recommended readings

Apache HTTP Server Version 2.4 Documentation

man pages – httpd(8), service(8)

This quick tutorial was contributed by Wendy Michele. Editing by admin. You can too contribute to nixCraft.

 

 

]]>
http://wiki.shopingserver.com/install-apache-mysql-php-stack-freebsd-unix-server/feed/ 0
How To Install MariaDB Databases on a FreeBSD v10/11 Unix Server http://wiki.shopingserver.com/install-mariadb-databases-freebsd-v10-11-unix-server/ http://wiki.shopingserver.com/install-mariadb-databases-freebsd-v10-11-unix-server/#respond Fri, 05 Jan 2018 16:06:18 +0000 http://wiki.shopingserver.com/?p=18371 I

‘m a new FreeBSD unix user. How can I install MariaDB database server on a FreeBSD unix based system?

 

MySQL is a very fast, multi-threaded, multi-user and robust SQL database server. The latest version is located at /usr/ports/databases/mysql57-server/. MariaDB is a database server that offers drop-in replacement functionality for MySQL1. MariaDB is built by some of the original authors of MySQL, with assistance from the broader community of Free and open source software developers around the world. In addition to the core functionality of MySQL, MariaDB offers a rich set of feature enhancements including alternate storage engines, server optimizations, and patches. The latest version is located at /usr/ports/databases/mariadb55-server/. In this tutorial, you will learn how to install MariaDB server and create a databases, users, and grant sql rights using sql commands on a FreeBSD 10 or 11 server.

Update all your ports

Make sure your ports are installed and up to date. I like to do:

# portsnap fetch update && portupgrade -a

FreeBSD MariaDB installation

To install MariaDB Server, MariaDB Client and MariaDB Scripts type the following commands.

A note about MySQL and MariaDB server together

You cannot run MariaDB and MySQL installed together. You will have deinstall one or the other and the clients if you have them. If you want to run them both, you

will need them to be jailed apart. If you are new it’s best to not think about this and run them one at a time focusing on learning one or the other. So for example if you have MySQL and want to install MariaDB you need to deinstall before installing. Check what version you are using by typing the command as root:

# pkg version | grep mysql

 

or as user or root you can type this command:

# mysql –version

 

or use pkg command:

# pkg info | grep mysql

 

Make sure you backup database before you uninstall mysql-server. To deinstall that:

# cd /usr/ports/databases/mysql57-server/ && make deinstall clean

# cd /usr/ports/databases/mysql57-client/ && make deinstall clean

# rm -rf /var/db/mysql/

 

or use pkg command to delete them:

# pkg remove mysql56-server mysql56-client

# rm -rf /var/db/mysql/

Install MariaDB server

To install the port, type:

# cd /usr/ports/databases/mariadb100-server && make install clean

 

When you install make sure you check what you want off in the configuration:

Fig.01: FreeBSD 10 Mariadb Server Install Command

 

Or, to add the binary package using pkg command, run:

# pkg install databases/mariadb100-server

 

Sample outputs:

Fig.02: FreeBSD 10 Install Mariadb using the pkg command

 

Here is output from my FreeBSD 11 box:

Updating FreeBSD repository catalogue…

FreeBSD repository is up-to-date.

All repositories are up-to-date.

The following 5 package(s) will be affected (of 0 checked):

 

New packages to be INSTALLED:

mariadb100-server: 10.0.29

openssl: 1.0.2j_1,1

mariadb100-client: 10.0.29

readline: 6.3.8

indexinfo: 0.2.6

 

Number of packages to be installed: 5

 

The process will require 244 MiB more space.

34 MiB to be downloaded.

 

Proceed with this action? [y/N]: y

Install MariaDB client only

MariaDB Client will be installed automatically. You should now check following options:

[X] THREADSAFE  Build thread-safe client

[X] SSL         Activate SSL support (yassl)

However, if you need MariaDB client on another FreeBSD server or jail, run:

# cd /usr/ports/databases/mariadb100-client

# make install clean

 

OR

# pkg install databases/mariadb100-client

 

Sample outputs:

Fig.03: FreeBSD 11 install mariadb client

How do I start MariaDB on boot?

Type the following command:

echo  mysql_enable= YES   >> /etc/rc.conf

How do I install MariaDB server configuration file?

MariaDB respects FreeBSD layout of file systems (and doesn’t check /etc and /etc/mysql for my.cnf. You will find the following default config files:

# ls -l /usr/local/share/mysql/my*.cnf

 

Sample outputs:

-rw-r–r–  1 root  wheel   4898 Nov 26 12:56 /usr/local/share/mysql/my-huge.cnf

-rw-r–r–  1 root  wheel  20418 Nov 26 12:56 /usr/local/share/mysql/my-innodb-heavy-4G.cnf

-rw-r–r–  1 root  wheel   4885 Nov 26 12:56 /usr/local/share/mysql/my-large.cnf

-rw-r–r–  1 root  wheel   4898 Nov 26 12:56 /usr/local/share/mysql/my-medium.cnf

-rw-r–r–  1 root  wheel   2824 Nov 26 12:56 /usr/local/share/mysql/my-small.cnf

I’m setting up a medium sized server, so I’m going to copy /usr/local/share/mysql/my-medium.cnf to /usr/local/etc/ directory using cp command:

# cp /usr/local/share/mysql/my-medium.cnf /usr/local/etc/my.cnf

 

To edit /usr/local/etc/my.cnf, enter:

# vi !!:2

 

OR

# vi /usr/local/etc/my.cnf

 

To enable remote access to MariaDB database server, enter:

# change ip

bind-address = 127.0.0.1

Save and close the file.

How do I start/stop/restart MariaDB on a FreeBSD 10?

To start the server you are going to type:

# service mysql-server start

 

You will see the following information when you start the server for the first time:

Fig.03 Starting the start for the first time

 

To stop the server you are going to type:

# service mysql-server stop

 

To restart the server you are going to type:

# service mysql-server restart

 

To see the server status you are going to type:

# service mysql-server status

 

You can also use the following commands for the same purpose:

call rc.d script to control MariaDB server ##

/usr/local/etc/rc.d/mysql-server start

/usr/local/etc/rc.d/mysql-server stop

/usr/local/etc/rc.d/mysql-server restart

/usr/local/etc/rc.d/mysql-server status

Sample outputs:

Fig.04: Starting/Stopping MariaDB server on a FreeBSD 10

How do I set root user password for MariaDB?

You should create password for root user after MariaDB installation, enter:

# mysqladmin -u root password YOURSECUREPASSWORD

 

Alternatively, I suggest that you can run the following command to set root password. This command will also give you the option of removing the test databases and anonymous user created by default. This is strongly recommended for production servers:

# /usr/local/bin/mysql_secure_installation

 

Sample outputs:

 

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB

SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

 

In order to log into MariaDB to secure it, we ll need the current

password for the root user.  If you ve just installed MariaDB, and

you haven t set the root password yet, the password will be blank,

so you should just press enter here.

 

Enter current password for root (enter for none):

OK, successfully used password, moving on…

 

Setting the root password ensures that nobody can log into the MariaDB

root user without the proper authorisation.

 

Set root password? [Y/n] y

New password:

Re-enter new password:

Password updated successfully!

Reloading privilege tables..

… Success!

 

 

By default, a MariaDB installation has an anonymous user, allowing anyone

to log into MariaDB without having to have a user account created for

them.  This is intended only for testing, and to make the installation

go a bit smoother.  You should remove them before moving into a

production environment.

 

Remove anonymous users? [Y/n] y

… Success!

 

Normally, root should only be allowed to connect from  localhost .  This

ensures that someone cannot guess at the root password from the network.

 

Disallow root login remotely? [Y/n] y

… Success!

 

By default, MariaDB comes with a database named  test  that anyone can

access.  This is also intended only for testing, and should be removed

before moving into a production environment.

 

Remove test database and access to it? [Y/n] y

– Dropping test database…

… Success!

– Removing privileges on test database…

… Success!

 

Reloading the privilege tables will ensure that all changes made so far

will take effect immediately.

 

Reload privilege tables now? [Y/n] y

… Success!

 

Cleaning up…

 

All done!  If you ve completed all of the above steps, your MariaDB

installation should now be secure.

 

Thanks for using MariaDB!

Notes: If you get message with unknown MySQL version when installing ports, you should edit /etc/make.conf and add line:

MYSQL52_LIBVER=16

You can edit with ee or your favorite editor. With ee type:

ee  /etc/make.conf

MYSQL52_LIBVER=16

pres Esc

a,a

or b if you do not want to save the changes.

How do I connect to MariaDB server?

The syntax is:

mysql

mysql -u user -p

mysql -h db-hostname-here -u user-name-here -p

How do I create MariaDB database and users?

First, login as root user:

mysql -u root -p mysql

Sample outputs:

Fig.05: Connecting to the server using mysql client

 

Create a new mysql database called foo. Type the following command at mysql> prompt:

MariaDB [mysql]>  CREATE DATABASE foo;

Create a new user called user1 for database called foo with a password called ‘hiddensecret’:

MariaDB [mysql]>  GRANT ALL ON foo.* TO user1@localhost IDENTIFIED BY  hiddensecret ;

How do I connect to MariaDB database foo using user1 account?

User user1 can connect to the foo database using the following shell command:

$ mysql -u user1 -p foo

 

OR

$ mysql -u user1 -h your-mysql-server-host-name-here -p foo

 

Sample session:

Fig.06: Creating users and database on the MariaDB server

 

See “Mysql User Creation: Setting Up a New MySQL User Account” tutorial for more information.

How do I enable remote access to the MariaDB server?

Edit the my.cnf file, run:

# vi /usr/local/etc/my.cnf

 

Make sure line skip-networking is commented (or remove line) and add the following line in the [mysqld] section:

bind-address=YOUR-SERVER-IP

For example, if your MariaDB server IP is 192.168.1.5 then entire block should be look like as follows:

# The MariaDB server

[mysqld]

port            = 3306

bind-address    = 192.168.1.5

socket          = /tmp/mysql.sock

skip-external-locking

key_buffer_size = 16M

max_allowed_packet = 1M

table_open_cache = 64

sort_buffer_size = 512K

net_buffer_length = 8K

read_buffer_size = 256K

read_rnd_buffer_size = 512K

myisam_sort_buffer_size = 8M

 

# Point the following paths to different dedicated disks

#tmpdir         = /tmp/

# Don t listen on a TCP/IP port at all. This can be a security enhancement,

# if all processes that need to connect to mysqld run on the same host.

# All interaction with mysqld must be made via Unix sockets or named pipes.

# Note that using this option without enabling named pipes on Windows

# (via the  enable-named-pipe  option) will render mysqld useless!

#

#skip-networking

log-bin=mysql-bin

binlog_format=mixed

server-id       = 1

Save and close the file. Restart the server:

# service mysql-server restart

 

Update your pf.conf file:

allows mysql client from 192.168.1.200 ##

pass in on $ext_if proto tcp from 192.168.1.200to any port 3306  flags S/SA synproxy state

Restart pf and test connectivity from 192.168.1.200 by typing any one of the following command:

# use nc for port testing ##

nc -z -w1 192.168.1.5 3306

# or old good telnet ##

echo X | telnet -e X 192.168.1.5 3306

telnet -e X 192.168.1.5 3306<<< X

or use mysql client ##

mysql -h 192.168.1.5 -u USER -p DB

How do I grant access to an existing database over the LAN based session?

Let us assume that you are always making connection from remote IP called 192.168.1.200 for database called foo for user bar, To grant access to this IP address type the following command at MariaDB [mysql]> prompt for existing database, enter:

MariaDB [mysql]> update db set Host= 192.168.1.200  where Db= foo ;

MariaDB [mysql]> update user set Host= 192.168.1.200  where user= bar ;

See “How Do I Enable Remote Access To MySQL Database Server?” tutorial for more information.

How to open ports in a FreeBSD pf firewall

Add the following rule in your pf.conf file:

pass in on $ext_if proto tcp from any to any port 3306

OR only allow access from 192.168.1.10:

pass in on $ext_if proto tcp from 192.168.1.10 to any port 3306

]]>
http://wiki.shopingserver.com/install-mariadb-databases-freebsd-v10-11-unix-server/feed/ 0
How To Setup a LAMP Server on Debian Linux 8 (Jessie) http://wiki.shopingserver.com/setup-lamp-server-debian-linux-8-jessie/ http://wiki.shopingserver.com/setup-lamp-server-debian-linux-8-jessie/#respond Fri, 05 Jan 2018 15:07:55 +0000 http://wiki.shopingserver.com/?p=18298 H

ow can I setup up a LAMP (Linux, Apache, MySql, PHP) stack on Debian Linux version 8 (Jessie) using command line options?

 

Setting up a LAMP stack on your Debian 8 server will allow for the hosting of websites and web applications written in PHP, Perl, and Python. You need to install the following packages on Debian Linux 8:

apache2 : Apache HTTP Server

mysql-server: MySQL Server

php5 : PHP 5

php-pear: PHP 5 pear package

php5-mysql: PHP 5 mysql support

In this tutorial, you will learn installing LAMP on your Debian 8 server.

Update your system

Type the following command:

# apt-get update

# apt-get upgrade

Install Apache 2 package

Type the following apt-get command to instal Apache httpd server version 2:

# apt-get install apache2

 

Sample outputs:

Fig. 01: Install Apache 2 on Debian 8

Install MySQL server package

Type the following apt-get command to instal Mysql server version 5.x:

# apt-get install mysql-server

Install PHP package

Type the following apt-get command to instal php5:

# apt-get install php5 php-pear libapache2-mod-php5

Install PHP modules

Type the following apt-get command to instal php modules:

# apt-get install php5-mysql php5-gd

 

To find out additional PHP5 modules, enter:

# apt-cache search php5-

 

Sample outputs:

php5-exactimage – fast image manipulation library (PHP bindings)

php5-gdcm – Grassroots DICOM PHP5 bindings

php5-vtkgdcm – Grassroots DICOM VTK PHP bindings

php5-geos – GEOS bindings for PHP

php5-lasso – Library for Liberty Alliance and SAML protocols – PHP 5 bindings

php5-libvirt-php – libvirt bindings for PHP

php5-mapscript – php5-cgi module for MapServer

php5-adodb – Extension optimising the ADOdb database abstraction library

php5-apcu – APC User Cache for PHP 5

php5-gearman – PHP wrapper to libgearman

php5-geoip – GeoIP module for php5

php5-gnupg – wrapper around the gpgme library

php5-igbinary – igbinary extension

php5-imagick – Provides a wrapper to the ImageMagick library

php5-json – JSON module for php5

php5-memcache – memcache extension module for PHP5

php5-memcached – memcached extension module for PHP5, uses libmemcached

php5-mongo – MongoDB database driver

php5-msgpack – PHP extension for interfacing with MessagePack

php5-mysqlnd-ms – MySQL replication and load balancing module for PHP

php5-oauth – OAuth 1.0 consumer and provider extension

php5-pecl-http – pecl_http module for PHP 5 Extended HTTP Support

php5-pecl-http-dev – pecl_http module for PHP 5 Extended HTTP Support development headers

php5-pinba – Pinba module for PHP 5

php5-propro – propro module for PHP 5

php5-propro-dev – propro module for PHP 5 development headers

php5-radius – PECL radius module for PHP 5

php5-raphf – raphf module for PHP 5

php5-raphf-dev – raphf module for PHP 5 development headers

php5-redis – PHP extension for interfacing with Redis

php5-rrd – PHP bindings to rrd tool system

php5-sasl – Cyrus SASL Extension

php5-solr – solr module for PHP 5

libssh2-php – transitional dummy package for php5-ssh2

php5-ssh2 – Bindings for the libssh2 library

php5-stomp – Streaming Text Oriented Messaging Protocol (STOMP) client module for PHP 5

php5-svn – PHP Bindings for the Subversion Revision control system

php5-tokyo-tyrant – PHP interface to Tokyo Cabinet s network interface, Tokyo Tyrant

php5-yac – YAC (Yet Another Cache) for PHP 5

php5-zmq – ZeroMQ messaging

libphp5-embed – HTML-embedded scripting language (Embedded SAPI library)

php5-cgi – server-side, HTML-embedded scripting language (CGI binary)

php5-cli – command-line interpreter for the php5 scripting language

php5-common – Common files for packages built from the php5 source

php5-curl – CURL module for php5

php5-dbg – Debug symbols for PHP5

php5-dev – Files for PHP5 module development

php5-enchant – Enchant module for php5

php5-fpm – server-side, HTML-embedded scripting language (FPM-CGI binary)

php5-gd – GD module for php5

php5-gmp – GMP module for php5

php5-imap – IMAP module for php5

php5-interbase – interbase/firebird module for php5

php5-intl – internationalisation module for php5

php5-ldap – LDAP module for php5

php5-mcrypt – MCrypt module for php5

php5-mysql – MySQL module for php5

php5-mysqlnd – MySQL module for php5 (Native Driver)

php5-odbc – ODBC module for php5

php5-pgsql – PostgreSQL module for php5

php5-phpdbg – server-side, HTML-embedded scripting language (PHPDBG binary)

php5-pspell – pspell module for php5

php5-readline – Readline module for php5

php5-recode – recode module for php5

php5-snmp – SNMP module for php5

php5-sqlite – SQLite module for php5

php5-sybase – Sybase / MS SQL Server module for php5

php5-tidy – tidy module for php5

php5-xmlrpc – XML-RPC module for php5

php5-xsl – XSL module for php5

php5-librdf – PHP5 language bindings for the Redland RDF library

php5-remctl – PECL module for Kerberos-authenticated command execution

php5-twig – Enhance performance of the Twig template engine

php5-uprofiler – hierarchical profiler for PHP (extension)

php5-xcache – Fast, stable PHP opcode cacher

php5-xdebug – Xdebug Module for PHP 5

php5-xhprof – Hierarchical Profiler for PHP5

Optional: Install Perl, for Perl apps

Type the following apt-get command to instal Perl module for Apache 2:

# apt-get install perl libapache2-mod-perl2

Optional: Install Python, for python apps

Type the following apt-get command to instal Python module for Apache 2:

# apt-get install python libapache2-mod-python

LAMP configurations

At this stage required software packages are installed. To find your severs’s IP address, run:

# ifconfig eth0

 

OR

# ip addr show eth0

 

Sample outputs:

2: eth0:  mtu 1500 qdisc pfifo_fast state UP group default qlen 1000

link/ether 00:08:9b:c4:30:30 brd ff:ff:ff:ff:ff:ff

inet 192.168.1.10/24 brd 192.168.1.255 scope global eth0

valid_lft forever preferred_lft forever

inet6 fe80::208:9bff:fec4:3030/64 scope link

valid_lft forever preferred_lft forever

Fire a web-browser and test it by typing your server IP address:

http://192.168.1.10/

Sample outputs:

Fig.02: The default Apache 2 page on Debian Linux 8

Configure Apache

Edit /etc/apache2/apache2.conf file, enter:

# vi /etc/apache2/apache2.conf

 

Make sure you setup port, IP address, and other information as per your needs. Finally, restart the server:

# systemctl restart apache2

HOW DO I CONFIGURE NAME BASED VIRTUAL HOST FOR DOMAIN CALLED CYBERCITI.BIZ?

First, create directories, as follows:

# D= cyberciti.biz

# mkdir -p /var/www/html/$D/html_root

# mkdir -p /var/log/apache2/$D/

 

Create /etc/apache2/sites-available/$D.conf file:

# vi /etc/apache2/sites-available/$D.conf

 

Append the following directives:

<VirtualHost *:80>

ServerAdmin webmaster@cyberciti.biz

ServerName cyberciti.biz

ServerAlias www.cyberciti.biz

DocumentRoot /var/www/html/cyberciti.biz/html_root

ErrorLog  /var/log/apache2/cyberciti.biz/logs/error.log

CustomLog  /var/log/apache2/cyberciti.biz/logs/access.log combined

</VirtualHost>

Save and close the file. Turn on configuration:

# a2ensite $D.conf

 

Again, restart apache server:

# systemctl restart apache2

Configure MySQL server

First, secure your mysql server, type:

# mysql_secure_installation

 

Create a sample mysql database called wordpress. First, login as follows:

# mysql -u root -p

 

Type the following sql commands at mysql> prompt:

mysql> create database wordpress;

mysql> grant all on wordpress.* to  vivek  identified by  1SfFAi9$ ;

mysql> quit

The above will create a database called ‘wordpress’ and grant your users permissions on it with username ‘vivek’ and the password ‘1SfFAi9$’. See how to create and use database/users on MySQL for more info.

Configure PHP

Edit /etc/php5/apache2/php.ini, enter:

# vi /etc/php5/apache2/php.ini

 

Append or modify as follows:

;

; *******************************************************************************************************

; NOTE: These settings are good starting points, but should be adjusted to best suite your requirements.*

; *******************************************************************************************************

 

; Set error reporting to a log file

display_errors=Off

error_reporting = E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR

error_log = /var/log/apache2/php-error.log

 

; Again set this as per your needs – Anit DoS settings

max_execution_time =  30

max_input_time = 30

memory_limit = 40M

 

; No exposing is allowed

expose_php=Off

 

; Disable file uploads

file_uploads=Off

 

; Turn off remote execution

allow_url_fopen=Off

allow_url_include=Off

 

; Block dangerous php functions

disable_functions =exec,passthru,shell_exec,system,proc_open,popen,curl_exec,curl_multi_exec,parse_ini_file,show_source

Note: See our php 5 security tips guide and block php functions which are not suppose to use for more information.

Again, restart apache 2 server:

# systemctl restart apache2

 

Next, create /var/www/html/info.php file to test PHP:

# echo  <?php phpinfo(); ?>  > /var/www/html/info.php

 

Test url:

http://192.168.1.10/info.php

Sample outputs:

Fig.03 Apache 2 php test page on Debian Linux 8

Security: Firewall settings

You need to open port 80:

/sbin/iptables -A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT

 

See our firewall settings guide on Debain for more information.

Security: Permission for /var/www/html/ DocumentRoot directory

Make sure you set files and directories permission as follows:

Must run as root user ##

# Make sure Apache user owns /var/www/html/

chown -R www-data:www-data /var/www/html

 

# Make sure it is read-only

chmod -R 0444 /var/www/html/

 

# Make sure Apache can read files in sub-dirs to avoid HTTP/403 status errors

find /var/www/html/ -type d -print0 | xargs -0 -I {} chmod 0445  {}

 

# Do you need to give write permission to certain directories like $D/blog/wp-cache/?

# Edit as per needs 🙂

# chmod -R 0775 /var/www/html/cyberciti.biz/blog/wp-cache/

# echo  Deny from all  >>  /var/www/html/cyberciti.biz/blog/wp-cache/

# EOF

Important commands

To start/stop/restart and to see status of Apache 2, enter:

# systemctl start apache2

# systemctl stop apache2

# systemctl restart apache2

# systemctl status apache2

 

To start/stop/restart and to see status of MySQL server, enter:

# systemctl start mysql

# systemctl stop mysql

# systemctl restart mysql

# systemctl status mysql

 

Verify that port # 80 open:

# netstat -tulpn | grep :80

# ss -t -a

# ss -t -a | grep http

# ss -o state established  ( dport = :http or sport = :http )

# iptable -L -n -v | less

Important log files

To see Apache 2 log files, enter:

tail -f /var/log/apache2/access.log

tail -f /var/log/apache2/error.log

grep something /var/log/apache2/error.log

PHP ##

tail -f /var/log/apache2/php-error.log

Vhost cyberciti.biz ##

tail -f /var/log/apache2/cyberciti.biz/logs/error.log

tail -f /var/log/apache2/cyberciti.biz/logs/access.log

grep something /var/log/apache2/cyberciti.biz/logs/error.log

Now, you have installed LAMP stack on your Debian v8.x server.

 

 

]]>
http://wiki.shopingserver.com/setup-lamp-server-debian-linux-8-jessie/feed/ 0
How to install mysql server 5.7 on Ubuntu 16.04 LTS ( Xenial Xerus ) http://wiki.shopingserver.com/install-mysql-server-5-7-ubuntu-16-04-lts-xenial-xerus/ http://wiki.shopingserver.com/install-mysql-server-5-7-ubuntu-16-04-lts-xenial-xerus/#respond Thu, 04 Jan 2018 08:32:02 +0000 http://wiki.shopingserver.com/?p=18123 M

ySQL is a popular database management system used for my web applications. How do I install MySQL server version 5.7 on Ubuntu Linux 16.04 LTS ( Xenial Xerus )?

 

This tutorial will introduce how to install, configure and manage MySQL on a Ubuntu Linux 16.04 LTS (Xenial Xerus). The latest version of MySQL database server is 5.7 and can be installed using the apt-get command or apt command:

mysql-server – Metapackage depending on the latest version (server)

mysql-client – Metapackage depending on the latest version (client)

Step 1: Update your system by typing the following commands:

$ sudo apt update

$ sudo apt upgrade

 

Fig.01: Before you begin, update your Ubuntu server

Step 2: Install mysql version 5.7 on Ubuntu 16.04

Type the following command:

$ sudo apt install mysql-server mysql-client

 

Sample outputs:

Reading package lists… Done

Building dependency tree

Reading state information… Done

The following additional packages will be installed:

libdbd-mysql-perl libdbi-perl libhtml-template-perl libmysqlclient18

libterm-readkey-perl mysql-client-5.7 mysql-client-core-5.7 mysql-common

mysql-server-5.7 mysql-server-core-5.7

Suggested packages:

libclone-perl libmldbm-perl libnet-daemon-perl libsql-statement-perl

libipc-sharedcache-perl mailx tinyca

The following NEW packages will be installed:

libdbd-mysql-perl libdbi-perl libhtml-template-perl libmysqlclient18

libterm-readkey-perl mysql-client mysql-client-5.7 mysql-client-core-5.7

mysql-common mysql-server mysql-server-5.7 mysql-server-core-5.7

0 upgraded, 12 newly installed, 0 to remove and 0 not upgraded.

Need to get 21.7 MB of archives.

After this operation, 155 MB of additional disk space will be used.

Do you want to continue? [Y/n] y

You need to type the password for the MySQL root user:

Fig.02: During the installation process set the password for the MySQL root account

Step 3: Run mysql_secure_installation to secure your installation

For all production server you must run the following command:

$ sudo mysql_secure_installation

 

Sample outputs:

Fig,03: Harden MySQL server on Ubuntu

 

The mysql_secure_installation command will change the root password, disable and remove anonymous users from MySQL server, turn off the MySQL root user login remotely, delete test database, and reload privilege tables on the system. If you’ve completed all of the steps and answer yes to these questions. Your MySQL installation should now be secure.

Step 4: How do I use MySQL server?

To log in as the root user, type:

$ mysql -u root -p

 

When prompted, enter the MySQL root password, and you should see mysql> prompt as follows:

Fig.04: Your first login

Step 5: How do I create a new MySQL server database and user account?

The sql syntax is as follows to create a new mysql database and setup password:

CREATE DATABASE DATABASE-NAME-HERE;

GRANT ALL ON DATABASE-NAME-HERE.* TO  DATABASE-USERNAME-HERE  IDENTIFIED BY  DATABASE-PASSWORD-HERE ;

For example, create a wpblogdb as the database, vivek as the user, and fooBarPwd8-4_2 as the user’s password, run (type at the mysql> prompt:)

mysql> create database wpblogdb;

mysql> grant all on wpblogdb.* to  vivek  identified by  fooBarPwd8-4_2 ;

mysql> quit;

 

Sample session:

Fig.05: Mysql admin: New MySQL User and Database

 

Now, try to log in as vivek user, enter:

$ mysql -u USERNAME -p DB-NAME-HERE

$ mysql -u vivek -p wpblogdb

 

Sample session:

Fig.06: Log back in as vivek user and wpblogdb database

 

Of course you can create a mysql tables and insert data too:

mysql> CREATE TABLE authors (id INT, name VARCHAR(20), email VARCHAR(20));

mysql> INSERT INTO authors (id,name,email) VALUES(1, Vivek , xuz@foo.gmail.com );

mysql> INSERT INTO authors (id,name,email) VALUES(2, Wendy , bar@foo.gmail.com );

mysql> INSERT INTO authors (id,name,email) VALUES(3, Tom , tom@foo.gmail.com );

mysql> SELECT * FROM authors;

mysql> quit;

 

Sample outputs:

Fig.07: Create a demo authors table in wpblogdb database

How do I start MySQL server?

$ sudo systemctl start mysql

 

OR

$ sudo systemctl start mysql.service

How do I stop MySQL server?

$ sudo systemctl stop mysql

 

OR

$ sudo systemctl stop mysql.service

How do I restart MySQL server?

$ sudo systemctl restart mysql

 

OR

$ sudo systemctl restart mysql.service

How do I find out if MySQL running/active?

$ sudo systemctl status mysql.service

 

Sample outputs:

● mysql.service – MySQL Community Server

Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enab

Active: active (running) since Mon 2016-03-28 14:20:54 CDT; 8s ago

Process: 24181 ExecStartPost=/usr/share/mysql/mysql-systemd-start post (code=exi

Process: 24176 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exite

Main PID: 24180 (mysqld_safe)

Tasks: 23 (limit: 512)

Memory: 106.1M

CPU: 514ms

CGroup: /system.slice/mysql.service

├─24180 /bin/sh /usr/bin/mysqld_safe

└─24528 /usr/sbin/mysqld –basedir=/usr –datadir=/var/lib/mysql –plug

 

Mar 28 14:20:53 xenial systemd[1]: Starting MySQL Community Server…

Mar 28 14:20:53 xenial mysqld_safe[24180]: 160328 14:20:53 mysqld_safe Can t log t

Mar 28 14:20:53 xenial mysqld_safe[24180]: 160328 14:20:53 mysqld_safe Logging to

Mar 28 14:20:53 xenial mysqld_safe[24180]: 160328 14:20:53 mysqld_safe Starting my

Mar 28 14:20:54 xenial systemd[1]: Started MySQL Community Server.

How do I reset the mysql root account password?

You need to type the following command, if you would like to change the MySQL root password:

$ sudo dpkg-reconfigure mysql-server-5.7

 

See “Recover the MySQL root Password” for more information.

A note about MySQL server configuration

You may edit the /etc/mysql/my.cnf file to configure the basic settings such as TCP/IP port, IP address binding, and other options. However, The MySQL database server configuration file on the Ubuntu 16.04 LTS is located at /etc/mysql/mysql.conf.d/mysqld.cnf and one can edit using a text editor such as vi or nano:

$ sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf

 

OR

$ sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf

 

After making a change to /etc/mysql/mysql.conf.d/mysqld.cnf the MySQL server will need to be restarted:

$ sudo systemctl restart mysql.service

 

And, there you have it, the MySQL database version 5.7 installed and working correctly on the latest version of Ubuntu Linux 16.04 LTS. For more information see MySQL 5.7 Reference Manual.

 

 

]]>
http://wiki.shopingserver.com/install-mysql-server-5-7-ubuntu-16-04-lts-xenial-xerus/feed/ 0