Home > Backend Development > PHP Tutorial > Detailed steps to install and configure LAMP environment in CentOS6.4_PHP tutorial

Detailed steps to install and configure LAMP environment in CentOS6.4_PHP tutorial

WBOY
Release: 2016-07-13 10:35:34
Original
806 people have browsed it

This article introduces in detail the process of installing and configuring the LAMP service in the CentOS6.4 system, that is, installing Apache+PHP+Mysql. It refers to the settings of online experts. Other Linux distribution systems can refer to it~

Some of the command operations in this article require root permissions. Enter the ‘’ command and then enter the password to switch the root identity.

Settings file allows port 80 and port 3306. Because port 80 is the port used by the http protocol, if the firewall blocks port 80, the website cannot be accessed from the outside even after it is configured. Port 3306 is the default port of the MySql database. Open the iptables file using VIM and add rules:

<span 1</span> <span 打开iptables文件进行修改
</span><span 2</span> vim /etc/sysconfig/<span iptables
</span><span 3</span> 
<span 4</span> <span 加入下列两行
</span><span 5</span> -A INPUT -p tcp -m state --state NEW -m tcp --dport <span 80</span> -<span j ACCEPT
</span><span 6</span> -A INPUT -p tcp -m state --state NEW -m tcp --dport <span 3306</span> -j ACCEPT
Copy after login

After adding, the file should be as shown below. If the file has been modified before, it may be slightly different from the author’s picture:

Detailed steps to install and configure LAMP environment in CentOS6.4_PHP tutorial

 

2. Close SELINUX

( provided in the 2.6 version of Linux )system. Of the security modules currently available, SELinux is the most comprehensive, and the most well-tested. Basically, load balancing equipment is used for traffic distribution, and only a few ports are opened to the outside world. Therefore, in terms of comprehensive security and complexity, SELinux is not cost-effective. Modify the file to turn off SELinux, as shown below:

<span 1</span> vim /etc/selinux/<span config
</span><span 2</span> 
<span 3</span> <span 注释掉如下两行,在行首添加#注释。
</span><span 4</span> SELINUX=<span enforcing
</span><span 5</span> SELINUXTYPE=<span targeted
</span><span 6</span> 
<span 7</span> <span 在后面增加:
</span><span 8</span> SELINUX=disabled
Copy after login

Detailed steps to install and configure LAMP environment in CentOS6.4_PHP tutorial’ Restart the system.

<span  1</span> <span 通过yum软件包管理器安装MySql,管理器会自动安装依赖项,遇到询问直接输入y确认,直到显示&ldquo;Complete!&rdquo;完成。
</span><span  2</span> <span yum</span> <span install</span> mysql mysql-<span server
</span><span  3</span> 
<span  4</span> <span 启动MySql
</span><span  5</span> /etc/init.d/<span mysqld start
</span><span  6</span> 
<span  7</span> <span 设置MySql服务为开机启动
</span><span  8</span> <span chkconfig mysqld on
</span><span  9</span> 
<span 10</span> <span 复制MySql默认配置文件,直接覆盖/etc/my.cnf
</span><span 11</span> <span cp</span> /usr/share/mysql/my-medium.cnf /etc/my.cnf
Copy after login

MySql settings:

<span <span 输入如下命令后需要连续输入两次密码确认,有询问输入Y同意即可,成功后显示</span></span><span Thanks for using MySQL!。</span>
Copy after login
<span mysql_secure_installation</span>
Copy after login

After successful setting, you need to restart the MySql service:

<span 1</span> /etc/init.d/<span mysqld stop
</span><span 2</span> /etc/init.d/mysqld start
Copy after login

2. Installation and configuration of Apache service

 

<span  1</span> <span 安装httpd
</span><span  2</span> <span yum</span> <span install</span><span  httpd
</span><span  3</span> 
<span  4</span> <span 启动Apache服务
</span><span  5</span> /etc/init.d/<span httpd start
</span><span  6</span> 
<span  7</span> <span 编辑apache设置
</span><span  8</span> vim /etc/httpd/conf/<span httpd.conf
</span><span  9</span> <span 查找 <span #ServerName www.example.com:80</span></span>
<span 10</span> <span 修改成 <span ServerName</span> <span www.XXXX.com:80</span></span> 
<span 11</span> <span 其中的&ldquo;www.XXXX.com&rdquo;自己的域名,没有可设置为localhost,如图
</span><span 12</span> 
<span 13</span> <span 设置Apache服务开机启动
</span><span 14</span> <span chkconfig httpd on
</span><span 15</span> 
<span 16</span> <span 重启Apache服务
</span><span 17</span> /etc/init.d/httpd restart
Copy after login

Detailed steps to install and configure LAMP environment in CentOS6.4_PHP tutorial3. Install PHP

 

<span 遇到询问直接输y确认
</span><span yum</span> <span install</span> php
Copy after login

Install PHP plug-in:

<span 插件包括MySql支持等,遇到询问一如既往的y确认~~
</span><span yum</span> <span install</span> php-mysql php-gd libjpeg* php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-bcmath php-mhash libmcrypt
Copy after login

