Use apt-get to build a LAMP Environment

Source: Internet
Author: User
Tags download zend mcrypt mysql commands phpinfo

Transfer from http://wiki.ubuntu.org.cn/original address http://wiki.ubuntu.org.cn/Apache

"

Basic

If you are installing it on the local machine for testing, it is best to ensure that the hosts content is as follows:

username@ubuntu:~$ cat /etc/hosts127.0.0.1       localhost

[Edit] install

[Edit] install LAMP

1. Careful manual installation (minimum components)

sudo apt-get install apache2 php5-mysql libapache2-mod-php5 mysql-server

Some of them are automatically installed because of dependencies, but they are more suitable for insurance purposes. At the beginning of installation, sudo will ask you for the password (only possible), which is the password of the system administrator.During installation, MySQL requires a password for the account, which is irrelevant to the operating system.

2. Lazy Installation Method
In the new software package manager, selectEdit -- mark a software package with a task group

In the displayed windowSelect LAMP SERVERThen confirm.

In the main windowClick the green check mark application button.

Okay. The next step is to wait... until the new version is automatically downloaded and installed.During installation, MySQL requires a password for the account, which is irrelevant to the operating system.

Sudo apt-get install apache2 mysql-server php5 php5-mysql # terminal command

Open http: // localhost

Apache default page

[Edit] install phpmyadmin

In fact, this is also a security risk. We recommend that you use openssh to manage servers.

Solution 1: run commands on the terminal (not recommended)

sudo apt-get install phpmyadmin

Solution 2:

We strongly recommend that you do not install it from the source
Download the software package from the phpmyadmin website and decompress it to the local directory/var/www/phpmyadmin.
Tips: If you need to decompress it directly to/var/www/phpmyadmin. If phpmyadmin does not exist, create it by yourself.
Run

sudo cp /var/www/phpmyadmin/config.sample.inc.php /var/www/phpmyadmin/config.inc.php
sudo gedit /var/www/phpmyadmin/config.inc.php

Find blowfish_secret and fill in any letter

$cfg['Servers'][$i]['auth_type']='cookie';$cfg['Servers'][$i]['host']='localhost';$cfg['Servers'][$i]['connect_type']='tcp';$cfg['Servers'][$i]['compress']='false';$cfg['Servers'][$i]['extension']='mysql';

Save and exit

Install php5-mcrypt

sudo apt-get install php5-mcrypt

Edit the php configuration file

sudo gedit /etc/php5/apache2/php.ini 

Add it under extension (any independent row will work)

Extension = php_mcrypt.so (the original php5-mcrypt.so is invalid)

Save and restart apache2
Enter http: // localhost/phpmyadmin in the browser

[Edit] configuration file path

1> apache configuration file path/etc/apache2/apache2.conf

2> apache website character encoding configuration path/etc/apache2/conf. d/charset

3> php. ini path/etc/php5/apache2/php. ini

4> mysql configuration file path/etc/mysql/my. cnfDo not use it, especially for beginners.

5> phpmyadmin configuration file path/etc/phpmyadmin/apache. conf

6> default website root directory/var/www

[Edit] Common commands

1. Restart apache

sudo /etc/init.d/apache2 restart

2. Restart mysql

sudo /etc/init.d/mysql restart

[Edit] configure apache

1. Change the default Character Set
Use commands in the terminal

sudo nano /etc/apache2/conf.d/charset 

Replace

# AddDefaultCharset 

The well number removed, the following field is changed to UTF-8 (If your website is like this)

AddDefaultCharset     UTF-8 

The number of spaces in the middle is not important, but must exist.

2. Add the Supported file types (not required), and the website address (required)

Use commands in the terminal

sudo nano /etc/apache2/apache2.conf

Add the following lines at the end of the configuration file:

Support for adding file types

AddType application/x-httpd-php .php .htm .html

The order of adding the three homepage files can be changed to the previous access priority (of course, you can also add other settings such as default. php)

<IfModule dir_module>DirectoryIndex index.htm index.html index.php</IfModule>

