LAMP環境(linux+apache+mysql+php)配置

來源:互聯網
上載者:User

標籤:mysql   apache   yum   lamp   selinux   

1、理論部分

LAMP 是Linux Apache MySQL PHP的簡寫,其實就是把Apache, MySQL以及PHP安裝在Linux系統上,組成一個環境來運行php的指令碼語言。

本文是測試Apache與PHP結合和創,搭建方法採用非常標準手法(開啟SELinux),初學者可以直接使用。

2、實驗部分

2.1、實驗環境

lampSer:

hostname=lamp

ipaddress=10.168.0.170


client:

hostnmae=client

ipaddress=10.168.0.8

2.2、yum源的安裝

In lampSer

yum -y install httpd php mysql mysql-server php-mysqlyum -y install policycoreutils-python

2.3、配置部分

In lampSer

2.3.1、step1

註:如果你不想瞭解php的載入方式本步驟請直接跳過

檢查是否引入php模組(預設開啟),主設定檔:

grep ^Include /etc/httpd/conf/httpd.conf

包含如下內容:

Include conf.d/*.conf

查看PHP支援模組設定檔:

less /etc/httpd/conf.d/php.conf

包含如下內容:

<IfModule prefork.c>  LoadModule php5_module modules/libphp5.so</IfModule><IfModule worker.c>  LoadModule php5_module modules/libphp5-zts.so</IfModule>AddHandler php5-script .phpAddType text/html .phpDirectoryIndex index.php

2.3.2、step2

啟動httpd&mysqld服務:

/etc/init.d/httpd startchkconfig httpd on/etc/init.d/mysqld startchkconfig mysqld on

註:關於MySQL的安全配置請運行,這裡不再詳述!

mysql_secure_installation

2.3.3、step3

配置httpd服務

1)啟用並更改ServerName(去掉ServerName前面的#):

ServerName www.cmdschool.org:80

2)建立虛擬目錄:

mkdir /var/www/wwww.cmdschool.org

3)添加測試頁面:

echo ‘<?php phpinfo(); ?>‘ > /var/www/www.cmdschool.org/index.php

4)確保selinux是Enforcing狀態:

getenforce

5)恢複預設的selinux type:

restorecon -RFvv /var/www/www.cmdschool.org/

顯示如下:

restorecon reset /var/www/www.cmdschool.org/index.php context unconfined_u:object_r:httpd_sys_content_t:s0->system_u:object_r:httpd_sys_content_t:s0

6)檢查當前的selinux type:

ll -dZ /var/www/www.cmdschool.org/

7)設定虛擬目錄:

vim編輯/etc/httpd/conf.d/www.cmdschool.org.conf

<VirtualHost *:80>    DocumentRoot /var/www/www.cmdschool.org    ServerName www.cmdschool.org</VirtualHost><Directory /var/www/www.cmdschool.org>    Options All    AllowOverride all</Directory>

8)重啟apache服務:

/etc/init.d/httpd restart

2.3.4、step4

設定防火牆:

vim編輯/etc/sysconfig/iptables

-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

重啟防火牆:

/etc/init.d/iptables restart

2.4.5、step5

In lampSer

測試伺服器

1)vim編輯/etc/hosts

確保包含www.cmdschool.org的指向10.168.0.170的唯一值:

10.168.0.170 www.cmdschool.org

2)curl測試

curl www.cmdschool.org

參閱資料:

官方參閱資料

http://www.php.net/manual/zh/

http://php.net/manual/zh/install.unix.apache2.php

http://linux.vbird.org/linux_basic/0440processcontrol.php#semanage


本文出自 “老譚linux部落格” 部落格,請務必保留此出處http://cmdschool.blog.51cto.com/2420395/1708325

LAMP環境(linux+apache+mysql+php)配置

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.