Linux服务配置 – LAMP服务搭建
title: LAMP安装和配置
categories:
- Linux
- Services
- LAMP
tags: - Linux
- Services
- LAMP
abbrlink: 1609
date: 2020-04-28 19:30:31
src: 1.jpg
1. Apache安装
```bash
yum -y install httpd
vi /etc/httpd/conf/httpd.conf
# line 86: change to admin's email address
ServerAdmin root@locahost
# line 95: change to your server's name
ServerName ops.yeehnn.com:80
# line 151: change
AllowOverride All
# line 164: add file name that it can access only with directory's name
DirectoryIndex index.html index.cgi index.php
# add follows to the end
# server's response header
ServerTokens Prod
# keepalive is ON 保持http连接
KeepAlive On
firewall-cmd --add-service=http --permanent
firewall-cmd --reload
```
#### 以下暂时跳过
```bash
vi /etc/httpd/conf.d/vhost.conf
# create new
# for original domain
<VirtualHost *:80>
DocumentRoot /var/www/html
ServerName ops.yeehnn.com
</VirtualHost>
# for virtual domain
<VirtualHost *:80>
DocumentRoot /home/cent/public_html
ServerName vhost.yeehnn.com
ServerAdmin webmaster@virtual.host
ErrorLog logs/virtual.host-error_log
CustomLog logs/virtual.host-access_log combined
</VirtualHost>
systemctl restart httpd
```
2. MariaDB安装
```bash
yum -y install mariadb-server
vi /etc/my.cnf
# add follows within [mysqld] section
[mysqld]
character-set-server=utf8
systemctl start mariadb
systemctl enable mariadb
```
```bash
mysql_secure_installation
mysql -u root -p
select user,host,password from mysql.user;
show databases;
grant all on *.* to user@'localhost' identified by 'UserPassword';
firewall-cmd --add-service=mysql --permanent
firewall-cmd --reload
```
3. PHP安装
```bash
yum -y install php php-mbstring php-pear
vi /etc/php.ini
# line 878: uncomment and add your timezone
date.timezone = "Asia/Shanghai"
systemctl restart httpd
```
```bash
vi /var/www/html/phpinfo.php
<?php
phpinfo();
?>
```
```bash
vi ~/public_html/virtual.php
<html>
<body>
<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">
Virtual Host Test Page
</div>
</body>
</html>
```
#### 扩展
```bash
yum -y install php-fpm
vi /etc/httpd/conf.d/php.conf
# line 5: change like follows
<FilesMatch \.php$>
# SetHandler application/x-httpd-php
SetHandler "proxy:fcgi://127.0.0.1:9000"
</FilesMatch>
systemctl start php-fpm
systemctl enable php-fpm
systemctl restart httpd
# http://ops.yeehnn.com/phpinfo.php
```