Don’t forget to restart Apache and MySql after the installation is complete:

/etc/init.d/<span mysqld restart
</span>/etc/init.d/httpd restart
Copy after login
Copy after login

 

The installation of this software is over. Next, configure and test.

<span  1</span> <span 编辑文件Apache设置文件
</span><span  2</span> <span vi</span> /etc/httpd/conf/<span httpd.conf
</span><span  3</span> 
<span  4</span> <span <span 44行:</span> 修改 <span ServerTokens OS</span>  为 <span ServerTokens Prod
</span></span><span  5</span> <span 防止错误页显示操作系统名字
</span><span  6</span> 
<span  7</span> <span <span 76行:</span> 修改 <span KeepAlive Off</span> 为 <span KeepAlive On
</span></span><span  8</span> <span 允许程序性联机
</span><span  9</span> 
<span 10</span> <span 83行:</span> 修改 <span MaxKeepAliveRequests 100</span> 为 <span MaxKeepAliveRequests 1000</span>
<span 11</span> <span 增加同时连接数
</span><span 12</span> 
<span 13</span> <span <span 331行:</span> 修改 <span Options Indexes FollowSymLinks</span> 为 <span Options Includes ExecCGI FollowSymLinks
</span></span><span 14</span> <span 允许服务器执行CGI及SSI,防止列出目录
</span><span 15</span> 
<span 16</span> <span <span 338行:</span> 修改 <span AllowOverride None</span>  为 <span AllowOverride All
</span></span><span 17</span> <span 允许.htaccess
</span><span 18</span> 
<span 19</span> <span <span 402行:</span> 修改 <span DirectoryIndex index.html index.html.var</span>  为 <span DirectoryIndex index.php Default.php index.html index.htm Default.html Default.htm
</span></span><span 20</span> <span 添加php默认文档
</span><span 21</span> 
<span 22</span> <span <span 536行:</span>  修改 <span ServerSignature On</span> 为 ServerSignature Off 
</span><span 23</span> <span 防止错误页显示Apache版本
</span><span 24</span> 
<span 25</span> <span <span 554行:</span> 修改 <span Options Indexes MultiViews FollowSymLinks</span>  为 <span Options MultiViews FollowSymLinks
</span></span><span 26</span> <span 不显示树状目录结构
</span><span 27</span> 
<span 28</span> <span 759行:</span> 根据需要设置为 <span AddDefaultCharset UTF-8</span><span  或者 <span AddDefaultCharset GB2312
</span></span><span 29</span> <span 笔者大多数时候都在使用UTF-8编码,所以不进行修改
</span><span 30</span> 
<span 31</span> <span 796行:</span> 修改 <span #AddHandler cgi-script .cgi</span> 为 <span AddHandler cgi-script .cgi .pl
</span><span 32</span> <span 允许扩展名为.pl的CGI脚本运行</span>
Copy after login

After the modification is completed, save, exit, restart Apache, and delete the test webpage:

/etc/init.d/<span httpd restart

<span 删除测试网页
</span></span><span rm</span> -f /etc/httpd/conf.d/welcome.conf /var/www/error/noindex.html 
Copy after login

<span  1</span> <span 编辑php设置文件
</span><span  2</span> vim /etc/<span php.ini
</span><span  3</span> 
<span  4</span> <span 946行:</span> 修改 <span ;date.timezone = PRC</span> 为 <span date.timezone =</span><span <span  PRC</span>  <span (去掉分号)
</span></span><span  5</span> 
<span  6</span> <span 386行:</span> 修改 <span disable_functions =</span> 为 <span 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
</span><span  7</span> <span 设置PHP的禁用函数,若程序中需要使用的函数可以删除掉。
</span><span  8</span> 
<span  9</span> <span 432行:</span> 设置 <span expose_php = Off
</span><span 10</span> <span 禁止显示php版本的信息
</span><span 11</span> 
<span 12</span> <span 745行:</span> 设置 <span magic_quotes_gpc = On
</span><span 13</span> <span 打开magic_quotes_gpc,用于防止SQL注入
</span><span 14</span> 
<span 15</span> <span 229行:</span> 设置 <span short_open_tag = ON
</span><span 16</span> <span 支持php短标签
</span><span 17</span> 
<span 18</span> <span 380行:</span> 设置 <span open_basedir = .:/tmp/</span> 
<span 19</span> <span 设置允许访问的目录和/tmp/目录,防止php木马跨站</span>
Copy after login

Restart the service after saving the modification:

/etc/init.d/<span mysqld restart
</span>/etc/init.d/httpd restart
Copy after login
Copy after login

 Enter "

<span 1</span> <?<span php
</span><span 2</span>     <span phpinfo</span><span ();
</span><span 3</span> ?>
Copy after login

After saving and exiting, enter localhost in the browser to view the php information:

Detailed steps to install and configure LAMP environment in CentOS6.4_PHP tutorial apache.apache -R /var/www/html

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/743819.htmlTechArticleThis article details the process of installing and configuring the LAMP service in the CentOS6.4 system, that is, installing Apache+ PHP+Mysql, refer to the settings of online masters. Other Linux distribution systems can refer to...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template