在VM下安裝了centos7體驗一下,首先安裝一下LAMP環境,以下:php
安裝LAMP環境:mysql
一、apache2linux
# yum install -y httpd # systemctl start httpd.service 啓動 # systemctl enable httpd.service 開機自動啓動 # vi /etc/httpd/conf/httpd.conf 默認配置文件 # systemctl restart httpd.service 重啓
二、mysqlnginx
# wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
centOS最小安裝,wget沒有安裝sql
# yum install -y wget # rpm -ivh mysql-community-release-el7-5.noarch.rpm # yum install mysql-community-server
成功安裝以後重啓mysql服務apache
# service mysqld restart
三、php5.6ubuntu
# yum install --enablerepo=remi --enablerepo=remi-php56 php php-opcache php-pecl-apcu php-devel php-mbstring php-mcrypt php-mysqlnd php-phpunit-PHPUnit php-pecl-xdebug php-pecl-xhprof php-pdo php-pear php-fpm php-cli php-xml php-bcmath php-process php-gd php-common
php-opcache及php-pecl-apcu會有效的提升php執行速度。centos
# php -v PHP 5.6.19 (cli) (built: Mar 3 2016 07:57:20) Copyright (c) 1997-2016 The PHP Group Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies with Xdebug v2.4.0, Copyright (c) 2002-2016, by Derick Rethans
注意要點:bash
一、Apache2.4目錄權限有變動:服務器
Order Deny,Allow Allow from All
換成
Require all granted
二、安裝成功後要去掉目錄預覽頁
cd /etc/httpd/conf.d touch welcome.conf welcome #不去掉的話,訪問老是apache提示頁
三、Vhost
NameVirtualHost *:80 #虛擬主機,新的2.4版本,這個指令不須要
四、虛擬主機設置,命令以下
<VirtualHost *:80> DirectoryIndex index.php ServerAdmin 123456@qq.com DocumentRoot /www/lockcom ServerName lock.com ServerAlias lock.com <Directory /www/lockcom> Options Indexes FollowSymLinks AllowOverride None Require all granted </Directory> </VirtualHost>
五、要注意iptables/firewall,若是iptables啓用了,要加一個指令,以便80端口能夠訪問
iptables:
/usr/sbin/iptables -I INPUT -p TCP --dport 80 -j ACCEPT
firewall:
firewall-cmd --zone=public --add-port=80/tcp --permanent 命令含義: --zone #做用域 --add-port=80/tcp #添加端口,格式爲:端口/通信協議 --permanent #永久生效,沒有此參數重啓後失效 firewall-cmd --reload #重啓防火牆
六、selinux
若是啓用了必需要關掉,不然訪問虛擬主機域名時,會出現這個錯誤
forbidden you don't have permission to access / on this serve
這個錯誤查看apache錯誤日誌才發現的,原來是selinux啓用致使的。花了我很長時間找錯誤。長時間的不弄服務器,許多要點都忘記了
檢測是否啓用selinux
getenforce
若是顯示「Enforcing」,則要關閉,命令以下:
setenforce 0
vi /etc/selinux/config,找到SELINUX 行修改爲爲:SELINUX=disabled: # This file controls the state of SELinux on the system. # SELINUX= can take one of these three values: # enforcing - SELinux security policy is enforced. # permissive - SELinux prints warnings instead of enforcing. # disabled - No SELinux policy is loaded. SELINUX=disabled # SELINUXTYPE= can take one of these two values: # targeted - Only targeted network daemons are protected. # strict - Full SELinux protection. SELINUXTYPE=targeted 重啓系統。 Centos還提供了實時改變SELinux工做模式的工具,前提是SELinux沒有被disabled掉的時候 /usr/sbin/setenforce 0 #使SELinux工做模式變成permissive模式 /usr/sbin/setenforce 1 #使SELinux工做模式變成enforcing模式
七、開機啓動
#vi /etc/rc.local /bin/systemctl start httpd.service /bin/systemctl start nginx.service #chmod +x /etc/rc.d/rc.local 必須加可執行權限,否則開機不能啓動
最後預祝各位同窗順利安裝成功,下一篇會說apache加nginx作反向代理~