Lamp Environment Construction

Source: Internet
Author: User

Excerpt from:

Enterprise website construction is bound to be inseparable from the server operation, a stable and efficient server environment is to ensure the normal operation of the site important premise. This article will explain in detail how the Linux system to build a high-efficiency lamp service environment, and in the lamp environment to build up the company's own website.

A brief overview of the main points of this article: (Operating system using CentOS 6.5 x64)

1. Install lamp service environment respectively;

2. Use lamp to install the package environment with one click;

3. Initially build a website in the lamp environment;

First, Install lamp service environment separately

Preparatory work:

1, configure the firewall, open 80 ports, 3306 ports
-A input-m state–state new-m tcp-p tcp–dport 80-j ACCEPT #允许80端口通过防火墙
-A input-m state–state new-m tcp-p tcp–dport 3306-j ACCEPT #允许3306端口通过防火墙

Add the above to the below of the-a input-m state–state new-m tcp-p tcp–dport 22-j ACCEPT

/etc/init.d/iptables Restart #最后重启防火墙使配置生效

2. Turn off SELinux
#SELINUX =enforcing #注释掉
#SELINUXTYPE =targeted #注释掉
Selinux=disabled #增加
: Wq #保存, close
Shutdown-r now #重启系统


1. Installing Apache

Uninstall your own Httpd:yum remove httpd
Yum Install httpd #根据提示, enter Y to install successfully
/ETC/INIT.D/HTTPD Start #启动Apache

Note: Apache will prompt for errors after booting:
Starting httpd:httpd:Could not reliably determine theserver ' s fully qualif domain name, using:: 1 for ServerName
Vi/etc/httpd/conf/httpd.conf #编辑
Found #ServerName
Modified to ServerName #这里设置为你自己的域名, if no domain name, can be set to localhost
: wq! #保存退出
Chkconfig httpd on #设为开机启动
/ETC/INIT.D/HTTPD Restart #重启Apache

2. Install MySQL

Uninstall your own MySQL first:

Yum remove MySQL mysql-server mysql-libs compat-mysql51


Yum install MySQL mysql-server #询问是否要安装, enter y for automatic installation until installation is complete
/etc/init.d/mysqld Start #启动MySQL
Chkconfig mysqld on #设为开机启动
CP/USR/SHARE/MYSQL/MY-MEDIUM.CNF/ETC/MY.CNF #拷贝配置文件 (Note: If the/etc directory has a my.cnf under the default, you can directly overwrite it)

To set a password for the root account:
Enter, follow the prompts for Y
Enter Password 2 times, enter
Enter Y as prompted
Last appearance: Thanks for using mysql!
MySQL password setup is complete, restart MySQL:
/etc/init.d/mysqld Restart #重启
/etc/init.d/mysqld Stop #停止
/etc/init.d/mysqld Start #启动

3, Installation PHP5
Yum Install PHP
Enter Y as prompted until the installation is complete

Install PHP components to enable PHP5 to support MySQL
Yum install php-mysql php-gd libjpeg* php-imap php-ldap php-odbc php-pearphp-xml php-xmlrpc php-mbstring php-mcrypt PHP-BC Math Php-mhash Libmcrypt
Select the above installation package here for installation
Enter Y return as prompted
/etc/init.d/mysqld Restart #重启MySql
/ETC/INIT.D/HTTPD Restart #重启Apche

Related configuration:

1. Apache Configuration
Vi/etc/httpd/conf/httpd.conf #编辑文件
Servertokens OS modified to: Servertokensprod in 44 rows (does not display the name of the server operating system when the error page appears)
Serversignature on 536 line modified to: Serversignatureoff (does not show Apache version in error page)
Options Indexes FollowSymLinks in 331 rows modified to: Options i n c l u d es e x e ccgi followsymlinks (Allow server to execute CGI and SSI, prohibit list of directories)
#AddHandler Cgi-script. CGI is modified in line 796 to: AddHandler cgi-script. cgi. PL (allows CGI scripts with extension. pl to run)
AllowOverride None in line 338 modified to: Allowoverrideall (Allow. htaccess)
Adddefaultcharset UTF-8 in 759 rows modified to: Adddefaultcharset GB2312 (add GB2312 as default encoding)
Options Indexes multiviews followsymlinks in 554 rows modified to Options multiviews followsymlinks (does not display the tree structure on the browser)
DirectoryIndex index.html Index.html.var in 402 line modified to: DirectoryIndex index.html index.htm default.html default.htm

index.php default.php Index.html.var (set default home file, add index.php)
KeepAlive Off in line 76 modified to: Keepaliveon (allow program online)
Maxkeepaliverequests 100 in 83 rows modified to: Maxkeepaliverequests 1000 (increase number of simultaneous connections)
: wq! #保存退出
/ETC/INIT.D/HTTPD Restart #重启
Rm-f/etc/httpd/conf.d/welcome.conf/var/www/error/noindex.html #删除默认测试页

