Linux安裝LAMP開發環境及配置檔案管理

2021-07-11 18:48:54 字數 4411 閱讀 6638

linux主要分為兩大系發行版,分別是redhat和debian,lamp環境的安裝和配置也會有所不同,所以分別以centos 7.1和ubuntu 14.04做為主機(l)

linux下安裝軟體,最常見有原始碼安裝方式、rpm/deb安裝方式、yum/apt-get安裝方式等,在這裡使用yum/apt-get安裝lamp開發環境

centos 7.1 下安裝lamp開發環境及配置檔案管理

安裝並配置apache

預設安裝的apache版本為httpd-2.4.6-31.el7.centos.x86_64,預設配置檔案主目錄位於/etc/httpd下,/etc/httpd/conf/httpd.conf是apache的主配置檔案,apache模組位於/usr/lib64/httpd/modules目錄下,apache模組的配置檔案位於/etc/httpd/conf.modules.d目錄下,設定禁用或開啟模組可以通過修改該目錄下每個檔案,web根目錄位於/var/www/html目錄下,日誌檔案位於/var/log/httpd目錄下。

重點關注/etc/httpd目錄。這個目錄下,有個conf.d目錄,預設情況下/etc/httpd/conf.d目錄下所有的「.conf」結尾的檔案都會被讀取。因此,很多情況下不需要修改主配置檔案/etc/httpd/conf/httpd.conf,而是在/etc/httpd/conf.d目錄下新建乙個以「.conf」結尾的檔案來完成各種配置。

將apache設定為開機自啟動模式

關閉apache服務

開啟apache服務

安裝並配置mariadb(mysql)

[root@localhost wuxiei]# yum install mariadb-server mariadb

mariadb完全相容mysql,包括api和命令列。centos 從7.x開始預設使用mariadb。

通過內建的安全配置指令碼可實現對資料庫的安全保護

[root@localhost wuxiwei]# /usr/bin/mysql_secure_installation

將mariadb設定為開機啟動

[root@localhost wuxiwei]# systemctl enable mariadb

開啟mariadb服務

[root@localhost wuxiwei]# systemctl start mariadb

關閉mariadb服務

[root@localhost wuxiwei]# systemctl stop mariadb

安裝並配置php

[root@localhost wuxiei]# yum install php php-cli php-pear php-pdo php-mysqlnd php-gd php-mbstring php-mcrypt php-xml

centos 7.1版本中,預設安裝php為php5.4版本,其中php-mysqlnd是php原始碼提供的mysql驅動資料庫。

[root@localhost wuxiwei]# wget

[root@localhost wuxiwei]# rpm -ivh epel-release-7-5.noarch.rpm

[root@localhost wuxiwei]# rpm --import

[root@localhost wuxiwei]# wget

[root@localhost wuxiwei]# rpm -ivh remi-release-7.rpm

預設情況下,remi是禁用的,防止多個yum源發生衝突。可以通過命令檢視remi源是否成功安裝

[root@localhost wuxiwei]# yum repolist disabled | grep remi

搜尋remi源倉庫中可用的包

[root@localhost wuxiwei]# yum --enablerepo=remi list php

[root@localhost wuxiwei]# yum --enablerepo=remi-php56 list php

通過remi源安裝需要的php版本,安裝php5.6版本。

[root@localhost wuxiwei]# yum --enablerepo=remi-php56 install php

ubuntu 14.04 下安裝lamp開發環境及配置檔案管理

安裝並配置apache

[root@localhost wuxiwei]# apt-get install apache2

重啟apache服務

[root@localhost wuxiwei]# service apache2 restart

安裝並配置php5

[root@localhost wuxiwei]# apt-get install php5

檢視apache是否已經正確配置php5

[root@localhost wuxiwei]# cat /etc/apache2/mods_enables/libphp5.so

安裝php5常用擴充套件

[root@localhost wuxiwei]# apt-get install php5-gd curl libcurl3 libcurl3-dev php5-curl

安裝並配置mysql

[root@localhost wuxiwei]# apt-get install mysql-server

檢視php5和mysql是否可以正常資料互動

[root@localhost wuxiwei]# cat /etc/php5.d/conf.d/mysql.ini

手動安裝php5對於mysql擴充套件

[root@localhost wuxiwei]# apt-get install php5-mysql

重啟mysql服務

[root@localhost wuxiwei]# service mysql restart

配置檔案管理

php5配置檔案位於/etc/php5目錄下,核心配置檔案php.ini。

mysql配置檔案位於/etc/mysql目錄下,核心配置檔案my.cnf,預設資料庫儲存位於/var/lin/mysql目錄下。

apache虛擬主機配置

#管理員郵箱

serveradmin [email protected]

#訪問的主機名

servername

wuxiwei.cn

#servername別名,通過別名也可以訪問這個虛擬主機

serveralias www.wuxiwei.cn

#主機目錄

documentroot

/wuxiwei

#指定該目錄啟用followsymlinks特性,none:表示不起用任何的伺服器特性,indexes:如果輸入的**對應伺服器上的乙個目錄,而此目錄中又沒有directorylndex指令(例如:directorylndex index.php index.html),那麼伺服器就會返回由mod_autoindex模組生成的乙個格式化後的目錄列表,並列出該目錄下所有的檔案。

options

followsymlinks

#允許所有都可以訪問

allowoverride

allrequire

all granted

#錯誤日誌

#訪問日誌

lamp環境安裝

安裝 yum install y vsftpd 設定開機啟動 systemctl enable vsftpd.service 啟動systemctl start vsftpd.service 停止systemctl stop vsftpd.service 檢視狀態 systemctl status ...

LAMP環境安裝

1.訪問 ftp報錯 解決方法 關閉selinux vi etc selinux config 內容修改為 selinux disable 之後輸入reboot重啟。2.依賴軟體查詢 一.安裝gcc gcccloog ppl ppl libppl.so.7 libppl c.so.2 cppmpfr...

linux檢視 LAMP環境安裝路徑

如果採用rpm包安裝,安裝路徑應在 etc httpd目錄下 apache配置檔案 etc httpd conf httpd.conf apache模組路徑 usr sbin apachectl web目錄 var www html 如果採用源 安裝,一般預設安裝在 usr local apache...