利用VPS來搭建個人主頁


Linux 系統中LAMP搭建與配置

起點

  • 安裝了linux系統的服務器
  • 終端

防火牆設置

  • 關閉firewall
systemctl stop firewalld.service
  • 禁止firewall開機啟動
systemctl disable firewalld.service
  • 安裝iptables防火牆
yum install iptables-services
  • 編輯iptables配置
vi /etc/sysconfig/iptables
  • 增加內容,后續有更多開辟的端口以相同方式添加
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
  • 重啟防火牆
systemctl restart iptables.service
  • 開機自啟動
systemctl enable iptables.service
  • 關閉SELINUX,編輯config文件內容
vi /etc/selinux/config
add the line: SELINUX=disabled
  • 使配置立即生效
setenforce 0

主要部件安裝

Apache

CentOS7安裝apache

yum install httpd
  • 啟動、停止、重啟、設置開機自啟動
systemctl start httpd.service
systemctl stop httpd.service
systemctl restart httpd.service
systemctl enable httpd.service
  • 完成這些之后可以在瀏覽器中打開服務器ip地址,如果正確配置則會出現apache默認界面

Ununtu安裝apache

  • 安裝apache
sudo apt-get install apache2
  • 編輯配置文件
sudo vim /etc/apache2/apache2.conf
add the line: ServerName IpAddress or domain
  • 重啟apache服務並測試
sudo systemctl restart apache2
sudo apache2ctl configtest

MySql

CentOS7安裝mysql

  • 因為yum沒有mysql,所以需要先下載再安裝mysql
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
rpm -ivh mysql-community-release-el7-5.noarch.rpm
yum install mysql-server
  • 重新啟動服務,保證權限足夠。然后設置mysql的密碼
service mysqld restart
mysql -u root
mysql > use mysql;
mysql > update user set password=password('123456') where user='root';
mysql > exit;

Ubuntu 安裝mysql

sudo apt-get install mysql-server

PHP

CentOS7 安裝PHP

yum install php
yum install php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-bcmath php-mhash

Ubuntu 安裝PHP

sudo apt-get install php libapache2-mod-php php-mcrypt php-mysql

最后的配置

Apache

  • 在CentOS7編輯文件
vi /etc/httpd/conf/httpd.conf
  • 在Ubuntu中對應的文件為
/etc/apache2/apache2.conf
  • 添加以下文件
//添加ServerSignature On (在錯誤頁中顯示Apache的版本) 
ServerSignature On
//允許服務器執行CGI及SSI,禁止列出目錄
Options Indexes FollowSymLinks #修改為:Options Includes ExecCGI FollowSymLinks
//允許.htaccess
AllowOverride None #修改為:AllowOverride All
//設置不在瀏覽器上顯示樹狀目錄結構
#Options Indexes FollowSymLinks #修改為 Options FollowSymLinks
//設置默認首頁文件,增加index.php
DirectoryIndex index.html#修改為:DirectoryIndex index.html index.htm index.php
//添加MaxKeepAliveRequests 500 (增加同時連接數)
MaxKeepAliveRequests 500
  • 刪除默認測試頁
rm -f /etc/httpd/conf.d/welcome.conf /var/www/error/noindex.html

php配置

  • 編輯php.ini文件
vi /etc/php.ini
  • 添加以下內容
//設置時區,把前面的分號去掉
date.timezone = PRC
//禁止顯示php版本的信息
expose_php = Off
//支持php短標簽
short_open_tag = ON

然后重啟apache服務

測試

 /var/www/html

為apache默認文件夾
在這里編輯

index.html index.htm index

都可以實現網頁顯示的效果

參考

后記

以上過程按着流程走,注意權限和端口開放都不會遇到什么問題。筆者在配置域名的時候倒是耽誤了一些時間,因為一些和a記錄相關的問題。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM