Thứ Năm, 30 tháng 5, 2013

How To: Install LAMP on Ubuntu

References : http://gregrickaby.com/how-to-install-lamp-on-ubuntu/

They had already downloaded Ubuntu 11.04 (Natty), but didn’t know how to get Apache, MySQL, or PHP installed. He was signed into gTALK, so I sent him one command line…about 5 minutes later, they had the LAMP stack running.

Below is a laundry list of commands to help you configure the perfect Ubuntu server.
Last Update: 2013-05-12 – added Nginx

LAMP Stack (Apache, Mysql, PHP)

sudo apt-get install lamp-server^

(More) PHP 5

Some applications require other PHP5 mods
sudo apt-get install php5 php5-gd php5-mysql php5-curl php5-cli php5-cgi php5-dev

Nginx

sudo apt-get install nginx
NGIX doesn’t start on its own, so:
sudo service nginx start
Add Nginx module to Webmin

phpMyAdmin

sudo apt-get install phpmyadmin
Choose Apache and then YES for dbconfig-common.
If you ever need to edit phpMyAdmin config:
sudo nano /etc/dbconfig-common/phpmyadmin.conf

Webmin

sudo nano /etc/apt/sources.list
Scroll to the bottom and paste the following lines then save:
deb http://download.webmin.com/download/repository sarge contrib
deb http://webmin.mirror.somersettechsolutions.co.uk/repository sarge contrib

Import the key
wget http://www.webmin.com/jcameron-key.asc
sudo apt-key add jcameron-key.asc

Update the sources list
sudo apt-get update
Run the install
sudo apt-get install webmin

Start Webmin
sudo /etc/webmin/start
When it’s finished, open Firefox or Chrome and type:
http://localhost:10000/ (or if on a network) http://your-server-ip:10000/
If you’ve installed a fresh copy of Ubuntu (or if you don’t know your password) you can set a new one:
sudo passwd ubuntu
You’ll be prompted to enter your new password twice. Now, you can login to Webmin.

ProFTPd

sudo apt-get install proftpd
(I always select “standalone”)
Turn on Passive FTP via Webmin:
Servers –> ProFTPD server –> Virtual Servers –> Default Server –> Networking Options
Masquerade as address = your-server-outside-ip
PASV Port Range: 1024-1088

Sendmail

sudo apt-get install sendmail

PostFix Mail

sudo apt-get install postfix
Select “Internet Site” and then enter the domain name you want the Reverse DNS entry to be. BTW: To avoid your server being blacklisted, get a reverse DNS entry!

Alternative PHP Cache (APC)

APC is the de-facto in PHP acceleration. It’s a PHP opcode cacher and works by caching PHP objects, functions, and database queries into your server’s RAM. If you run a WordPress web site – then it takes full advantage of APC out-of-the-box. See my post on The Perfect APC Configuration
sudo apt-get install php-apc
By default, Ubuntu will install this from a repository which has an outdated version. To install the latest version of APC:
sudo apt-get install make
sudo apt-get install libpcre3-dev
sudo apt-get install php-pear
sudo pecl install apc
sudo /etc/init.d/apache2 restart
Uninstall APC
sudo pecl uninstall apc

Memcached

Like APC, Memcached is a high-performance, distributed memory object caching system. However, it can work together with multiple servers (unlike APC).
sudo apt-get install memcached
sudo apt-get install php-pear
sudo pecl install memcache
Check to see if Memcached is running
ps aux | grep memcached

Image Magick

sudo apt-get install imagemagick

Icecast2

Icecast is a streaming audio server. If you ever wanted to have your own web radio station (like Shoutcast) here it is:
sudo apt-get install icecast2

Configure Icecast2. Mainly, setting up your passwords and default port.
sudo nano /etc/icecast2/icecast.xml
Enable init.d script. Scroll to the bottom and change enable=true
sudo nano /etc/default/icecast2/

