centOS 7.2搭建服务器lamp环境

来源:互联网 发布:淘宝店铺入驻规则 编辑:程序博客网 时间:2024/06/06 02:19

lamp环境

yum list //列出所指定的软件包,后可以加上你想查找的软件包的名字
yum linst installed //列出所有已安装的软件包
yum info installed //列出所有已安装的软件包信息

阿里云默认ECS没有打开公网ip 需要设置安全组.

1.安装apache
  需要服务器联网
  安装:yum install -y httpd
  运行:/bin/systemctl start httpd.service
  执行完运行命令之后是看不到效果的,这时候再输入查看apache服务状态命令来查看服务是否已经启动:
    查看状态:service httpd status
    Apache开启服务:systemctl start httpd
    Apache停止服务:systemctl stop httpd
测试apache服务是否正常开启,在我们本地浏览器里输入云服务器的公网ip

2.安装mysql
  wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
  rpm -ivh mysql-community-release-el7-5.noarch.rpm
  yum install mysql-community-server
  
成功安装之后重启mysql服务
systemctl restart mysqld
初次安装mysql是root账户是没有密码的
设置密码的方法:

输入mysql -uroot进入mysql数据库
  mysql> set password for ‘root’@‘localhost’ = password(‘newpasswd’);
  mysql> quit   

远程授权连接mysql
mysql>use mysql;   
mysql>GRANT ALL PRIVILEGES ON . TO ‘root’@’%’ IDENTIFIED BY ‘你要设置的数据库密码’ WITH GRANT OPTION;
查看user表 host % user root 就对了
mysql>FLUSH PRIVILEGES;//从新加载授权表

3.安装5.6php
以下是CentOS 7的源

yum install epel-release
rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
使用yum list命令查看可安装的包(Packege)。
yum list –enablerepo=remi –enablerepo=remi-php56 | grep php

安装PHP5.6.x
yum install –enablerepo=remi –enablerepo=remi-php56 php php-opcache php-devel php-mbstring php-mcrypt php-mysqlnd php-phpunit-PHPUnit php-pecl-xdebug php-pecl-xhprof

4.配置apache 和 php

让apache支持php

使用httpd -V 命令查看apache的配置文件httpd.conf文件所在目录:
编辑httpd.conf

vim /… /httpd.conf

找到DirectoryIndex,在index.html后添加

index.php

找到AddType,在之后添加一行

AddType application/x-httpd-php .php

重启apache

netstat -tunpl 查看端口是否已经开启

配置域名 搭建laravel
打开 /etc/httpd/conf/httpd.conf
确保DocumentRoot 指向的目录是laravel中public文件夹。如果不是需要改为如下:

DocumentRoot “/var/www/html/laravel/public/”
< Directory “/var/www/html/laravel/public”>
Allowoverride All
< /Directory>

< VirtualHost *:80>
ServerAdmin xxx@xxx.com
ServerName (域名)
DocumentRoot /var/www/html/Code/laravel_demo/public
ErrorLog /var/log/apache/error_log_xx
CustomLog /var/log/apache/access_log_xx common
< /VirtualHost>

原创粉丝点击