How to install LAMP (Apache, MySQL and PHP) on Ubuntu

1. Install Apache
To install Apache you must install the apache2 by running this command.

sudo apt-get install apache2

2. Install MySQL
To install MySQL you must install mysql-server by running the following command.

sudo apt-get install mysql-server

3. Install PHP
To install PHP you must install php5 and libapache2-mod-php5 by running the command below.

sudo apt-get install php5 libapache2-mod-php5

4. Restart Apache Server
Your server should restart Apache automatically after the installation of both MySQL and PHP. If it doesn’t, execute this command to do that.

sudo /etc/init.d/apache2 restart

5. Check Apache
Open a web browser and navigate to http://localhost/. You should see a message saying It works!

6. Check PHP
You can check your PHP by executing any PHP file from within /var/www/ or execute the following command, which will make PHP run the code without the need for creating a file .

php -r 'echo "\n\nYour PHP installation is working fine.\n\n\n";'

How to Set Up VSFTP on CentOS

Warning: FTP is inherently insecure. if you must use FTP, consider securing your FTP connection with SSL/TLS. otherwise, it is best to use SFTP, a secure alternative to FTP.
The first two letters of vsftpd stand for “very secure” and the program was built to have strongest protection against possible FTP vulnerabilities.
You can install vsftpd on your server by running the command below

yum install vsftpd

Once VSFTP is installed, you can adjust the configuration. open the configuration file:

nano /etc/vsftpd/vsftpd.conf

change the anonymous_enable to No

anonymous_enable=NO

Prior to this change, vsftpd allowed anonymous, unidentified users to access the server’s files.
After that, uncomment and change these two lines as shown below

local_enable=YES
chroot_local_user=YES

Now all the local users will be jailed within their chroot and will be denied access to any other part of the server.
Restart VSFTP

service vsftpd restart

In order to ensure that vsftpd runs at boot, run chkconfig:

chkconfig vsftpd on

Apache Redirect HTTP to HTTPS

If you want to redirect all HTTP requests to your site to the HTTPS version, all you need to do is add the following code to your .htaccess file:

RewriteEngine On
# This will enable the Rewrite capabilities
RewriteCond %{HTTPS} !=on
# This checks to make sure the connection is not already HTTPS
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]

Apache Redirect non-www to www

If you want to redirect all non-www requests to your site to the www version, all you need to do is add the following code to your .htaccess file:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

This will redirect any requests to http://domain.com to http://www.domain.com.
Advantages:

  • Avoid duplicate content in Google
  • Avoid the possibility of split page rank and link popularity (inbound links).

Uninstalling CloudLinux

To uninstall CloudLinux (convert the system back to CentOS), run the command bellow

wget -O cldeploy http://repo.cloudlinux.com/cloudlinux/sources/cln/cldeploy
sh cldeploy -c

At the end, script will provide instructions on how to remove CloudLinux kernel (manual step), and install CentOS kernel (if needed) by running this command.

yum install kernel kernel-headers

Make sure grub entries are fine (by checking this file /boot/grub/grub.conf) and reboot. once the server is back execute command below to cleanup CloudLinux

yum remove lve liblve lve-utils lve-stats

Then rebuild Apache

(In cPanel servers) /scripts/easyapache --build

That’s all

Setup a remote connection to MySQL

First start MySQL with this command

mysql -u root -p

Enter your MySQL root password
Now grant all privileges to remote user

GRANT ALL PRIVILEGES ON DATABASE.* TO USERNAME@IP IDENTIFIED BY "PASSWORD";

DATABASE: is the database that you would like to grant access too.
USERNAME: is the username that you would like to create.
IP: is the public IP address of your remote server.
PASSWORD: is the password you would like to use for this username.
If you need to revoke privileges from user

REVOKE ALL PRIVILEGES ON DATABASE.* FROM USERNAME@IP

Now you must flush MySQL’s privileges

FLUSH PRIVILEGES;

Exit MySQL

exit

Configure iptables to allow remote connections to port 3306

iptables -A INPUT -p tcp -m tcp --dport 3306 -j ACCEPT
service iptables save
service iptables restart

Configure MySQL to accept remote connections, open “/etc/my.cnf” and add this line

bind-address=YOUR REMORE SERVER IP

Then restart MySQL

service mysql restart

It’s done, now you can connect MySQL server remotely
You can use this command in remote server to connect

mysql -h IP -u USERNAME -pPASSWORD DATABASE

How to Setup FreeRADIUS on CentOS 6

Follow the instructions below

yum install freeradius freeradius-mysql freeradius-utils mysql-server -y

To setup MySQL you need to start the service by running command below

service mysqld start

Now run the following command to set MySQL password and security settings

/usr/bin/mysql_secure_installation

Now we need to create radius database

mysql -u root -p

Then enter your MySQL root password
Create radius database and grant all privileges to user radius

CREATE DATABASE radius;
GRANT ALL PRIVILEGES ON radius.* TO radius@localhost IDENTIFIED BY "radpass";

And replace radpass with your radius database password
Now we want to import radius databases tables

use radius;
SOURCE /etc/raddb/sql/mysql/schema.sql

Exit from MySQL

exit

Now open “/etc/raddb/sql.conf” and enter your MySQL database you created

nano /etc/raddb/sql.conf

In “/etc/raddb/radiusd.conf” ensure line below is uncommented

$INCLUDE  sql.conf

And in “/etc/raddb/sites-available/default” ensure lines contain “sql” in “authorize”, “accounting” and “session” sections is uncommecnted.
Additionally in “/etc/raddb/sites-available/inner-tunnel” uncomment lines contain “sql” in “authorize” and “session” sections.
Now check to see if Radius is working

service radiusd start
service radiusd stop

To add clients you should edit “/etc/raddb/clients.conf” and insert them after line:

# coa_server = coa
}

Add a block like this for each client

client VPN_SERVER_IP {
  secret = YOUR CLIENT SECRET HERE
  shortname = YOUR CLIENT NAME
  nastype = other
}

Everytime you add or change a value in the config files you need to restart radius to apply changes

service radiusd restart

Add a test user to the radius database
First you need to login to your mysql radius database:

mysql -u root -p

Enter your MySQL root password
Switch to use the radius database

use radius;
INSERT INTO `radcheck` (`id`, `username`, `attribute`, `op`, `value`) VALUES (1,'test','User-Password',':=','test');

Exit from MySQL

exit

now test the test user with radclient

radtest test test 127.0.0.1 0 mysecret

Replace mysecret with your FreeRadius secret, you can find it in “/etc/raddb/clients.conf”
If you see “Access-Accept” then your installation is working.