基本流程:
1.安装apche或nginx
2.安装mysql
3.安装php
4.测试环境
流程一:安装apche或nginx
1)关闭SELINUX
修改配置文件,重启服务后永久生效。
sed -i 's/SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config
命令行设置立即生效。
setenforce 0
网易官方源 centos6.x cd /etc/yum.repos.d/ mv CentOS-Base.repo CentOS-Base.repo.$(date +%F) wget http://mirrors.163.com/.help/CentOS6-Base-163.repo yum clean all yum makecache
更多国内知名yum源可参考:http://blog.51cto.com/13707680/2104644
2)安装Apache:
yum -y install httpd
yum -y install httpd-manual mod_ssl mod_perl mod_auth_mysql
/etc/init.d/httpd start
netstat -tnlp|grep 80
安装nginx:
Centos6系统库中默认是没有nginx的rpm包的,所以我们需要先更新下rpm依赖库
1)使用yum安装nginx,安装nginx库
rpm -Uvh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
2)使用下面命令安装nginx
yum -y install nginx
[root@localhost ~]# nginx -v
nginx version: nginx/1.14.0
3)启动nginx
/etc/init.d/nginx start 或 service nginx start
4 ) 防火墙允许通过80端口
vim /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
/etc/init.d/iptables restart
流程二:安装mysql
1)安装Mysql,先更新yum源。yum源下载地址,根据自己需要的版本选择相应的源
https://dev.mysql.com/downloads/repo/yum/
2)这里版本是6.x系列的,所以选择linux 6 下载
wget https://repo.mysql.com//mysql57-community-release-el6-11.noarch.rpm
3)安装mysql的yum源
rpm -Uvh mysql57-community-release-el6-11.noarch.rpm 或 yum -y localinstall mysql57-community-release-el6-11.noarch.rpm
4)查看mysql源是否成功
[root@localhost yum.repos.d]# ls /etc/yum.repos.d/|grep mysql
mysql57-community-release-el6-11.noarch.rpm
mysql-community.repo
mysql-community-source.repo
5)安装mysql
yum -y install mysql-community-server
[root@localhost ~]# mysql -V
mysql Ver 14.14 Distrib 5.7.22, for Linux (x86_64) using EditLine wrapper
6)开启mysql,并更改默认密码
/etc/init.d/mysqld start
netstat -tnlp |grep 3306
chkconfig mysqld on
[root@localhost yum.repos.d]# grep 'temporary password' /var/log/mysqld.log
2018-05-10T22:59:11.434638Z 1 [Note] A temporary password is generated for root@localhost: OScMFRu&j75Q
mysql -uroot -p"OScMFRu&j75Q"
ALTER USER 'root'@'localhost' IDENTIFIED BY 'ywxi123';
mysql -uroot -p"ywxi123"
7)防火墙允许通过3306端口
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
service iptables restart
流程三:安装php
1)更新yum源
rpm -Uvh http://ftp.iij.ad.jp/pub/linux/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
2)安装PHP
yum -y install --enablerepo=remi --enablerepo=remi-php56 php php-bcmath php-opcache php-devel php-mbstring php-mcrypt php-mysqlnd php-gd php-xml php-memcache php-redis php-fpm php-mysql php-common php-mssql
3)配置php.ini文件,关闭php信息头
sed 's#expose_php = On#expose_php = Off#g' /etc/php.ini -i
[root@localhost html]# php -v
PHP 5.6.36 (cli) (built: Apr 25 2018 10:11:47)
4)启动php,并开机自启
/etc/init.d/php-fpm start
chkconfig php-fpm on
流程四:环境测试
1)LNMP环境测试准备
编辑/etc/nginx/conf.d/default.conf,在所支持的主页面格式中添加php格式的主页,类似如下:
[root@localhost conf.d]# cat default.conf
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.php index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html/$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
[root@localhost html]# cat /usr/share/nginx/html/index.php
<?php
$conn=mysql_connect('127.0.0.1','root','ywxi123');
if ($conn){
echo "LNMP platform connect to mysql is successful!";
}else{
echo "LNMP platform connect to mysql is failed!";
}
phpinfo();
?>
chown -R nginx.nginx /usr/share/nginx/html/
http://192.168.1.22/index.php 访问到如下页面证明LNMP环境搭建成功
2)LAMP环境测试准备
/etc/init.d/nginx stop
/etc/init.d/httpd start
[root@localhost html]# cat /var/www/html/index.php
<?php
$conn=mysql_connect('127.0.0.1','root','ywxi123');
if ($conn){
echo "LAMP platform connect to mysql is successful!";
}else{
echo "LAMP platform connect to mysql is failed!";
}
phpinfo();
?>
chown -R apache.apache /var/www/html
http://192.168.1.22/index.php 访问到如下页面证明LAMP环境搭建成功
原文地址:http://blog.51cto.com/13707680/2115079