Change server address (to local machine)

ServerName 127.0.0.1

Modify the apache root directory DocumentRoot:

sudo nano /etc/apache2/sites-enabled/000-default 

Change DocumentRoot/var/www to the desired directory, for example, DocumentRoot/var/www/htdocs/or above, and The Apache2 configuration is complete. Restart the Apache2 service. The following is a reference, which generally does not need to be changed unless there are special requirements.

Sudo nano/etc/apache2/ports. conf # modify the port number and Listen 80

Modify the configuration file of the site.

/etc/apache2/sites-available/default

80 is the port number.

<VirtualHost *:80>
Sudo a2enmod rewrite # enable the rewrite function of apache

[Edit] Apache module
Sudo a2enmod # enable the module
Sudo a2dismod # disable the module

[Edit] configure PHP5

There is nothing to say about it, depending on your own needs.
We recommend that you enable the Security Module (note! Phpmyadmin cannot be used after it is enabled)

sudo nano /etc/php5/conf.d/php.ini

Nano can use Ctrl + w to search and set safe_mode = off safe_mode = to safe_mode = on safe_mode =/var/www/htdocs/or above/var/www/htdocs/you are on the top set the website root directory, modify as needed. The ending/must be added,

Otherwise, directories such as/var/www/htdocsa,/var/www/htdocsb can also be accessed.

Change the default time zone

;date.timezone=

Remove the semicolon and add a PRC. Indicates the People's Republic of China (GMT + 8 time zone)

date.timezone= PRC

[Edit] configure MySQL

[Edit] MySQL Common commands

Most MySQL commands use

;

At the end, except for the command given in "5", the other commands must be

;

End!

1. Enter mysql

Mysql-h [server address]-u [user name]-p

This is to access the local server

