Monday 27 February 2012

Set up a LAMP Server on Linux Mint / Ubuntu

Install and Configure the Apache Web Server

The Apache Web Server is a very popular choice for serving web pages. While many alternatives have appeared in the last few years, Apache remains a powerful option that is recommended for most uses. Issue the following command to install Apache:

apt-get install apache2

Now we'll configure virtual hosting so that we can host multiple domains (or subdomains) with the server. These websites can be controlled by different users, or by a single user, as you prefer.

Configure Virtual Hosting

There are different ways to set up virtual hosts, however we recommend the method below. By default, Apache listens on all IP addresses available to it. We must configure it to listen only on addresses we specify. Even if you only have one IP, it is still a good idea to tell Apache what IP address to listen on in case you decide to add more.

Begin by modifying the NameVirtualHost entry in /etc/apache2/ports.conf as follows:

File excerpt:/etc/apache2/ports.conf

NameVirtualHost 12.34.56.78:80

Be sure to replace "12.34.56.78" with your IP address. Now, modify the default site's virtual hosting in the file /etc/apache2/sites-available/default so that the entry reads:

File excerpt:/etc/apache2/sites-available/default

<VirtualHost 12.34.56.78:80>

Configure Name-based Virtual Hosts First, create a file in the /etc/apache2/sites-available/ directory for each virtual host that you want to set up. Name each file with the domain for which you want to provide virtual hosting. See the following example configurations for the hypothetical "example.com" and "example.org" domains. Substitute your own domain names for those shown below. File:/etc/apache2/sites-available/example.com

<VirtualHost 12.34.56.78:80>
    ServerAdmin webmaster@example.com
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /srv/www/example.com/public_html/
    ErrorLog /srv/www/example.com/logs/error.log
    CustomLog /srv/www/example.com/logs/access.log combined
</VirtualHost>


File:/etc/apache2/sites-available/example.org

<VirtualHost 12.34.56.78:80>
    ServerAdmin webmaster@example.org
    ServerName example.org
    ServerAlias www.example.org
    DocumentRoot /srv/www/example.org/public_html/
    ErrorLog /srv/www/example.org/logs/error.log
    CustomLog /srv/www/example.org/logs/access.log combined
</VirtualHost>


Notes regarding this example configuration:
    All of the files for the sites that you host will be located in directories that exist underneath /srv/www. You can symbolically link these directories into other locations if you need them to exist in other places.
    ErrorLog and CustomLog entries are suggested for more fine-grained logging, but are not required. If they are defined (as shown above), the logs directories must be created before you restart Apache.
    Before you can use the above configuration, you'll need to create the specified directories. For the above configuration, you can do this with the following commands. Substitute your own domain names for those shown below.

mkdir -p /srv/www/example.com/public_html
mkdir /srv/www/example.com/logs
mkdir -p /srv/www/example.org/public_html
mkdir /srv/www/example.org/logs


After you've set up your virtual hosts, issue the following commands:

a2ensite example.com
a2ensite example.org


This command symbolically links your virtual host file from sites-available to the sites-enabled directory. Finally, before you can access your sites you must reload Apache with the following command:

/etc/init.d/apache2 reload

Assuming that you have configured the DNS for your domain to point to your IP address, Virtual hosting for your domain should now work.

The a2dissite command is the inverse of a2ensite. For example, if you wanted to disable the example.com site, you would issue the following command:

a2dissite example.com

After enabling, disabling, or modifying any part of your Apache configuration, you will need to reload the Apache configuration again with the "/etc/init.d/apache2 reload" command. You can create as many virtual hosting files as you need to support the domains that you want to host.

Install and Configure the MySQL Database Server

MySQL is a relational database management system (RDBMS) and is a popular component of web development tool-chains. It is used to store data for many popular applications, including Wordpress and Drupal.

Install MySQL

The first step is to install the mysql-server package, which is accomplished by the following command:

apt-get install mysql-server

During the installation you will be prompted for a password. Choose something secure (use letters, numbers, and non-alphanumeric characters) and record it for future reference.
At this point MySQL should be ready to configure and run. While you shouldn't need to change the configuration file, note that it is located at /etc/mysql/my.cnf for future reference.

Configure MySQL and Set Up Databases

After installing MySQL, it's recommended that you run mysql_secure_installation, a program that helps secure MySQL. While running mysql_secure_installation, you will be presented with the opportunity to change the MySQL root password, remove anonymous user accounts, disable root logins outside of localhost, and remove test databases. It is recommended that you answer yes to these options. If you are prompted to reload the privilege tables, select yes. Run the following command to execute the program:

mysql_secure_installation

Next, you may create a database and grant your users permissions to use databases. First, log in to MySQL:

mysql -u root -p

Enter MySQL's root password, and you'll be presented with a MySQL prompt where you can issue SQL statements to interact with the database. To create a database and grant your users permissions on it, issue the following command. Note, the semi-colons (;) at the end of the lines are crucial for ending the commands. Your command should look like this:

create database ex_db;
grant all on ex_db.* to 'ex_db_admin' identified by 'ex_db_admin_password';
flush privileges;

In the example above, "lollipop" is the name of the database, "foreman" is the username, and "5t1ck" is the password (without the quotes). Note that database user names and passwords are only used by scripts connecting to the database, and that database user account names need not (and perhaps should not) represent actual user accounts on the system. With that completed, you've successfully configured MySQL and you may now pass these database credentials on to your users. To exit the MySQL database administration utility issue the following command:

quit

With Apache and MySQL installed you are now ready to move on to installing PHP to provide scripting support for your web pages.

Install and Configure PHP

