1. 程式人生 > >VPS下搭建LAMP環境

VPS下搭建LAMP環境

CentOS7.5 安裝部署Apache+Mysql+PHP

安裝Apache

1、安裝

yum -y install httpd

2、開啟Apache服務

systemctl start httpd.service

3、設定Apache服務開機啟動

systemctl enable httpd.service

4、開啟防火牆

firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload

5.驗證apache服務是否安裝成功
開啟http://xx.xx.xx.xx/,apache預設的頁面–有Testing 123…字樣

安裝PHP

6、安裝

yum -y install php

7、重啟Apache服務

systemctl restart httpd.service

8、測試PHP
vi /var/www/html/info.php編輯內容為:

<?php phpinfo(); ?>儲存,然後開啟http://xx.xx.xx.xx/info.php如果有內容則說明安裝成功。

安裝SQL

9、下載安裝Mysql
下載

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

解壓安裝

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

源安裝

yum -y install mysql-community-server

10、重啟Mysql

service mysqld restart

11、設定Mysql
登入Mysql

mysql -u root

顯示資料庫

show databases;

設定密碼

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

遠端連線設定

grant all privileges on *.* to 
[email protected]
'%'identified by '123456';

如果不是root則先新建使用者

create user '使用者名稱'@'%' ip地址 by '密碼'

12、設定防火牆

firewall-cmd --permanent --zone=public --add-port=3306/tcp
firewall-cmd --reload

將PHP和Mywql關聯起來

yum -y install php-mysql

13、安裝常用的PHP模組

yum -y install php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel

14、重啟Apache服務

systemctl restart httpd.service

安裝phpmyadmin

mkdir -p /var/www/html/html/phpmtadmin
cd /home/使用者/
wget http://oss.aliyuncs.com/aliyunecs/onekey/phpMyAdmin-4.1.8-all-languages.zip
unzip phpMyAdmin-4.1.8-all-languages.zip
mv phpMyAdmin-4.1.8-all-languages/* /var/www/html/phpmyadmin

測試 http://xx.xx.xx.xx/phpmyadmin

附:
selinux設定
當網頁開啟403時可以先臨時設定selinux為警告模式setenforce 0,然後測試
修改目錄下的上下檔案型別為公共型別
semanage fcontext -a -t public_content_t ‘/var/www(/.*)?’
然後 輸入命令restorecon -RvvF /var/www/將規則同步至目錄及其子目錄

以上即完成伺服器設定
初次將專案放入yum安裝的目錄/var/www/html/檔案下,進行瀏覽器登陸http://127.0.0.1/index.php首頁的圖片全沒有出現,
解決辦法: 問題網站沒有許可權訪問檔案內容,開啟專案內圖片檢視許可權
cd /var/www/
chmod -R 777 *

Apache的基本命令
#啟動服務
systemctl start httpd.service

#檢視服務
ps aux | grep httpd

#停止服務
systemctl stop httpd.service

#重啟服務
systemctl restart httpd.service