Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Detailed installation tutorial of LAMP environment under ubuntu

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the relevant knowledge of "detailed installation tutorial of LAMP environment under ubuntu". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

The concept of LAMP:

Linux+Apache+Mysql+Perl/PHP/Python is a group of open source software commonly used to build dynamic websites or servers, which are independent programs themselves, but because they are often used together, they have a higher and higher degree of compatibility and form a powerful Web application platform.

Installation of LAMP has already installed the web server database Perl/PHP/Python voice environment.

If you are installing to test on this machine, it is best to make sure that the content of hosts is like this.

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

Installation

Install LAMP

One-time installation of kit

Sudo tasksel

Select LAMP with the space, and press enter. (however, be careful not to modify other options, otherwise the service will be installed or removed! )

Careful manual installation (smallest piece)

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

Some are automatically installed because of dependencies, but for insurance purposes, more calls have been made. At the beginning of the installation, sudo will ask you for your password (only possible), which is the password of your system administrator. During the installation, MySQL requires that the account has a password, which has nothing to do with the operating system.

Graphic installation method

Select Edit in Synaptic package Manager-Mark the package using task grouping

Check LAMP SERVER in the open window and then OK.

Click the green sign application button in the main window

All right, then. The next step is to wait. Wait for Synaptic to download and install automatically.

Note: during the installation, MySQL requires that the account has a password, which has nothing to do with 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. At the same time, it can carry out a variety of system functions such as installation, process management and so on.

First, go to the webmin official download software and open the terminal under the location of the software package. (you can also use the command to switch to this position)

Sudo dpkg-I package name (you can type fewer words with Tab)

If there is a lack of dependency, pretend to be what is missing.

Access address (note: encrypted security link): https://127.0.0.1:10000

Install phpmyadmin

This is a database management software, management mysql.

In fact, this is also a security risk, it is recommended to use openssh to manage the server.

Option 1: run commands in the terminal (not recommended)

Sudo apt-get install phpmyadmin

Option 2:

It is strongly recommended that you do not install from the source

Download the software package from phpmyadmin and extract it to the local directory / var/www/phpmyadmin

Tips: if you extract it directly to / var/www/phpmyadmin, if there is no phpmyadmin, please create it yourself.

Execute under the terminal

Sudo cp / var/www/phpmyadmin/config.sample.inc.php / var/www/phpmyadmin/config.inc.phpsudo gedit / var/www/phpmyadmin/config.inc.php

Find "blowfish_secret" and fill in any letter after it.

$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, exit

Install php5-mcrypt

Sudo apt-get install php5-mcrypt

Edit php profile

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

Add (any separate line will do) under extension

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

Save, restart apache2

Sudo / etc/init.d/apache2 restart

Type http://localhost/phpmyadmin in the browser

Note: if the profile reference fails to enter phpmyadmin, delete the one you just added yourself.

$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, exit

Then restart apache2

Sudo / etc/init.d/apache2 restart

Type http://localhost/phpmyadmin in the browser

Configuration file path

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

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

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

4 > mysql profile path / etc/mysql/my.cnf is generally not used, especially for beginners.

5 > phpmyadmin profile path / etc/phpmyadmin/apache.conf

6 > default site root / var/www

Common command

1. Restart apache

Sudo / etc/init.d/apache2 restart

two。 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

Put one of them

# AddDefaultCharset

Remove the pound sign and change the following field to UTF-8 (if this is the case with your website)

AddDefaultCharset UTF-8

The number of spaces in the middle is not important, but there must be one.

two。 Add support file type (generally not required), with 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:

Add file type support (Note: if the php statement cannot be parsed in html, add the following statement. Many people on the Internet are talking about editing httpd.conf directly, but the ubuntu version of apache2 does not have this file, you can edit apache2.conf directly, or add your own httpd.conf as a user profile, include in apache2.conf.)

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

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

DirectoryIndex index.htm index.html index.php

Change the server address (change it to local machine here), you can modify it according to your preference, but it must be consistent.

ServerName 127.0.0.1

Modify the root directory DocumentRoot of apache:

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

Change the DocumentRoot / var/www to the directory you want, such as DocumentRoot / var/www/htdocs/ or above Apache2, and the basic configuration is complete. Just restart the Apache2 service. The following is a reference, which generally does not need to be changed, unless there are special needs.

Sudo nano / etc/apache2/ports.conf # modify the port number, change NameVirtualHost *: 80 to NameVirtualHost 127.0.0.1 NameVirtualHost 80, modify Listen 80

Then modify the configuration file of 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 module sudo a2dismod # disable module

Configure PHP5

There's nothing to say about this, according to one's own needs.

It is recommended to open the security module (pay attention! Can phpmyadmin be used after it is enabled)

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

Note: you may need to type in the command

Php-ini

Or

Php-I | grep php.ini

To get the php.ini path (Loaded Configuration File, such as / etc/php5/cli/php.ini instead of / etc/php5/conf.d/php.ini) loaded by your php cli. But this file is not necessarily the php.ini file loaded by the apache php5 module. If you want to get the php.ini 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/ is where you set the root directory of the website. Please modify it as appropriate. The / at the end must be added.

Otherwise, / var/www/htdocsa,/var/www/htdocsb, and other directories can also be accessed.

The following is to change the default time zone

; date.timezone=

Remove the semicolon and add a PRC after it. Represents the people's Republic of China (that is, the GMT+8 time zone)

Date.timezone= PRC

