站长视角
用户至上

CentOS 6下手动安装LAMP环境(通用版)

优质广告位招租,欢迎联系站长

本期教程目录
1.安装/配置Apache
2.安装/配置MySQL
3.安装/配置PHP

一、安装/配置Apache

1.更新系统&安装Apache
yum update
yum install httpd

推荐:使用如下命令备份Apache配置文件
cp /etc/httpd/conf/httpd.conf ~/httpd.conf.backup

为了给大家拓展思路,本次在CentOS上的教程,和大家分享Apache的另外一种绑定域名和创建虚拟机的方式~

2.编辑/etc/httpd/conf.d/vhost.conf,假设我们要绑定example.com和example.org两个域名,则参照下面内容加入文件,
NameVirtualHost *:80

ServerAdmin webmaster@example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /srv/www/example.com/public_html/
ErrorLog /srv/www/example.com/logs/error.log
CustomLog /srv/www/example.com/logs/access.log combined

ServerAdmin webmaster@example.org
ServerName example.org
ServerAlias www.example.org
DocumentRoot /srv/www/example.org/public_html/
ErrorLog /srv/www/example.org/logs/error.log
CustomLog /srv/www/example.org/logs/access.log combined

3.因为我们上文指定了几个目录而这几个目录还不存在,所以,使用如下命令创建相应目录,
mkdir -p /srv/www/example.com/public_html
mkdir /srv/www/example.com/logs

mkdir -p /srv/www/example.org/public_html
mkdir /srv/www/example.org/logs

4.启动Apache
/etc/init.d/httpd start

日后每次修改vhost.conf文件,都需要使用如下命令使Apache重新载入配置文件
/etc/init.d/httpd reload

5.设置Apache开机启动
/sbin/chkconfig –levels 235 httpd on

二、安装/配置MySQL

1.安装MySQL
yum install mysql-server

2.设置MySQL开机自动启动
/sbin/chkconfig –levels 235 mysqld on

3.启动MySQL
/etc/init.d/mysqld start

MySQL的配置文件位于/etc/my.cnf

4.安装mysql_secure_installation(MySQL安全设置)
mysql_secure_installation

5.附上常用的MySQL命令

登录MySQL
mysql -u root -p

创建数据库iaodun(注意MySQL命令行下都需要以;结尾),并将该数据库所有权限赋予iaodun_user(密码为123)
create database iaodun;
grant all on iaodun.* to ‘iaodun_user’ identified by ‘123’;

退出MySQL
quit

三、安装/配置PHP

1.安装PHP
yum install php php-pear php-mysql

2.编辑配置文件/etc/php.ini,修改如下内容
error_reporting = E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR
display_errors = Off
log_errors = On
error_log = /var/log/php.log
max_execution_time = 300
memory_limit = 64M
register_globals = Off

最后,重启Apache,大功告成~
/etc/init.d/httpd restart

赞(0)
版权声明:本文采用知识共享 署名4.0国际许可协议 [BY-NC-SA] 进行授权, 转载请注明出处。
文章名称:《CentOS 6下手动安装LAMP环境(通用版)》
文章链接:https://cnidc.co/394.html
【声明】:国外主机测评仅分享信息,不参与任何交易,也非中介,所有内容仅代表个人观点,均不作直接、间接、法定、约定的保证,读者购买风险自担。一旦您访问国外主机测评,即表示您已经知晓并接受了此声明通告。
【关于安全】:任何 IDC商家都有倒闭和跑路的可能,备份永远是最佳选择,服务器也是机器,不勤备份是对自己极不负责的表现,请保持良好的备份习惯。
香港110M(含10M CN2)大带宽独服限量促销,香港E3-8G-1T硬盘-3IP,月付仅799!

登录

找回密码

注册