2. PHP Configuration
Vi/etc/php.ini #编辑
Date.timezone = PRC #在946行 Remove the preceding semicolon and change to Date.timezone = PRC

Disable_functions = p A s s t h r u,e x e c,s y s t e m,chroot,scandir,chgrp,chown,shell_e x e C, p r o C _ o p e n,proc_g Et_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,pope p a s S t h R u,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

#在386行 lists the functions that PHP can disable, and if some programs need to use this function, you can delete and cancel the disabled.
expose_php = Off #在432行 Suppress the PHP version information
MAGIC_QUOTES_GPC = on #在745行 open MAGIC_QUOTES_GPC to prevent SQL injection
Short_open_tag = on #在229行支持php短标签
Open_basedir =.:/ tmp/#在380行 settings to allow access to the current directory (that is, the php script file directory) and/tmp/directory, you can prevent the PHP Trojan cross-site, if you change the installation program after the problem (for example: Dream Content Management System), you can log off this line, or directly write the program directory/data/
: wq! #保存退出
/etc/init.d/mysqld Restart #重启MySql
/ETC/INIT.D/HTTPD Restart #重启Apche

VI index.php #输入下面内容
Phpinfo ();
: wq! #保存退出
In the client browser enter the server IP address, you can see the configuration information as shown in the relevant!


Follow-up installation of Pdo_mysql expansion module, only need: Yum install Php-mysql

Manual Installation Error (Configure:error:mysql_query missing!?) )

Second, the use of lamp one-click installation package to build the environment

Many friends may think that installing Apache, MYDQL, PHP is cumbersome and requires manual configuration. So the next small series to lead you to understand how to use lamp one-click installation package to build a service environment.

Deploying the Lnmp/lamp/lnmpa one-click Package

1. Download the script to extract and perform the installation


Tar xzf lnmp-full.tar.gz



2, the installation process of the project selection

Because the features of this script are not unattended from the beginning, we need to choose various versions according to our environment, so the selection process is more complicated, we have to see clearly, in this process we install the lamp environment.

(1), upgrade system and port, Web server installation settings

The beginning of the process we see, the official proposal does not update the system, then we do not update. We can directly modify the root port in the process of installing the script directly, this is very good, or we need to modify the port when handling the server security matters, do not use the default 22. Web server installation, because we want to install lamp environment, so nginx does not install, Apache installs its own desired version, I install here 2.4.

(2), database version and PHP version select Install

Here we also choose to install the database and PHP version.

(3) Installation of other related server components

We according to our own site environment requirements environment, configuration needs components, small pieces of personal advice is if you need to use the installation, there is no need to do not install.

Third, some deployment work after the installation is completed

After setting up, then is automatic unattended installation, according to the speed of the system need to execute 20-30 minutes, in short we wait, waiting for the interface to see the installation is complete, we can enter the Y to restart the server, and then detect whether the installation integrity.

We in the server configuration environment still need to do a few work, the most important thing is to delete the default installation of the home page, in the Home/wwwroot/default home page, and the need to modify the directory path phpMyAdmin, the reason we all understand, do not understand also to do.

Third, in the lamp environment to initially build a website

Here we take the mainstream cicada knowledge system for example, directly in just a button installed in the lamp environment to build the site.

Cicada know Enterprise Building Station system download: WWW.CHANZHI.ORG/DOWNLOAD/CHANZHI5.2-126.HTML/?U=XCJ

Cicada Knowledge System User's Manual: HTTP://WWW.CHANZHI.ORG/BOOK/CHANZHIEPS.HTML/?U=XCJ

After the download decompression, the s y S t e M folder is moved to the WWW folder, this www folder is what I will need to upload the site files.

Lamp Environment Add Site:

Because the one-button package is different from the Web panel, we need to add the site command, at least better than the manual deployment, use the following command.



We will upload the file under WWW to the root directory of the website, visit the website address to install.

Start the Setup program

Access to your domain name http://domain/install.php. If you install the Cicada in the level two directory, you also need to add a level two path.

Check module and directory permissions

Note: If the module or directory check does not pass, follow the instructions given by the system to resolve the issue.

Configuration Database

Note: If you have previously installed a cicada-aware system, you can select the "Empty existing data" button to reinstall it.

Save configuration file

Note: The system will automatically attempt to save the configuration file. If the problem is due to permissions, follow the prompts to copy the contents of the text box, manually saved to the config/my.php file.

set up an administrator account

Login Background

At this point, we have successfully built the lamp service environment, and built our website in the lamp environment. How we have other questions, welcome comments and discussions, we communicate together and progress together.

Lamp Environment Construction

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