Mysql-h 127.0.0.1-u [user name 〕

After the authentication is successful, go to the mysql command console. The following are commands on the mysql command console.

2. Display existing databases

SHOW DATABASES;

3. The name of the database to be created does not exist in !!, In linux, It is case sensitive (only related to the use time !).

Create datadases [database name];

4. create a restricted user. This user (testuser) has only one database (here is the test database) for access and writing. This database has the permission to create and Delete tables and can only be logged in locally, the password is userpasswd.

grant select insert update delete create alter on test.* to test@localhost  IDENTIFIED BY 'userpasswd';

5. log out of the database

quit

[Edit] configuration file (for beginners, do not change unless otherwise required)
sudo nano /etc/mysql/my.cnf

Note that only local access to the database is allowed by default.This does not mean that a website is set up on the local machine, and the user cannot access MySQL through the webpage. It means that other hosts cannot directly access MySQL.

bind-address 127.0.0.1

To remove the restriction, you can only access mysql locally. If you need access from other machines, use the following statement to comment out the "bind-address 127.0.0.1" sentence #

#bind-address 127.0.0.1

[Edit] configure phpmyadmin (do not check it if it is not installed)
sudo apt-get install phpmyadmin

Access http: // localhost/phpmyadmin. phpmyadmin is not installed under/var/www by default, but in/usr/share/phpmyadmin

You can copy or link phpmyadmin.

sudo ln -s /usr/share/phpmyadmin /var/www/phpmyadmin

Then run the command in the terminal

sudo gedit /etc/phpmyadmin/apache.conf

Then, change the path of the following two sentences to/var/www/phpmyadmin (because I have configured the environment, I forgot how to write the default configuration in phpmyadmin .. There are two sentences in the third and fourth rows. If I remember correctly, it should be as follows)

Alias /phpmyadmin /usr/share/phpmyadmin<Directory /usr/share/phpmyadmin>

Changed:

Alias /phpmyadmin /var/www/phpmyadmin<Directory /var/www/phpmyadmin>

[Edit] LAMP has been configured.

[Edit] Test phpinfo (). (You can select it as needed. Do not do it)

Create and test phpinfo:

sudo vi /var/www/info.php
<?php phpinfo(); ?>

Open http: // localhost/info. php.

Apache phpinfo page

[Edit] performance optimization (select your preferred one based on your needs)

[Edit] install Zend Optimizer

PHP version 5.2 is required. PHP5.3 of Ubuntu10.04 is not supported. See PHP5.2.

Download Zend Optimizer. Paste directly, refer to the version number to change (this is a 32-bit), or the home page can only be registered

 http://downloads.zend.com/optimizer/3.3.9/ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz 
tar zxvf ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz
cd ZendOptimizer-3.3.9-linux-glibc23-i386/data/5_2_x_compsudo mkdir /usr/local/zendsudo cp ZendOptimizer.so /usr/local/zend 

Edit php. ini

sudo gedit /etc/php5/apache2/php.ini

Note that punctuation marks must start with English.

[Zend Optimizer]zend_optimizer.optimization_level=1  zend_extension="/usr/local/zend/ZendOptimizer.so"

Restart apache2

sudo /etc/init.d/apache2 restart 

Or the above phpinfo file, you need to see the following information

This program makes use of the Zend Scripting Language Engine:Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies    with Zend Optimizer v3.3.9, Copyright (c) 1998-2009, by Zend Technologies

[Edit] server guard XCache
sudo apt-get install php5-xcache
root@ubuntu:/home/qii# dpkg -l | grep xcachii  php5-xcache                          1.2.2-5                                         Fast, stable PHP opcode cacher

The xcache configuration file path is

/etc/php5/conf.d/xcache.ini

Edit php. ini

sudo gedit /etc/php5/apache2/php.ini

Add the xcache. ini content to php. ini. Restart apache2

sudo /etc/init.d/apache2 restart 

Check whether the installation is successful

root@ubuntu:/home/qii# php -vPHP 5.2.10-2ubuntu6 with Suhosin-Patch 0.9.7 (cli) (built: Oct 23 2009 16:30:10) Copyright (c) 1997-2009 The PHP GroupZend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies    with XCache v1.2.2, Copyright (c) 2005-2007, by mOo

The previous info. php page should contain the XCache module.

XCache module on info page

It is a bit strange here that apache can load xcache without adding the XCache. ini content to php. ini, but there is no XCache module in info. php.

[Edit] install eAccelerator
sudo apt-get install php5-dev

Download eAccelerator

wget http://bart.eaccelerator.net/source/0.9.6.1/eaccelerator-0.9.6.1.tar.bz2
tar jxvf eaccelerator-0.9.6.1.tar.bz2
cd eaccelerator-0.9.6.1 
phpizesudo ./configure -enable-eaccelerator=sharedsudo make
qii@ubuntu:~/tmp/eaccelerator-0.9.6.1$ sudo make installInstalling shared extensions:     /usr/lib/php5/20060613+lfs/

Modify the php. ini file and install it as the Zend extension. It is best to put it at the beginning and put it before [zend] To avoid inexplicable problems:

sudo vi /etc/php5/apache2/php.ini
[eaccelerator]zend_extension="/usr/lib/php5/20060613+lfs/eaccelerator.so" eaccelerator.shm_size="16" eaccelerator.cache_dir="/tmp/eaccelerator" eaccelerator.enable="1" eaccelerator.optimizer="1" eaccelerator.check_mtime="1" eaccelerator.debug="0" eaccelerator.filter="" eaccelerator.shm_max="0" eaccelerator.shm_ttl="0" eaccelerator.shm_prune_period="0" eaccelerator.shm_only="0" eaccelerator.compress="1" eaccelerator.compress_level="9" eaccelerator.allowed_admin_path="/var/www/control.php"

Create cache directory

Eaccelerator. cache_dir = "/var/cache/eaccelerator" the cache path is defined here.

The default value is/tmp/eaccelerator. This is very simple because anyone can write to this directory, but it is unwise because the directory is automatically cleared after restart. A better solution is/var/cache/eaccelerator. Create the Directory and make sure it is writable to the user of the eAccelerator (generally, this user is your web server operator, and may be www-data ). Use the default value to continue:

mkdir /tmp/eaccelerator
chmod 777 /tmp/eaccelerator

Change to/var/cache/eaccelerator.

eaccelerator.cache_dir="/var/cache/eaccelerator" 
sudo mkdir /var/cache/eacceleratorsudo chown root:www-data /var/cache/eacceleratorsudo chmod u=rwx,g=rwx,o= /var/cache/eaccelerator

Copy control file control. php to the website root directory

sudo cp control.php /var/www/htdocs/

Modify $ user and $ pw of control. php. The default values are admin and eAccelerator.

sudo vi /var/www/htdocs/control.php 

Restart apache

sudo /etc/init.d/apache2 restart

Open http: // localhost/control. php

EAccelerator control. php page

View the following fields on the info. php page:

This program makes use of the Zend Scripting Language Engine:Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies    with eAccelerator v0.9.6.1, Copyright (c) 2004-2010 eAccelerator, by eAccelerator    

[Edit] others

[Edit] install PDO
pecl search pdo
sudo pecl install pdo
sudo pecl install pdo_mysql

Finally, edit php. ini.

sudo gedit /etc/php5/apache2/php.ini 

Add two rows at the end:

extension = pdo.so
extension = pdo_mysql.so

<Nowiki> insert unformatted text here </nowiki> </nowiki>

[Edit] troubleshooting

[Edit] The php file cannot be parsed. the browser prompts you to download the PHP file to be opened.

Run:

sudo apt-get install libapache2-mod-php5sudo a2enmod php5

If:

This module does not exist!

Then you need to completely delete the libapache2-mod-php5, and then reinstall it

sudo apt-get remove --purge libapache2-mod-php5sudo apt-get install libapache2-mod-php5

Restart apache2

sudo /etc/init.d/apache2 restart

Clear the browser cache and enter http: localhost

[Edit] VM

See Apache Virtual Host Guide

[Edit] SHIELD thunder

The user-agent of thunder is

Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; )Mozilla/5.0  (compatible; MSIE 6.0; Windows NT 5.0)Mozilla/4.0 (compatible; MSIE  6.0; Windows NT 5.0; .NET CLR 3.5.20706)Mozilla/4.0 (compatible;  MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)

