Ubuntu Linux: Apache installation settings

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


Apache
Directory
  • 1
    Basic
  • 2
    Install

    • 2.1
      Install Lamp
    • 2.2
      Install phpMyAdmin
  • 3
    Configuration File Path

    • 3.1
      Common commands
    • 3.2
      Configure Apache

      • 3.2.1
        Apache module
    • 3.3
      Configure PhP5
    • 3.4
      Configure MySQL

      • 3.4.1
        MySQL Common commands
      • 3.4.2
        Configuration file (new user, do not touch without special requirements)
    • 3.5
      Configure phpMyAdmin)

      • 3.5.1
        Lamp has been configured.
  • 4
    Test phpinfo (). (select the phpinfo as needed. Do not do it)
  • 5
    Performance Optimization (you can choose one or more based on your needs)

    • 5.1
      Install Zend Optimizer
    • 5.2
      Security Protection xcache
    • 5.3
      Install eaccelerator
  • 6
    Others

    • 6.1
      PDO Installation
  • 7
    Troubleshooting

    • 7.1
      The PHP file cannot be parsed. the browser prompts you to download the PHP file to be opened.
  • 8
    Virtual Host
  • 9
    Shield thunder
  • 10
    Reference

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 

Install

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 Server
Then confirm.

In the main windowClick the green check box
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

3. Install with tasksel

sudo tasksel

Select lamp and click OK. (Be careful not to modify other options. Otherwise, the service will be installed or deleted !)

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

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:

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

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

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

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

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<Directory /usr/share/phpmyadmin>

Changed:

Alias /phpmyadmin /var/www/phpmyadmin<Directory /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
<?php phpinfo(); ?>

Open http: // localhost/info. php
.

Apache phpinfo page

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. For more information, 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

Security Protection 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.

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    

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

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

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/)$  [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.