PHP makes it possible to produce dynamic and interactive pages using your own scripts and popular web development frameworks. Furthermore, many popular web applications like WordPress are written in PHP. If you want to be able to develop your websites using PHP, you must first install it.

Ubuntu includes packages for installing PHP from the terminal. Issue the following command:

apt-get install php5 php-pear

Once PHP5 is installed, you'll need to tune the configuration file located in /etc/php5/apache2/php.ini to enable more descriptive errors, logging, and better performance. These modifications provide a good starting point if you're unfamiliar with PHP configuration. Make sure that the following values are set, and relevant lines are uncommented (comments are lines beginning with a semi-colon (;)):

File excerpt:/etc/php5/apache2/php.ini

max_execution_time = 30
memory_limit = 64M
error_reporting = E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR
display_errors = Off
log_errors = On
error_log = /var/log/php.log
register_globals = Off

After making changes to the PHP configuration file, restart Apache by issuing the following command:

/etc/init.d/apache2 restart

If you need support for MySQL in PHP, then you must install the php5-mysql package with the following command:

apt-get install php5-mysql

To install the php5-suhosin package, which provides additional security for PHP 5 applications (recommended), issue the following command:

apt-get install php5-suhosin

Restart Apache to make sure everything is loaded correctly:

/etc/init.d/apache2 restart

Congratulations! That's it!

Tuesday 21 February 2012

Linux Mint hidden Startup Applications

If you have been using Linux Mint for a while you might notice that the Startup Applications Preferences has far fewer entries than before. This is because most of them are hidden by default, to get them back launch Terminal and run the following command:
sudo sed -i 's/NoDisplay=true/NoDisplay=false/g' /etc/xdg/autostart/*.desktop
Now you will be able to see all the applications and services that are set to automatically start

Monday 20 February 2012

TV Maxe

TV Maxe is a SopCast GUI that also supports mms, rmtp and http streams. By default, it comes with a Romanian channel list but more lists (International, UK, France, Danmark, Hungary, Spain, etc.) are available on its wiki page.

TV Maxe comes with a PPA for Lucid, Maverick Natty and Oneiric - add it and install TV Maxe using the commands below:

sudo apt-add-repository ppa:venerix/blug
sudo apt-get update
sudo apt-get install tv-maxe

For other Linux distributions, see the TV Maxe download page (but please note that you'll need to manually install the sp-auth package).

SopCast Player "segfault" Ubuntu x64

So, "sopcast-player" does not start, and you do:

strace sopcast-player

in terminal, and you get:

execve("/usr/bin/sopcast-player", ["sopcast-player"], [/* 42 vars */]) = 0
brk(0) = 0x74f000
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f7377495000
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=126050, ...}) = 0
mmap(NULL, 126050, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f7377476000
close(3) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0 \24\2\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=1677624, ...}) = 0
mmap(NULL, 3793768, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f7376ed8000
mprotect(0x7f737706d000, 2093056, PROT_NONE) = 0
mmap(0x7f737726c000, 20480, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x194000) = 0x7f737726c000
mmap(0x7f7377271000, 21352, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f7377271000
close(3) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f7377475000
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f7377473000
arch_prctl(ARCH_SET_FS, 0x7f7377473720) = 0
mprotect(0x7f737726c000, 16384, PROT_READ) = 0
mprotect(0x619000, 4096, PROT_READ) = 0
mprotect(0x7f7377497000, 4096, PROT_READ) = 0
munmap(0x7f7377476000, 126050) = 0
getpid() = 8514
rt_sigaction(SIGCHLD, {SIG_DFL, [CHLD], SA_RESTORER|SA_RESTART, 0x7f7376f0e420}, {SIG_DFL, [], 0}, 8) = 0
geteuid() = 1000
brk(0) = 0x74f000
brk(0x770000) = 0x770000
getppid() = 8513
stat("/home/paul", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
stat(".", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
open("/usr/bin/sopcast-player", O_RDONLY) = 3
fcntl(3, F_DUPFD, 10) = 10
close(3) = 0
fcntl(10, F_SETFD, FD_CLOEXEC) = 0
rt_sigaction(SIGINT, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGINT, {0x40f050, ~[RTMIN RT_1], SA_RESTORER, 0x7f7376f0e420}, NULL, 8) = 0
rt_sigaction(SIGQUIT, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGQUIT, {SIG_DFL, ~[RTMIN RT_1], SA_RESTORER, 0x7f7376f0e420}, NULL, 8) = 0
rt_sigaction(SIGTERM, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGTERM, {SIG_DFL, ~[RTMIN RT_1], SA_RESTORER, 0x7f7376f0e420}, NULL, 8) = 0
read(10, "#!/bin/sh\n/usr/bin/python /usr/s"..., 8192) = 77
clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f73774739f0) = 8515
wait4(-1, [{WIFSIGNALED(s) && WTERMSIG(s) == SIGSEGV}], 0, NULL) = 8515
--- SIGCHLD (Child exited) @ 0 (0) ---
write(2, "Segmentation fault\n", 19Segmentation fault
) = 19
read(10, "", 8192) = 0
exit_group(139)

There is a workaround for it. Edit /usr/share/sopcast-player/lib/vlc_1_0_x.py with root privileges.
At line 5453:
replace,

callbackmethod=ctypes.CFUNCTYPE(None, Event, ctypes.c_void_p)

by,

callbackmethod=ctypes.CFUNCTYPE(None, ctypes.POINTER(Event), ctypes.c_void_p)

Saturday 4 February 2012

Install Sopcast in Ubuntu / Linux Mint etc.

Open up a terminal and paste the following:

sudo apt-add-repository ppa:jason-scheunemann/ppa
sudo apt-get update
sudo apt-get install sopcast-player