LAMP指的Linux操作系统)、ApacheHTTP 服务器,MySQL(有时也指MariaDB,数据库软件) 和PHP(有时也是指PerlPython) 的第一个字母,一般用来建立web应用平台。

LNMP中的N指的是Nginx



配置防火墙,开启80端口(web)、3306端口(mysql)

vi /etc/sysconfig/iptables

-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT

-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT


#wq 保存后重启防火墙

#service iptables restart


关闭selinux

vi /etc/selinux/config

SELINUX=disabled


保存退出

setenforce 0     #使配置立即生效

一、安装Apache

yum install httpd -y

service httpd start      #启动http服务

启动服务时会有提示信息:

Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName

找到  #ServerName www.example.com:80
      修改为 你自己的域名,如果没有域名,可以设置为localhost

chkconfig httpd on    #开机自启动服务

浏览器输入本机ip,查看apache安装成功。

配置apache

vi /etc/httpd/conf/httpd.conf

ServerTokens Prod              出现错误页的时候不显示服务器的操作系统

ServerSignature Off        在错误页中不显示apache的版本

Options Indexes ExecCGI FollowSymLinks        允许服务器执行cgi及ssl,禁止列出目录

AddHandler cgi-script .cgi .pl        允许扩展名为.pl的cgi脚本运行    

AllowOverride All        允许.htaccess    

AddDefaultCharset GB2312         修改GB2312为默认编码 

Options MultiViews FollowSymLinks         在浏览器上不显示树状目录结构 

DirectoryIndex index.html index.htm Default.html Default.htm

KeepAlive ON        允许程序联机 

MaxKeepAliveRequests 1000        修改同时连接数 


保存后重启 http

service httpd restart


二、安装mysql

yum install mysql mysql-server -y

servcie mysqld start

chkconfig mysqld on

mysql_secure_installation     #mysql安全设置,密码等等

三、安装php

yum install php -y

安装php组件,使php支持 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 -y

重启mysql和httpd服务

service mysqld restart

service httpd restart

配置php

vi /etc/php.ini 修改内容如下:

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 

#列出PHP可以禁用的函数,如果某些程序需要用到这个函数,可以删除,取消禁用。

expose_php = Off  #禁止显示php版本

short_open_tag = ON     #支持php短标签

open_basedir =.:/tmp/     #设置表示允许访问当前目录(即PHP脚本文件所在之目录)和/tmp/目录,可以防止php木马跨站,如果改了之后安装程序有问题(例如:织梦内容管理系统),可以注销此行,或者直接写上程序的目录


保存退出,重启mysql,http服务

service httpd restart

service mysqld restart


测试

cd /var/www/html

vi index.php

<?

phpinfo();

?>


保存退出

浏览器输入ip地址查看 


注意:apache默认的程序目录是/var/www/html


权限设置:chown apache.apache -R /var/www/html