Use the. htaccess file to shield Thunder's download/leeching functions:

RewriteEngine On#Anti ThunderRewriteCond  %{HTTP_USER_AGENT}  ^Mozilla/4\.0\  \(compatible;\ MSIE\ 6\.0;\ Windows\ NT\ 5\.0\)$  [NC,OR]RewriteCond   %{HTTP_USER_AGENT}  ^Mozilla/5\.0\ \(compatible;\ MSIE\ 6\.0;\ Windows\  NT\ 5\.0\)$  [NC,OR]RewriteCond  %{HTTP_USER_AGENT}  ^Mozilla/4\.0\  \(compatible;\ MSIE\ 6\.0;\ Windows\ NT\ 5\.1;\ \)$   [NC,OR]RewriteCond   %{HTTP_USER_AGENT}  ^Mozilla/4\.0\ \(compatible;\ MSIE\ 6\.0;\ Windows\  NT\ 5\.0;\ \.NET\ CLR\ 3\.5\.20706\)$  [NC,OR]RewriteCond   %{HTTP_USER_AGENT}  ^Mozilla/4\.0\ \(compatible;\ MSIE\ 6\.0;\ Windows\  NT\ 5\.1;\ SV1;\ \.NET\ CLR\ 1\.1\.4322;\ \.NET\ CLR\ 2\.0\.50727\)$   [NC]RewriteRule  ^.*\.(gif|jpg|bmp|zip|rar|exe|mp3|swf)$   /    [NC,F]

You can use Firefox's extended user-agent switcher to test the effect.

If your data address has been indexed by thunder, modify the path address of the resource.

If the user manually uses UltraEdit to rewrite the user-agent of thunder, or installs a virtual machine on the local machine, mounts the virtual machine to the proxy, and mounts the proxy in the virtual machine, this blocking method becomes invalid.

"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.