Start icecast2
sudo /etc/init.d/icecast2 start
If you left the default port as 8000 then you can view your Icecast2 Server
http://your-server.com:8000/

Munin – Graphical Server Monitor

Munin requires PHP-CLI
sudo apt-get install php-cli
Now, this is a single server setup, so let’s install munin and munin-node
sudo apt-get install munin munin-node

Configure Munin:
sudo nano /etc/munin/munin.conf
The first thing you should see is the operating directories. We need to change one of them:
# dbdir   /var/lib/munin
# htmldir /var/cache/munin/www
# logdir /var/log/munin
# rundir  /var/run/munin
to
# dbdir   /var/lib/munin
htmldir /var/www/munin
# logdir /var/log/munin
# rundir  /var/run/munin

Now let’s edit apache.conf
sudo nano /etc/munin/apache.conf
Delete everything inside apache.conf  and just add:
Alias /munin /var/www/munin
Move the web files to /var/www/munin
sudo mv /var/cache/munin/www/ /var/www/munin

Set permissions
sudo chown munin.munin -R /var/www/munin
Restart Munin
sudo /etc/init.d/munin-node restart
Finally, restart Apache
sudo /etc/init.d/apache2 restart
http://your-server.com/munin

Cacti – Graphical Server Monitor

sudo apt-get install cacti-spine
Choose YES for dbconfig-common and Apache2. When finished you need to configure:
http://your-server-ip-address/cacti
Default user & pass: admin / admin
Remove cacti
sudo apt-get remove cacti

BMON – Simple CLI Bandwidth Monitor

sudo apt-get install bmon
When it’s finished installing:
bmon

Zip and Unzip

sudo apt-get install zip

Other handy related commands:

Edit PHP.ini
sudo nano /etc/php5/apache2/php.ini
Restart Apache
sudo /etc/init.d/apache2 restart
Set Recursive Permissions for your websites direcotry
sudo chmod -R 775 /var/www/
cd /var/www/ sudo chmod -R www-data:www-data FOLDER NAME

Block IP addresses/hackers using IPTABLES

Single IP
iptables -A INPUT -s 192.168.100.1 -j DROP
IP Range
iptables -A INPUT -s 192.168.100.0/24 -j DROP
You can also manage IPTABLES (e.g., the linux firewall) via Webmin under “Networking”.

Manage packages

sudo apt-get update && sudo apt-get upgrade
sudo apt-get autoremove

Remove LAMP

sudo apt-get purge libapache2-mod-auth-mysql phpmyadmin
sudo apt-get purge mysql-server mysql-server-5.1 mysql-server-core-5.1
sudo apt-get purge apache2 apache2-mpm-prefork apache2-utils apache2.2-bin apache2.2-common libapache2-mod-php5
sudo apt-get autoremove

Serve your websites from an EBS volume

This practice has saved my butt on more than one occasion. Rather than use the given storage attached to the EC2 instance, I always create a 1TB EBS volume and mount it as /public_html/. That way, if your EC2 instance crashes…you’re web site files will not. For this, we’ll assume our attached EBS volume is /xvdf/.
First you must be logged in as root:
su
Make sure you’re in the file system root:
cd
Now, let’s list all the attached drives. You should see /dev/xvda1, /dev/xvdb, /dev/xvdf/ etc…
sudo fdisk -l
Let’s make a directory (such as /public_html/)
mkdir /public_html/
Finally, let’s mount our EBS volume:
mount -t ext4 /dev/xvdf /public_html/
Now you can serve your websites from an EBS volume!

Benchmark the CPU

time for i in {0..10000}; do for j in {0..1000}; do :; done; done
 
 

Không có nhận xét nào:

Đăng nhận xét

Học lập trình web căn bản với PHP

Bài 1: Các kiến thức căn bản Part 1:  https://jimmyvan88.blogspot.com/2012/05/can-ban-lap-trinh-web-voi-php-bai-1-cac.html Part 2:  https://...