LAMP代表的就是:Linux系统下Apache+MySQL/Mariadb+PHP这种网站服务器架构。
1. 安装apache
yum install -y httpd httpd-devel
2. 编辑apache配置文件
vim /etc/httpd/conf/httpd.conf
95 ServerName 192.168.200.101:80
103 AllowOverride All (允许.htaccess)
164 DirectoryIndex index.html index.php
316 AddDefaultCharset UTF-8
ServerTokens Prod (在出现错误页的时候不显示服务器操作系统的名称)
ServerSignature Off (在错误页中不显示Apache的版本)
Options Includes ExecCGI FollowSymLinks(允许服务器执行CGI及SSI,禁止列出目录)
AddHandler cgi-script .cgi .pl (允许扩展名为.pl的CGI脚本运行)
Options MultiViews FollowSymLinks(不在浏览器上显示树状目录结构)
KeepAlive On (允许程序性联机)
MaxKeepAliveRequests 1000 (增加同时连接数)
httpd -t
systemctl restart httpd
systemctl enable httpd
ss -ntlu
3. 安装MariaDB
yum install -y mariadb mariadb-devel mariadb-server
cp /usr/share/mysql/my-medium.cnf /etc/my.cnf
cp:是否覆盖"/etc/my.cnf"? y
systemctl restart mariadb
systemctl enable mariadb
ss -ntlu | grep 3306
tcp LISTEN 0 50 *:3306 *:*
mysql_secure_installation
该命令会执行以下几个设置:
a)为root用户设置密码y
b)删除匿名账号y
c)取消root用户远程登录y
d)删除test库和对test库的访问权限y
e)刷新授权表使修改生效y
4. 安装PHP
yum install -y php php-common php-devel php-mysql php-cli php-mbstring php-pdo php-gd php-ldap php-odbc php-dba php-bcmath php-xml php-xmlrpc php-pear php-soap php-tidy php-mhash php-fpm php-pecl-memcache php-mhash php-mcrypt libmcrypt
5. 编辑PHP配置文件
vim /etc/php.ini
375 expose_php = Off #禁止显示php版本信息
692 default_charset = "UTF-8"
763 cgi.fix_pathinfo=1
878 date.timezone = Asia/Shanghai
1357 session.save_path = "/var/lib/php/session/"
1361 session.use_cookies = 1
magic_quotes_gpc = On #不对输入和输出数据库的字符串数据作addslashes()和stripslashes()的操作,数据也会正常显示
测试:
清空apache主目录
rm -rf /var/www/html/*
vim /var/www/html/index.php
<?php
echo "hello wprld";
phpinfo();
?>
chown -R apache:apache /var/www/html/ #设置目录所有者
chmod -R 755 /var/www/html/ #设置目录权限
systemctl restart httpd
测试数据库连接
vim /var/www/html/sql.php
<?php
$link=mysqli_connect("localhost","root","123456");
if(!$link)
{
echo "数据库连接失败";
}
else{
echo "数据库连接成功";
mysqli_close();
}
?>