Linux 系统中LAMP搭建与配置
起点
- 安装了linux系统的服务器
- 终端
防火墙设置
- 关闭firewall
systemctl stop firewalld.service
- 禁止firewall开机启动
systemctl disable firewalld.service
- 安装iptables防火墙
yum install iptables-services
- 编辑iptables配置
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
- 重启防火墙
systemctl restart iptables.service
- 开机自启动
systemctl enable iptables.service
- 关闭SELINUX,编辑config文件内容
vi /etc/selinux/config
add the line: SELINUX=disabled
- 使配置立即生效
setenforce 0
主要部件安装
Apache
CentOS7安装apache
yum install httpd
- 启动、停止、重启、设置开机自启动
systemctl start httpd.service
systemctl stop httpd.service
systemctl restart httpd.service
systemctl enable httpd.service
- 完成这些之后可以在浏览器中打开服务器ip地址,如果正确配置则会出现apache默认界面
Ununtu安装apache
- 安装apache
sudo apt-get install apache2
- 编辑配置文件
sudo vim /etc/apache2/apache2.conf
add the line: ServerName IpAddress or domain
- 重启apache服务并测试
sudo systemctl restart apache2
sudo apache2ctl configtest
MySql
CentOS7安装mysql
- 因为yum没有mysql,所以需要先下载再安装mysql
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
rpm -ivh mysql-community-release-el7-5.noarch.rpm
yum install mysql-server
- 重新启动服务,保证权限足够。然后设置mysql的密码
service mysqld restart
mysql -u root
mysql > use mysql;
mysql > update user set password=password('123456') where user='root';
mysql > exit;
Ubuntu 安装mysql
sudo apt-get install mysql-server
PHP
CentOS7 安装PHP
yum install php
yum install php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-bcmath php-mhash
Ubuntu 安装PHP
sudo apt-get install php libapache2-mod-php php-mcrypt php-mysql
最后的配置
Apache
- 在CentOS7编辑文件
vi /etc/httpd/conf/httpd.conf
- 在Ubuntu中对应的文件为
/etc/apache2/apache2.conf
- 添加以下文件
//添加ServerSignature On (在错误页中显示Apache的版本)
ServerSignature On
//允许服务器执行CGI及SSI,禁止列出目录
Options Indexes FollowSymLinks #修改为:Options Includes ExecCGI FollowSymLinks
//允许.htaccess
AllowOverride None #修改为:AllowOverride All
//设置不在浏览器上显示树状目录结构
#Options Indexes FollowSymLinks #修改为 Options FollowSymLinks
//设置默认首页文件,增加index.php
DirectoryIndex index.html#修改为:DirectoryIndex index.html index.htm index.php
//添加MaxKeepAliveRequests 500 (增加同时连接数)
MaxKeepAliveRequests 500
- 删除默认测试页
rm -f /etc/httpd/conf.d/welcome.conf /var/www/error/noindex.html
php配置
- 编辑php.ini文件
vi /etc/php.ini
- 添加以下内容
//设置时区,把前面的分号去掉
date.timezone = PRC
//禁止显示php版本的信息
expose_php = Off
//支持php短标签
short_open_tag = ON
然后重启apache服务
测试
/var/www/html
为apache默认文件夹
在这里编辑
index.html index.htm index
都可以实现网页显示的效果
参考
后记
以上过程按着流程走,注意权限和端口开放都不会遇到什么问题。笔者在配置域名的时候倒是耽误了一些时间,因为一些和a记录相关的问题。