Switch PHP version ubuntu & debain

From php5.6 to php7.0 :
Apache:
sudo a2dismod php5.6 ; sudo a2enmod php7.0 ; sudo service apache2 restart
CLI:
update-alternatives –set php /usr/bin/php7.0
from php7.0 to php5.6 :
Apache:
sudo a2dismod php7.0 ; sudo a2enmod php5.6 ; sudo service apache2 restart
CLI:
sudo update-alternatives –set php /usr/bin/php5.6

Advertisements

Apache and Node.js on the same Ubuntu server

Install Node.js

apt-get install nodejs
apt-get install npm
 apt-get install build-essential

Install express node module

npm install express

Edit Apache

sudo a2enmod proxy
sudo a2enmod proxy_http
edit the  default apache conf
ProxyRequests Off
<Proxy *>
 Order deny,allow
 Allow from all
 </Proxy>
 <Location /node>
 ProxyPassReverse  http://server-name:5000
 </Location>
Now restart the apache 
service apache2 restart
The first app
created two files: web.js and package.json
web.js:
varexpress = require("express");
varapp = express();
app.use(express.logger());
app.get('/', function(request, response) {
    response.send('Hello World!');
});
app.get('/test', function(request, response) {
    response.send('This was only a test');
});
app.use(function(err, req, res, next){
  console.error(err.stack);
  res.send(500, 'Something broke!');
});
varport = process.env.PORT || 8080;
app.listen(port, function() {
    console.log("Listening on "+ port);
});
package.json:
{
  "name": "node-example",
  "version": "0.0.1",
  "dependencies": {
    "express": "3.1.x"
  },
  "engines": {
    "node": "0.10.x",
    "npm": "1.2.x"
  }
}
Start the app
    node web.js

How To Add Swap on Ubuntu

Check for Swap Space

sudo swapon -s

An empty list will confirm that you have no swap files enabled:

Filename				Type		Size	Used	Priority

Check the File System

df
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sda        20907056 1437188  18421292   8% /
udev              121588       4    121584   1% /dev
tmpfs              49752     208     49544   1% /run
none                5120       0      5120   0% /run/lock

Create and Enable the Swap File

sudo dd if=/dev/zero of=/swapfile bs=1024 count=256k
sudo mkswap /swapfile

The results display:

Setting up swapspace version 1, size = 262140 KiB
no label, UUID=103c4545-5fc5-47f3-a8b3-dfbdb64fd7eb

Finish up by activating the swap file:
sudo swapon /swapfile

You will then be able to see the new swap file when you view the swap summary.

swapon -s
Filename				Type		Size	Used	Priority
/swapfile                               file		262140	0	-1

This file will last on the virtual private server until the machine reboots. You can ensure that the swap is permanent by adding it to the fstab file.

Open up the file:

sudo nano /etc/fstab

Paste in the following line:

/swapfile       none    swap    sw      0       0 

Swappiness in the file should be set to 10. Skipping this step may cause both poor performance, whereas setting it to 10 will cause swap to act as an emergency buffer, preventing out-of-memory crashes.

You can do this with the following commands:

echo 10 | sudo tee /proc/sys/vm/swappiness
echo vm.swappiness = 10 | sudo tee -a /etc/sysctl.conf

To prevent the file from being world-readable, you should set up the correct permissions on the swap file:

sudo chown root:root /swapfile 
sudo chmod 0600 /swapfile


 none 124372 0 124372 0% /run/shm