Installation configuration lamp (linux+apache+mysql+php) under CentOS

Source: Internet
Author: User
Tags install php time zones safe mode what is lamp

A variety of knowledge about lamp, today is mainly about the installation under CentOS, the process of building a Web server. (This article is installed using the installation package)

First, Introduction

What is lamp     Lamp is a Web network application and development environment, is the abbreviation of Linux, Apache, MySQL, Php/perl, each letter represents a component, each component in itself is a very powerful component in the aspect it represents. The origin of the word lamp originated in the German magazine "C ' t Magazine", where Michael Kunze first set together these projects to create the acronym for Lamp in 1990. These components are not designed to be used together at the outset, but they are open source and readily available and free to use, which leads to the frequent use of these components. The compatibility of these components is also evolving, and in order to improve collaboration among the different components, some extension features have been created, and the application situation together becomes very popular, making it the most prevalent Web application infrastructure.

Lamp's components     Platform consists of four components in a hierarchical structure, Each layer provides a key part of the entire architecture:    linux : linux  is at the bottom, providing the operating system. Its flexibility and customizable features mean it can produce a highly customizable platform for other components to run on. Other components run on linux , but not necessarily limited to Linux, or run on Microsoft Windows, Mac OS X, or   UNIX.    apache : Apache is located on the second tier, which is a Web services platform that provides a mechanism for users to get web pages. Apache is a powerful, stable, mission-critical Web server that uses it as a Web server for more than 50% of sites on the Internet.    mysql : MySQL is the most popular open source relational database management system, which is the data storage side of lamp. In a WEB application, all account information, product information, customer information, business data, and other types of information are stored in the database and can be easily queried through the SQL language.    php/perl : Perl is a flexible language, especially when it comes to working with text features, which makes it easy for Perl to handle the data provided through the CGI interface, with the flexibility to use text files and simple databases to support dynamic features. PHP is a widely used, open-source, multi-purpose scripting language that can be embedded in   HTML, especially for Web development. You can use PHP to write dynamic content that accesses the data in the MySQL database and some of the features that Linux provides.

Second, the system environment

System platform: CentOS6.3

Apache Version: httpd-2.2.9

Mysql version: mysql-5.0.41

PHP Version: php-5.2.6

There are two ways to install software under CentOS, the first is to install the software automatically with the Yum command, the installed software has a fixed location and a fixed directory, the second is to download the source installation package, manually unzip, configure, compile and install, in the process of installation can choose their own installation of directories and paths. Here, I choose the installation method is the first, more convenient, although the flexibility of the lack of, but for the pilot phase is enough.

Third, installation

(1): Configure firewall (By default, ports 80 and 3306 are denied access and are configured on the firewall):

1.vi/etc/sysconfig/iptables (Add the following two sentences on the previous line of "COMMIT")

2.-a input-m State--state new-m tcp-p TCP--dport 80-j ACCEPT (allow port 80 via firewall)

3.-a input-m State--state new-m tcp-p TCP--dport 3306-j ACCEPT (Allow port 3306 via firewall)

Then reboot the firewall to make the configuration effective:

1./etc/init.d/iptables restart

(2): Installation Apache

Install Apache using the following command:

1.yum Install httpd

If the statement shown below shows that Apache is already installed, you do not need to reinstall:

After the installation is complete, restart apache:/etc/init.d/httpd restart

The Apache is then set to boot: Chkconfig httpd on. (This step makes it unnecessary for the server to manually start the httpd service at each reboot)

To view the startup status of the HTTPD service, you can use the command: Chkconfig--list httpd (Displays the httpd start state at each level)

(3): Installation MySQL

1. Install MySQL using the following command:

1.yum install MySQL Mysql-server

Similarly, if the prompt has been installed, it means that the system installed MySQL, you can skip this step, otherwise, the system will automatically install MySQL next.

After the installation is complete, start the Mysql:/etc/init.d/mysql start

Set MySQL to boot: chkconfig mysqld on
Finally, copy the configuration file: Cp/usr/share/mysql/my-medium.cnf/etc/my.cnf (there is a my.cnf file in/etc, just overwrite it)

2. Use the following command to set the password for the root account

1.mysql_secure_installation

Enter the password 2 times as prompted, and the setting is successful. Note that during the setup process, you will be prompted to delete whether the user is anonymous, whether to deny root remote access, whether to delete the test database, etc., which need to be selected according to their actual situation. Last appeared: Thanks for using mysql!, set password succeeded.

Restart Mysql:/etc/init.d/mysqld restart

(4) Installation PHP

1. Install PHP using the following command:

