CentOS 6.6 installation and configuration of LAMP server (Apache+PHP5+MySQL)

1. Configure the firewall, open port 80 and port 3306

?
1
2
3
vi /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT

:wq! #Save and exit

The firewall configuration file after adding the rules is shown in the following figure:

/etc/init.d/iptables restart#Restart the firewall to make the configuration take effect

2. Close SELINUX

?
1
2
3
4
vi /etc/selinux/config
#SELINUX=enforcing #注释掉
#SELINUXTYPE=targeted #注释掉
SELINUX=disabled #增加

:wq! #Save and exit

The SELINUX configuration file is shown in the following figure:

3. Add a third-party yum source

The default yum source software version of CentOS is too low. To install the latest version of LAMP, a third-party yum source is used here.

wget http://www.atomicorp.com/installers/atomic#download

First install wget command using default yum source

yum install wget

sh ./atomic #Install

yum clean all #Clear the current yum cache
yum makecache #Cache the package information in the
yum source yum repolist #List the packages available in the yum source

Installation articles:

1. Install Apache

yum install httpd #According to the prompt, enter Y to install to successfully install

/etc/init.d/httpd start #Start Apache

Note: After Apache starts, it will prompt an error:

httpd:httpd: Could not reliably determine the server's fully qualif domain name, using ::1 for ServerName

Solution:

vi /etc/httpd/conf/httpd.conf #Edit
ServerName www.example.com:80 #Remove the previous comment

:wq! #Save and exit

chkconfig httpd on #Set to boot

/etc/init.d/httpd restart #Restart Apache

2. Install MySQL

1. Install MySQL

yum install mysql mysql-server #Ask ​​if you want to install, enter Y to install automatically until the installation is complete

/etc/init.d/mysqld start #Start MySQL
chkconfig mysqld on #Set to boot
cp /usr/share/mysql/my-medium.cnf /etc/my.cnf #Copy the configuration file (note: if the /etc directory There is a my.cnf by default below, which can be directly overwritten)

2. Set a password for the root account

mysql_secure_installation

Enter, enter Y according to the prompt

Enter the password twice and press Enter

Enter Y all the way according to the prompt

Finally appeared: Thanks for using MySQL!

MySql password setting is complete, restart MySQL:

/etc/init.d/mysqld restart #Restart
/etc/init.d/mysqld stop
#Stop /etc/init.d/mysqld start #Start

3. Install PHP

1. Install PHP

yum install php #Enter Y according to the prompt until the installation is complete

2. Install PHP components to enable PHP to support MySQL

yum install 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

Here select the above installation package to install

Enter Y according to the prompt and press Enter

/etc/init.d/mysqld restart#Restart MySql
/etc/init.d/httpd restart#Restart Apache

Configuration articles

1. Apache configuration

?
1
2
3
4
5
6
7
8
9
10
11
12
vi /etc/httpd/conf/httpd.conf #编辑文件
ServerTokens OS  在44行 修改为:ServerTokens Prod (在出现错误页的时候不显示服务器操作系统的名称)
ServerSignature On  在536行 修改为:ServerSignature Off (在错误页中不显示Apache的版本)
Options Indexes FollowSymLinks  在331行 修改为:Options Includes ExecCGI FollowSymLinks(允许服务器执行CGI及SSI,禁止列出目录)
#AddHandler cgi-script .cgi 在796行 修改为:AddHandler cgi-script .cgi .pl (允许扩展名为.pl的CGI脚本运行)
AllowOverride None  在338行 修改为:AllowOverride All (允许.htaccess)
AddDefaultCharset UTF-8 在759行 修改为:AddDefaultCharset GB2312 (添加GB2312为默认编码)
Options Indexes MultiViews FollowSymLinks 在554行 修改为 Options MultiViews FollowSymLinks(不在浏览器上显示树状目录结构)
DirectoryIndex index.html index.html.var 在402行 修改为:DirectoryIndex index.html index.htm Default.html Default.htm
index.php Default.php index.html.var (设置默认首页文件,增加index.php)
KeepAlive Off 在76行 修改为:KeepAlive On (允许程序性联机)
MaxKeepAliveRequests 100 在83行 修改为:MaxKeepAliveRequests 1000 (增加同时连接数)

:wq! #Save and exit

/etc/init.d/httpd restart # restart

rm -f /etc/httpd/conf.d/welcome.conf /var/www/error/noindex.html#delete default test page

Second, php configuration

?
1
2
3
4
5
6
7
8
vi /etc/php.ini #编辑
date.timezone = PRC #在946行 把前面的分号去掉,改为date.timezone = PRC
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
#在386行 列出PHP可以禁用的函数,如果某些程序需要用到这个函数,可以删除,取消禁用。
expose_php = Off #在432行 禁止显示php版本的信息
magic_quotes_gpc = On #在745行 打开magic_quotes_gpc来防止SQL注入
short_open_tag = ON #在229行支持php短标签
open_basedir = .:/tmp/ #在380行 设置表示允许访问当前目录(即PHP脚本文件所在之目录)和/tmp/目录,可以防止php木马跨站,如果改了之后安装程序有问题(例如:织梦内容管理系统),可以注销此行,或者直接写上程序的目录/data/www.osyunwei.com/:/tmp/

:wq! #Save and exit

/etc/init.d/mysqld restart #Restart MySql
/etc/init.d/httpd restart#Restart Apache


Test article

cd / var / www / html

vi index.php #Enter the following

?
1
2
3
<?php
phpinfo();
?>

:wq! #Save and exit

Enter the server IP address in the client browser, and you can see the related configuration information as shown in the figure below!

Note: The default program directory of apache is /var/www/html

Permission settings: chown apache.apache -R /var/www/html

So far, the CentOS 6.6 installation and configuration of the LAMP server (Apache+PHP5+MySQL) tutorial is complete!

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326065513&siteId=291194637