一、關閉防火墻
1.查看防火墻狀態
systemctl status firewalld

- inactive 關閉狀態
- active 開啟狀態
2.關閉防火墻
systemctl stop firewalld
3.永久關閉防火墻
systemctl disable firewalld
二、安裝Apache
1.安裝Apache服務及擴展包
yum -y install httpd httpd-manual mod_ssl mod_perl mod_auth_mysql
2.啟動Apache服務
systemctl start httpd
3.設定Apache服務開機自啟動
systemctl enable httpd
4.查看apache是否安裝成功
在瀏覽器地址欄輸入 http://ip地址,運行,出現如下頁面即安裝成功

三、安裝并配置MySQL
1.更新YUM源
rpm -Uvh http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
2.安裝MySQL
yum -y install mysql-community-server
如果出現”No match for argument“錯誤,請先運行yum module disable mysql禁用默認的mysql模塊,再安裝MySQL
3.查看MySQL版本號
mysql -V
出現如下資訊即表示安裝成功,注意”V“要大寫

4.啟動mysql
systemctl start mysqld
5.設定開機自啟動
systemctl enable mysqld systemctl daemon-reload
6.查看初始密碼
grep "password" /var/log/mysqld.log

7.配置MySQL的安全性
mysql_secure_installation
- 重置root賬號的密碼
Enter password for user root: #輸入上一步獲取的root用戶初始密碼
The 'validate_password' plugin is installed on the server.
The subsequent steps will run with the existing configuration of the plugin.
Using existing password for root.
Estimated strength of the password: 100
Change the password for root ? (Press y|Y for Yes, any other key for No) : Y #是否更改root用戶密碼,輸入Y
New password: #輸入新密碼,長度為8至30個字符,必須同時包含大小寫英文字母、數字和特殊符號,特殊符號可以是()` ~!@#$%^&*-+=|{}[]:;‘<>,.?/
Re-enter new password: #再次輸入新密碼
Estimated strength of the password: 100
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y
- 輸入Y洗掉匿名用戶賬號
By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y #是否洗掉匿名用戶,輸入Y Success.
- 輸入Y禁止root賬號遠程登錄
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y #禁止root遠程登錄,輸入Y Success.
- 輸入Y洗掉test庫以及對test庫的訪問權限
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y #是否洗掉test庫和對它的訪問權限,輸入Y - Dropping test database... Success.
- 輸入Y重新加載授權表
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y #是否重新加載授權表,輸入Y Success. All done!
四、安裝PHP
1.更新YUM源
- 添加epel源
yum install -y \ https://repo.ius.io/ius-release-el7.rpm \ https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
- 添加Webtatic源
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
2.安裝PHP
yum -y install php70w-devel php70w.x86_64 php70w-cli.x86_64 php70w-common.x86_64 php70w-gd.x86_64 php70w-ldap.x86_64 php70w-mbstring.x86_64 php70w-mcrypt.x86_64 php70w-pdo.x86_64 php70w-mysqlnd php70w-fpm php70w-opcache php70w-pecl-redis php70w-pecl-mongodb
3.查看PHP版本
php -v
出現如下結果即表示php安裝成功

4.在Apache網站根目錄創建測驗檔案
echo "<?php phpinfo(); ?>" > /var/www/html/phpinfo.php
5.重啟Apache服務
systemctl restart httpd
6.運行,在瀏覽器地址欄輸入http://ip地址/phpinfo.php,出現如下頁面即表示安裝成功

五、安裝phpMyAdmin
1.創建phpMyAdmin資料存放目錄
mkdir -p /var/www/html/phpmyadmin
2.下載phpMyAdmin壓縮包并解壓
- 下載
wget https://files.phpmyadmin.net/phpMyAdmin/4.0.10.20/phpMyAdmin-4.0.10.20-all-languages.zip
- 解壓
yum install -y unzip unzip phpMyAdmin-4.0.10.20-all-languages.zip
3.復制phpMyAdmin檔案到準備好的資料存放目錄
mv phpMyAdmin-4.0.10.20-all-languages/* /var/www/html/phpmyadmin
4.檢查是否安裝成功,在瀏覽器地址欄輸入http://ip地址/phpmyadmin,運行,出現如下頁面即表示安裝成功
LAMP環境配置完成!
如果使用navicat連接資料庫報錯,ERROR 1130: Host xxx.xxx.xxx.xxx is not allowed to connect to this MySQL server,是無法給遠程連接的用戶權限問題,就是”7.配置MySQL的安全性“中第三步設定了禁止遠程登陸
解決辦法:
mysql -u root -p密碼
進入Mysql控制臺
- 提權
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '密碼' WITH GRANT OPTION;
- 重繪
flush privileges;
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/233344.html
標籤:其他
