CentOS7 安裝LAMP環境,centos7lamp環境

來源:互聯網
上載者:User

CentOS7 安裝LAMP環境,centos7lamp環境

1、使用yum安裝

yum -y install httpd mysql mysql-server php php-mysql postgresql postgresql-server php-postgresql php-pgsql php-devel

2、配置httpd

2.1、啟動httpd服務並把此服務單元加入當前運行級

systemctl start httpd.service

systemctl enable httpd

2.2、開啟firewalld防火牆的80連接埠

firewall-cmd --add-service=http                    (即時開啟)

firewall-cmd --permanent --add-service=http  (寫入設定檔)

 

3、配置MySQL

3.1 安裝wget工具

yum install wget

3.2 下載mysql的repo源

wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm 

3.3 安裝mysql-community-release-el7-5.noarch.rpm包

sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm

3.4 進行資料庫安裝

sudo yum install mysql-server

3.5 執行命令mysql -u root ,看到系統報錯

3.6 變更檔的許可權,執行命令sudo chown -R root:root /var/lib/mysql

3.7 重啟mysql

service mysqld restart

3.8執行mysql -u root命令進入mysql, 使用mysql資料庫

use mysql 

3.9 設定使用者root的密碼

update user set password=password('root') where user='root';

3.10 添加使用localhost登入時候的密碼

set password for 'root' @ 'localhost' = password('root');

3.11 授權允許遠程登入

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION; 

3.12 執行命令:FLUSH   PRIVILEGES

3.13 重啟mysql

3.14 開啟3306連接埠

firewall-cmd --add-port=3306/tcp

 

 4、測試

4.1 建立資料庫,建立資料表

4.2 在 var/www/html下,建立一個新檔案,編寫代碼

vi demo.php

<?php

mysql_connect('地址','使用者名稱','密碼');

……

4.3 在其他電腦上輸入linux的ip地址再加上檔案名稱(如:192.168.1.100/demo.php),如果可以顯示結果,則表明配置成功!

另:

1、查詢是否開啟80連接埠

firewall-cmd --query-port=80/tcp

2、開啟80連接埠

firewall-cmd --add-port=80/tcp

 3、查看ip地址

ip addr

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.