Configure MySQL

MySQL common commands

Most of the commands in MySQL are

At the end, except for the command given by 5, the rest must be marked with

The end!

1. Enter mysql

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

This is access to the local server

Mysql-h 127.0.0.1-u [user name)-p such as: mysql-h 127.0.0.1-u root-p

After the authentication is successful, enter the command console of mysql. The following are the commands in the command console of mysql.

two。 Show existing databases

SHOW DATABASES

3. There is no [] number to create a database name here! And under linux it is case-sensitive (only relevant when using it! ).

CREATE DATADASE [database name]

4. Create a restricted user this user (testuser) has access to only one database (in this case, the test library), the database has permission to create and delete tables, and can only log in locally with a password of userpasswd

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

5. Exit the database

Quit or\ Q

Configuration file (novice, do not move without special requirements)

Sudo nano / etc/mysql/my.cnf

Here is a place to pay attention to the default: only allow local access to the database here does not mean that the local set up a website, users through the web pages set up can not access MySQL, it means that other computers cannot directly access MySQL

Bind-address 127.0.0.1

Remove the restriction that you can only access mysql locally. If you need other machine access, you should use the following statement to comment out the sentence "bind-address 127.0.0.1" with #

# bind-address 127.0.0.1

Configure phpmyadmin (if you don't install it, don't read it)

Sudo apt-get install phpmyadmin

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

You can copy the phpmyadmin or link it.

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. Anyway, there are two sentences in the third and fourth lines. If I remember correctly, it should be as follows)

Alias / phpmyadmin / usr/share/phpmyadmin

Change to:

Alias / phpmyadmin / var/www/phpmyadmin

LAMP has been configured at this point

Test phpinfo (); (choose but not to do as needed)

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 (choose by yourself, but do not do as needed)

Install Zend Optimizer

PHP version 5.2 is required. PHP5.3 of Ubuntu10.04 is not supported. Please refer to PHP5.2.

Download Zend Optimizer. Directly post the download address, refer to the version number to change (this is 32-bit), otherwise the home page must be registered before it can be downloaded

Http://downloads.zend.com/optimizer/3.3.9/ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gztar zxvf ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gzcd 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

Add at the beginning, pay attention to the punctuation marks in English.

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

Restart apache2

Sudo / etc/init.d/apache2 restart

The same phpinfo file above should be able 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

Install XCache

Sudo apt-get install php5-xcacheroot@ubuntu:/home/qii# dpkg-l | grep xcachii php5-xcache 1.2.2-5 Fast, stable PHP opcode cacher

The path to the xcache configuration file is

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

Edit php.ini

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

Add the contents of xcache.ini 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 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

And there should be a XCache module on the front info.php page.

It's a little strange that you can load XCache without adding the contents of xcache.ini to php.ini,apache, but there is no XCache module on 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.bz2tar jxvf eaccelerator-0.9.6.1.tar.bz2cd eaccelerator-0.9.6.1phpizesudo. / configure-enable-eaccelerator=sharedsudo makeqii@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 a Zend extension. It is best to put it at the beginning and before [zend], to avoid inexplicable problems:

Sudo vi / etc/php5/apache2/ php.ini] 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 a cache cache directory

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

The default value is / tmp/eaccelerator, which is very simple because anyone can write to the directory, but it is unwise because the system automatically cleans up the directory after reboot. A better place is / var/cache/eaccelerator. Create this directory and make sure it is writable to eAccelerator users (usually the user is your web server operator, possibly www-data). With the default value, continue like this:

Mkdir / tmp/eacceleratorchmod 777 / tmp/eaccelerator

If you change it to / var/cache/eaccelerator, go on like this, change php.ini first.

Eaccelerator.cache_dir= "/ var/cache/eaccelerator" sudo mkdir / var/cache/eacceleratorsudo chown root:www-data / var/cache/eacceleratorsudo chmod upright RWX Magazine gendarrwx Magi o = / var/cache/eaccelerator

Copy the control file control.php to the root of the website

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

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

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

Restart apache

Sudo / etc/init.d/apache2 restart

Open http://localhost/control.php

Looking at the previous info.php page, there are the following fields:

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

Safety

Hide server information

Vim / etc/apache2/apache2.confServerTokens Prod

Specify the running account of apache2

It is dangerous to run with root, change it in the following way, here it is all changed to www-data

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

To confirm that these user groups exist.

Enable .htaccess

This is good for programs like pbpbb3 that come with .htaccess, but can cause problems in other situations. Method: add an example of AllowOverride AuthConfi under the host configuration of the website:

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

Other

Installation of PDO

Pecl search pdosudo pecl install pdosudo pecl install pdo_mysql

Last edit php.ini

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

Add two more lines at the end:

Extension = pdo.soextension = pdo_mysql.so

Troubleshooting

Unable to parse php file, browser prompts to download php file to be opened

Execute:

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

If it is displayed as:

This module does not exist!

Then delete libapache2-mod-php5 completely 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 hosting guide

Shield Thunderbolt

The user-agent of Thunderbolt 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)

Block Xunlei's download / hotlink function through .htaccess files:

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 Thunderbolt, please modify the path address of the resource.

If users use UltraEdit to rewrite the user-agent of Xunlei, or install a virtual machine locally, hang a proxy in a virtual machine, or hang a proxy in a virtual machine, this shielding method will be invalid.

This is the end of the detailed installation tutorial for the LAMP environment under ubuntu. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report