如何在centos7上部署lnmp环境
答案:2 悬赏:80
解决时间 2021-02-12 03:49
- 提问者网友:烟刺痛了眼
- 2021-02-11 08:15
如何在centos7上部署lnmp环境
最佳答案
- 二级知识专家网友:不傲怎称霸
- 2021-02-11 09:54
一、安装httpd。
yum install -y httpd
安装完成之后使用以下命令启动httpd服务:
systemctl start httpd.service #启动apache
systemctl stop httpd.service #停止apache
systemctl restart httpd.service #重启apache
systemctl enable httpd.service #设置apache开机启动 可以在浏览器中输入服务器所在的主机的IP即可看到apache的欢迎界面。要在另外一台主机上实现这种访问,需要关闭系统的防火墙。 在CentOS7中,修改防火墙的机制已经做了修改,在CentOS 6.x系统中可以使用以下命令:
service iptables stop
chkconfig iptables off // 开机禁止启动
而在CentOS7中只能使用以下命令,如果使用上面的命令并不会报任何错误,但是起不到关闭防火墙的效果:
systemctl stop firewalld.service
systemctl disable firewalld.service //禁止防火墙开机启动关闭SeLinux:
使用getenforce命令可以查看SeLinux的状态,SeLinux有三种状态,分别为enforcing、permissive和disabled。因为我们的服务器只在内部使用,所以这里我们选择完全关闭(disabled)。具体的做法为修改/etc/sysconfig/selinux文件,具体操作可以看里面的说明。
成功安装httpd(apache)的效果图为:
二、安装MySQL数据库。
MySQL数据库,新版本已经更名为Mariadb,所以这里需要安装Mariadb,可以使用下面的命令进行安装:
yum install -y mariadb
安装完成以后使用下面的命令开启数据库服务:
systemctl start mariadb.service #启动MariaDB
systemctl stop mariadb.service #停止MariaDB
systemctl restart mariadb.service #重启MariaDB
systemctl enable mariadb.service #设置开机启动
三、安装PHP。
使用下面的命令可以安装PHP:
yum -y install php
使用下面的命令安装php对Mariadb的支持:
yum install php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-bcmath php-mhash
使用下面的命令重启Mariadb和httpd服务:
systemctl restart mariadb.service #重启MariaDB
systemctl restart httpd.service #重启apache
yum install -y httpd
安装完成之后使用以下命令启动httpd服务:
systemctl start httpd.service #启动apache
systemctl stop httpd.service #停止apache
systemctl restart httpd.service #重启apache
systemctl enable httpd.service #设置apache开机启动 可以在浏览器中输入服务器所在的主机的IP即可看到apache的欢迎界面。要在另外一台主机上实现这种访问,需要关闭系统的防火墙。 在CentOS7中,修改防火墙的机制已经做了修改,在CentOS 6.x系统中可以使用以下命令:
service iptables stop
chkconfig iptables off // 开机禁止启动
而在CentOS7中只能使用以下命令,如果使用上面的命令并不会报任何错误,但是起不到关闭防火墙的效果:
systemctl stop firewalld.service
systemctl disable firewalld.service //禁止防火墙开机启动关闭SeLinux:
使用getenforce命令可以查看SeLinux的状态,SeLinux有三种状态,分别为enforcing、permissive和disabled。因为我们的服务器只在内部使用,所以这里我们选择完全关闭(disabled)。具体的做法为修改/etc/sysconfig/selinux文件,具体操作可以看里面的说明。
成功安装httpd(apache)的效果图为:
二、安装MySQL数据库。
MySQL数据库,新版本已经更名为Mariadb,所以这里需要安装Mariadb,可以使用下面的命令进行安装:
yum install -y mariadb
安装完成以后使用下面的命令开启数据库服务:
systemctl start mariadb.service #启动MariaDB
systemctl stop mariadb.service #停止MariaDB
systemctl restart mariadb.service #重启MariaDB
systemctl enable mariadb.service #设置开机启动
三、安装PHP。
使用下面的命令可以安装PHP:
yum -y install php
使用下面的命令安装php对Mariadb的支持:
yum install php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-bcmath php-mhash
使用下面的命令重启Mariadb和httpd服务:
systemctl restart mariadb.service #重启MariaDB
systemctl restart httpd.service #重启apache
全部回答
- 1楼网友:气场征服一切
- 2021-02-11 10:51
sudo vi /etc/apt/sources.list 输入提供软件的地址(里面有默认的地址可以用,不可以的话网上到处都是这里就不贴出来了)保存退出
sudo apt-get update
可能会出现更新不了,这是看一下/etc/apt/apt.conf (这个貌似是设置http代理的文件)。如果没有设置代理,将里面的东西删除即可
开始安装
1、安装nginx,并启动
sudo apt-get install nginx
sudo /etc/init.d/nginx start(或者 service nginx start)
2、安装php和mysql
sudo apt-get install php5-cli php5-cgi mysql-server php5-mysql
更改数据库用户的权限grant all on *.* to root@'%' identified by '123456';
刷新让权限生效flush privileges;
修改mysql的配置文件 sudo vi /etc/mysql/my.cnf
将bind-address = 127.0.0.1 注释掉,就可以远程连接数据库了
3、安装php5-fpm
sudo apt-get install php5-fpm
4、配置nginx并重启服务
sudo vi /etc/nginx/sites-enabled,修改如下
server{
listen 80;
root /var/www;
index index.php index.html index.htm;
server_name localhost;
location / {
try_files $uri $uri/ /index.html;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param script_filename /var/www$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
}
保存退出
5、启动fastcgi php
sudo service php5-fpm start
6、重启nginx服务
sudo service nginx restart
7、安装php相关扩展
如 xdebug 、memcache、 oauth等
1)安装curl:sudo apt-get install php5-curl
2)安装gettext:sudo apt-get install php-gettext
3)安装gd库:sudo apt-get install php5-gd
4)安装mcrypt:sudo apt-get install php5-mcrypt
5)安装memcache
a)安装服务器 :
sudo apt-get install memcached
$ memcached -d -m 50 -p 11211 -u root
参数说明 -m 指定使用多少兆的缓存空间;-p 指定要监听的端口; -u 指定以哪个用户来运行
b)安装php 模块:
sudo apt-get install php5-memcache
6)安装oauth:基于pecl的
a)sudo apt-get install php5-dev php-pear libpcre3-dev
sudo pecl install oauth (要确保有linux系统里可以make)
b)修改配置文件
sudo vi /etc/php5/fpm/php.ini
在最后添加extension=oauth.so
7)安装ssh2:sudo apt-get install libssh2-php
8)安装xdebug:
sudo apt-get install php5-xdebug
修改php的配置文件 sudo vi /etc/php5/fpm/php.ini
将display_errors和html_errors都改为on
9)安装完上述扩展后重启php服务 :sudo service php5-fpm restart
至此整个环境就搭好了。
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