Install the LAMP environment in ubuntu

Source: Internet
Author: User
Tags download zend mcrypt mysql commands php cli
Linux + Apache + Mysql + Perl/PHP/Python is a group of open-source software commonly used to build dynamic websites or servers. they are independent programs, but they are often used together, with a higher degree of compatibility, together constitute a powerful Web application platform UbuntuLAMP

LAMP concept:

Linux + Apache + Mysql + Perl/PHP/Python is a group of open-source software commonly used to build dynamic websites or servers. they are independent programs, but they are often used together, with higher compatibility, a powerful Web application platform is formed together.

After LAMP is installed, the Perl/PHP/Python voice environment of the web server database has been installed.

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

Install

Install LAMP

Kit one-time installation

sudo tasksel

Select LAMP with a space and press enter. (But be careful not to modify other options. Otherwise, the service will be installed or deleted !)

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.

Graph 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.

Note: During installation, MySQL requires that the account have a password, which is irrelevant to the operating system.

Open http: // localhost or http: // 127.0.0.1

Graphical management software (optional)

Install webmin

This is a system management software that manages most system services including LAMP components. Multiple system functions such as installation and process management can also be performed.

Download the software from the webmin official website and open the terminal at the location where the software package is stored. (You can also use commands to switch to this location)

Sudo dpkg-I software package name (you can use a Tab to enter less words)

If you are prompted that the dependency is missing, install the dependency.

Access address (encrypted secure link): https: // 127.0.0.1: 10000

Install phpmyadmin

This is a database management software that manages mysql.

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

sudo /etc/init.d/apache2 restart

Enter http: // localhost/phpmyadmin in the browser

Note: If you fail to reference the configuration file when you enter phpmyadmin, delete

$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
Then restart apache2.

sudo /etc/init.d/apache2 restart

Enter http: // localhost/phpmyadmin in the browser

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

Common Commands

1. restart apache

sudo /etc/init.d/apache2 restart

2. restart mysql

sudo /etc/init.d/mysql restart

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:

Supports adding file types (note: If php statements cannot be parsed in html, add the following statements. Many online users say that httpd is directly edited. conf, but the ubuntu version of apache2 does not have this file, you can directly edit apache2.conf, or add an httpd. conf, as the user configuration file, include this configuration file in apache2.conf .)

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)

 
  DirectoryIndex index.htm index.html index.php
 

Change the server address (here changed to the local machine). you can modify the server address according to your preference, that is, the server address must be consistent.

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, change NameVirtualHost *: 80 to NameVirtualHost 127.0.0.1: 80, and modify Listen 80.

Modify the configuration file of the site.

/etc/apache2/sites-available/default

80 is the port number.

 
Sudo a2enmod rewrite # enable the rewrite function of apache

Apache Module

Sudo a2enmod # enable the module
Sudo a2dismod # Disable the module

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

Note:You may need to input the command

php --ini

Or

php -i | grep php.ini

To get your php cli-loaded php. ini path (Loaded Configuration File, such as/etc/php5/cli/php. ini instead of/etc/php5/conf. d/php. ini ). However, this file is not necessarily the php. ini file loaded by the apache php5 module. to obtain the php. ini file loaded by the apache php5 module, see test _ phpinfo ()

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

Configure MySQL

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]-p
For example, mysql-h 127.0.0.1-u root-p

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 datadase [Database name];

4. create a restricted user. this user (testuser) has only one database (here is the test database) access and write permissions. 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 or \ q

Configuration file (new user, do not touch without special requirements)

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

Configure phpmyadmin)

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
 

Changed:

Alias /phpmyadmin /var/www/phpmyadmin
 

LAMP has been configured.

Test phpinfo (). (select the phpinfo as needed. do not do it)

Create and test phpinfo:

Sudo vi/var/www/info. php note: the path here is wrong, it should be sudo vi/var/www/htdocs/info. php modifier: fenghelong mailbox fenghelong_njit@163.com
 

Open http: // localhost/info. php.

Performance Optimization (you can choose one or more based on your needs)

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

Ann? 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.

 

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.

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

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

Security

Hide server information

vim /etc/apache2/apache2.confServerTokens Prod

Apache2 running account

It is very dangerous to run it as root. use the following methods to change it. here we will change it to www-data.

vim /etc/apache2/envvarsexport APACHE_RUN_USER=www-dataexport APACHE_RUN_GROUP=www-data

Confirm that these user groups exist.

Enable. htaccess

This is advantageous for the program with. htaccess such as pbpbb3, but it may cause problems in other occasions. Method: Add AllowOverride AuthConfi to the website host configuration. example:

vim /etc/apache2/sites_available/default
 ...AllowOverride AuthConfig...

Others

PDO installation

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

Troubleshooting

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

Virtual host

See Apache virtual host Guide

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\)___FCKpd___98nbsp; [NC,OR]RewriteCond   %{HTTP_USER_AGENT}  ^Mozilla/5\.0\ \(compatible;\ MSIE\ 6\.0;\ Windows\  NT\ 5\.0\)___FCKpd___98nbsp; [NC,OR]RewriteCond  %{HTTP_USER_AGENT}  ^Mozilla/4\.0\  \(compatible;\ MSIE\ 6\.0;\ Windows\ NT\ 5\.1;\ \)___FCKpd___98nbsp;  [NC,OR]RewriteCond   %{HTTP_USER_AGENT}  ^Mozilla/4\.0\ \(compatible;\ MSIE\ 6\.0;\ Windows\  NT\ 5\.0;\ \.NET\ CLR\ 3\.5\.20706\)___FCKpd___98nbsp; [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\)___FCKpd___98nbsp;  [NC]RewriteRule  ^.*\.(gif|jpg|bmp|zip|rar|exe|mp3|swf)___FCKpd___98nbsp;  /    [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.

Appendix

List of apache2 configuration files and subdirectories

/Etc/apache2/apache2.conf global configuration/etc/apache2/envvars environment variable/etc/apache2/ports. conf httpd service port information/etc/apache2/conf. d/general configuration file storage location/etc/apache2/mod-available/installed module/etc/apache2/mod-enabled/enabled module/etc/apache2/sites- available/available site information/etc/apache2/sites-enabled/enabled site information, the file in is a soft connection to the/etc/apache2/sites-available/file. /Etc/apache2/httpd. conf

Related Article

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.