系統(tǒng)環(huán)境centos7.6
一、安裝Apache
1.1 安裝apache
yum install httpd httpd-devel
1.2 啟動apache服務(wù)
systemctl start httpd
1.3 設(shè)置httpd服務(wù)開機(jī)啟動
systemctl enable httpd
1.4 查看服務(wù)狀態(tài)
systemctl status httpd
1.5 防火墻設(shè)置開啟80端口
firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload
1.6確認(rèn)80端口監(jiān)聽中
yum install net-tools
netstat -tulp//確認(rèn)[::]:http的state處在listen中
1.7 查服務(wù)器IP
ip addr
若使用云服務(wù)器,則直接使用實(shí)例公網(wǎng)ip
1.8瀏覽器登陸
使用瀏覽器登陸1.7中的IP地址,確認(rèn)Apache服務(wù)器正確運(yùn)行中
二、安裝mysql
2.1安裝mysql
yum install mariadb mariadb-server mariadb-libs mariadb-devel
2.2 開啟mysql服務(wù),并設(shè)置開機(jī)啟動,檢查mysql狀態(tài)
systemctl start mariadb
systemctl enable mariadb
systemctl status mariadb
netstat -tulp//確認(rèn)0.0.0.0:mysql的state處在listen中
2.3數(shù)據(jù)庫安全設(shè)置
mysql_secure_installation
需要設(shè)置以下幾個問題:
Enter current password for (enter for none)://輸入當(dāng)前root用戶密碼(無密碼直接按回車)
Set root password?[Y/n]//是否設(shè)置root密碼(建議按Y)
New password://請輸入新的密碼
Re-enter new password://請確認(rèn)新密碼
Remove anonymous users?[Y/n]//是否刪除匿名用戶(建議按Y)
Disallow root login remotely? [Y/n]//是否拒絕root用戶遠(yuǎn)程鏈接(建議按n)
Remove test database and access to it? [Y/n] //是否刪除test數(shù)據(jù)庫(建議按Y)
Reload privilege tables now? [Y/n]//是否立即更新權(quán)限表(建議按Y)
2.4 登陸數(shù)據(jù)庫測試
mysql -u root -p
Enter password://輸入root用戶密碼,進(jìn)入即可(退出數(shù)據(jù)庫的命令是exit)
2.5開放遠(yuǎn)程連接
iptables -L -n//查看防火墻是否開放3306端口
沒有開放3306端口則進(jìn)行如下操作
firewall-cmd --permanent --zone=public --add-port=3306/tcp
若已開放3306端口則直接進(jìn)入數(shù)據(jù)庫進(jìn)行如下操作
//以下SQL命令最好手打,否則語句中的引號可能出現(xiàn)問題
use mysql;
update user set host=’%’ where user=’root’ limit 1;
grant all privileges on *.* to 'root'@'%' identified by '遠(yuǎn)程連接密碼' with grant option;//identified by后寫實(shí)際的root密碼,記得帶引號
flush privileges;
三、安裝PHP
3.1 安裝php
yum -y install php
3.2 將php與mysql關(guān)聯(lián)起來
yum install php-mysql
3.3安裝常用PHP模塊(用不到就跳過)
yum install -y php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel php-bcmath
3.4測試PHP
cd /var/www/html //這是PHP的網(wǎng)站目錄,項(xiàng)目就放在這下面
vi index.php //創(chuàng)建并編輯index.php文件,在文件中使用phpinfo函數(shù),保存退出
systemctl restart httpd //重啟Apache服務(wù)器
而后使用瀏覽器訪問服務(wù)器IP,查看PHP環(huán)境
四、搭建FTP服務(wù)器
4.0關(guān)閉selinux(準(zhǔn)備工作)
vi /etc/selinux/config
將SELINUX=enforcing改成SELINUX=disabled
保存
setenforce 0 //立即關(guān)閉selinux
4.1安裝vsftp
yum install -y vsftpd
4.2啟動服務(wù)
chkconfig vsftpd on
service vsftpd restart
netstat -antup | grep ftp //查看ftp服務(wù)端口
service vsftpd restart //重啟服務(wù),不能省
4.3修改主配置文件
vi /etc/vsftpd/vsftpd.conf
將anonymous_enable=YES改成anonymous_enable=NO
將chroot_local_user=YES的注釋解開
保存
4.4創(chuàng)建ftp用戶
useradd -s /sbin/nologin -d /var/www/html qwerty123 //創(chuàng)建用戶名為qwerty123的用戶
passwd qwerty123 //為用戶qwerty123設(shè)置密碼
chmod o+w /var/www/html/ //給主目錄修改權(quán)限
4.5防火墻開放20、21端口
firewall-cmd --permanent --zone=public --add-port=20/tcp
firewall-cmd --permanent --zone=public --add-port=21/tcp
firewall-cmd --reload
4.6使用filezilla連接
輸入服務(wù)器IP地址、用戶名、密碼,點(diǎn)擊‘連接’,如果可以建立連接但是不能讀取列表,則在filezilla進(jìn)行如下操作:
點(diǎn)擊菜單欄“文件”->“站點(diǎn)管理器”,在“常規(guī)”選項(xiàng)卡中填入服務(wù)器IP地址,登陸類型選擇“正?!?,填入用戶名、密碼,在“傳輸設(shè)置”選項(xiàng)卡中把傳輸模式從“默認(rèn)”設(shè)為“主動”或“被動”,再點(diǎn)擊“連接”即可。