1. 程式人生 > >linux配置LAMP(CentOS7.4 Apache2.4 PHP5.6)

linux配置LAMP(CentOS7.4 Apache2.4 PHP5.6)

nload isa sin all 80端口 then 安裝PHP5 -c 2.6.0

1、安裝Apache

這個就不手動安裝了,直接上腳本執行

bash apache.sh

以下為腳本的內容:

#!/bin/bash
version=`lsb_release -a|grep Release`
a=${version#*:}
if [ `echo ${a} | awk -v tem=6.8 ‘{print($a<=tem)? "0":"1"}‘` -eq "0" ]
then
#不大於6.8
url="http://ftp.iij.ad.jp/pub/linux/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm"
rpm -Uvh "${url%?}" #
url="http://rpms.famillecollet.com/enterprise/remi-release-6.rpm"
rpm -Uvh "${url%?}" #
else
#大於6.8
yum install epel-release
url="http://rpms.famillecollet.com/enterprise/remi-release-7.rpm"
rpm -Uvh "${url%?}" #
fi
yum install -y --enablerepo=remi --enablerepo=remi-php56 php php-opcache php-devel php-mbstring php-mcrypt php-mysqlnd php-phpunit-PHPUnit php-pecl-xdebug php-pecl-xhprof memcached php-pecl-memcache mysql mysql-server mysql-devel libmemcached libmemcached-devel
yum install -y httpd
service mysqld start
service httpd start

2、安裝PHP

1.刪除以前的php版本(跟上面刪除mysql的命令是一樣的)

先查看

rpm -qa | grep php

再刪除

yum remove 文件名

2. 配置yum源

事先確認yum源的鏈接是不是有效的。

yum install epel-release
rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

3. 確認安裝的php版本

yum list --enablerepo=remi --enablerepo=remi-php56 | grep php

4. 安裝php5.6

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執行速度。

5. 確認php版本

php -v

安裝成功

6.安裝zend Guard

如果你需要將源碼加密,可以使用這個,如果不需要就可以忽略這一步。

不過目前zend Guard最高支持到php5.6的加密,如果你項目用的版本比較高的話,推薦使用Swoole Compiler。

這裏就不多BB了。

zend Guard下載地址:http://www.zend.com/en/products/guard/downloads#Linux

下載完成之後進行解壓

tar -xvf zend-loader-php5.6-linux-x86_64_update1.tar

解壓完成之後打開文件將ZendGuardLoader.so和opcache.so移至擴展庫裏面

cd zend-loader-php5.6-linux-x86_64

cp opcache.so /etc/httpd/modules

cp ZendGuardLoader.so /etc/httpd/modules

配置

vim /etc/php.ini

在最底部添加

zend_extension=/etc/httpd/modules/ZendGuardLoader.so
zend_extension=/etc/httpd/modules/opcache.so
zend_loader.enable=1
zend_loader.disable_licensing=0
zend_loader.obfuscation_level_support=3
zend_loader.license_path=

保存退出重啟apache服務器

systemctl restart httpd.service

再看php版本

php -v

如果顯示

Cannot load Zend OPcache - extension already loaded
PHP 5.6.37 (cli) (built: Jul 19 2018 19:57:52)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
with Zend Guard Loader v3.3, Copyright (c) 1998-2015, by Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
with Xdebug v2.5.5, Copyright (c) 2002-2017, by Derick Rethans

就完全配置好啦~!

測試

vim /var/www/html/index.php

<?php

phpinfo();

?>

退出保存,訪問你的域名或者ip地址,別忘了阿裏雲上設置安全組,放開80端口。

3、安裝Composer

1.安裝composer

php -r "copy(‘https://install.phpcomposer.com/installer‘, ‘composer-setup.php‘);"
php composer-setup.php
php -r "unlink(‘composer-setup.php‘);"

2.配置全局

sudo mv composer.phar /usr/local/bin/composer


linux配置LAMP(CentOS7.4 Apache2.4 PHP5.6)