1.yum Install PHP

Follow the prompts to install on the line. Restart APACHE:/ETC/INIT.D/HTTPD after installation restart
2, install PHP components, is PHP support MySQL

You can use the command: Yum search php to view the components of PHP and select the required modules for installation:

(PHP component list http://www.php100.com/html/itnews/PHPxinwen/2013/0305/12149.html)

Yum install php-mysqlphp-gd libjpeg* php-imap php-ldap php-odbc php-pear php-xml php-xmlrpcphp-mbstring php-mcrypt PHP-BC Math Php-mhash Libmcrypt

After installation, restart APACHE:/ETC/INIT.D/HTTPD restart

Restart Mysql:/etc/init.d/mysqld restart

At this point, the amp in lamp has been installed, but the Web server is not accessible at this time, because the server is accessed and the Apache and PHP are configured accordingly.

First step: Configure Apache

Modify the Apache configuration file: vi/etc/httpd/conf/httpd.conf, and look for the following line in the file, make changes (find can enter "/to find characters" in the general mode of VI to find):

Servertokens OS modified to: Servertokens Prod (the name of the server operating system is not displayed when the error page appears)

Serversignature on modified to: Serversignature OFF (the Apache version is not shown in the error page)

Options Indexes followsymlinks modified to: Options includes execcgi followsymlinks (Allow server to execute CGI and SSI, prohibit listing of directories)

#AddHandler cgi-script. CGI modified to: AddHandler cgi-script. cgi. pl (Allow extension Run for. PL CGI Scripts)

AllowOverride None modified to: allowoverride all (Allow. htaccess)

Adddefaultcharset UTF-8 modified to: Adddefaultcharset GB2312 (add GB2312 as default encoding)

Options Indexes multiviews followsymlinks modified to Options MultiViews FollowSymLinks (does not display the tree structure on the browser)

DirectoryIndex index.html Index.html.var modified to: DirectoryIndex index.html index.htm default.html default.htm in dex.php default.php Index.html.var (set default home file, add index.php)

KeepAlive Off modified to: KeepAlive on (allow program online)

Maxkeepaliverequests 100 modified to: Maxkeepaliverequests 1000 (Increased number of simultaneous connections)

Save the configuration after you modify it and restart apache:/etc/init.d/httpd restart

We recommend that you delete the default test page: Rm-f/etc/httpd/conf.d/welcome.conf/var/www/error/noindex.html

Step Two: Configure PHP

To modify a PHP configuration file: Vi/etc/php.ini, the following lines that need to be modified can be found through the Find command of VI:

Date.timezone = PRC #把前面的分号去掉, changed to Date.timezone = PRC

(Prc,people's Republic of China, PRC, that is, dates using Chinese time zones)

If you want to keep your server secure, add this function to disable_functions or open it in safe mode.

disable_functions =                               Passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status, Ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server, Escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space, Posix_ctermid,posix_get_last_error,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_ Getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix_getppid,posix_getpwnam, Posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid, Posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname, Posix_uname

#列出PHP可以禁用的函数, if some programs need to use this function, you can delete, cancel disable.

expose_php = Off #禁止显示php版本的信息

Display_errors = OFF #关闭错误提示

Register_globals = OFF #关闭注册全局变量

MAGIC_QUOTES_GPC = on #打开magic_quotes_gpc来防止SQL注入

Log_errors = on #记录错误日志

Error_log =/var/log/php/error_log.log #设置错误日志存放目录, the file must allow the Apache user's and group to have write permissions (note that before modifying, the file is created first/var/log/php/error_ Log.log, and then modifies its properties so that it belongs to Apache users and user groups. Chown Apache/var/log/php/error_log.log and Chgrp Apache/var/log/php/error_log.log)

Open_basedir =.:/ tmp/#设置表示允许访问当前目录 (i.e. the directory where the php script files are located) and the/tmp/directory, which prevents the PHP Trojan from crossing the station

After installation and configuration, the Web server is basically set up and can be accessed.

Test article

Under directory/var/www/html: cd/var/www/html

Create PHP File: VI index.php

<?php

Phpinfo ();

?>

Then, when you enter the native address in the browser, you can access the index.php Web page file you just created.

Note: Apache's default program directory is:/var/www/html, Web page files can be accessed here. Need to ensure that this directory belongs to the user Apache and user group Apache.

The MySQL database directory is:/var/lib/mysql

Write here, lamp installed configuration, the browser just enter the server's IP address or domain name, you can access to the Server Web page files.

Installation configuration lamp (linux+apache+mysql+php) under CentOS

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.