這篇文章主要介紹Centos7.4環(huán)境如何安裝lamp-php7.0,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!
超過十多年行業(yè)經(jīng)驗(yàn),技術(shù)領(lǐng)先,服務(wù)至上的經(jīng)營模式,全靠網(wǎng)絡(luò)和口碑獲得客戶,為自己降低成本,也就是為客戶降低成本。到目前業(yè)務(wù)范圍包括了:做網(wǎng)站、成都網(wǎng)站設(shè)計(jì),成都網(wǎng)站推廣,成都網(wǎng)站優(yōu)化,整體網(wǎng)絡(luò)托管,微信小程序,微信開發(fā),成都app軟件開發(fā),同時(shí)也可以讓客戶的網(wǎng)站和網(wǎng)絡(luò)營銷和我們一樣獲得訂單和生意!本文實(shí)例講述了Centos7.4環(huán)境安裝lamp-php7.0的方法。分享給大家供大家參考,具體如下:
一. 環(huán)境準(zhǔn)備
橋接模式
能訪問外網(wǎng)
#ping www.baidu.com
ping得通則能到外網(wǎng)
關(guān)閉防火墻
#systemctl disable firewalld //禁用防火墻 #systemctl stop firewalld //關(guān)閉防火墻
關(guān)閉seLinux
#vim /etc/selinux/config
改為:
SELINUX=disabled
配置yum源
# cd /etc/yum.repos.d/ # mkdir repo_bak //創(chuàng)建備份源文件夾 # mv *.repo repo_bak/ //將源文件都放到備份文件夾 # wget http://mirrors.aliyun.com/repo/Centos-7.repo //配置阿里源 # wget http://mirrors.163.com/.help/CentOS7-Base-163.repo //配置網(wǎng)易源 # ls //列出/etc/yum.repos.d/目錄下的文件 Centos-7.repo CentOS-Base-163.repo repo.bak # yum clean all //清除系統(tǒng)所有yum緩存 # yum makecache //生成yum緩存 # yum list | grep epel-release //查看epel源列表 # yum install -y epel-release //安裝epel源 # ls //epel源安裝成功,比原來多了一個(gè)epel.repo和epel-testing.repo文件 Centos-7.repo CentOS-Base-163.repo epel.repo epel-testing.repo repo.bak # wget -O /etc/yum.repos.d/epel-7.repo http://mirrors.aliyun.com/repo/epel-7.repo //下載阿里源的epel源 # ls CentOS7-Base-163.repo Centos-7.repo epel-7.repo epel.repo epel-testing.repo repo_bak # yum clean all //再次清除系統(tǒng)yum緩存 # yum makecache //重新生成新的yum緩存 # yum repolist enabled //查看系統(tǒng)可用的yum源 # yum repolist all //查看所有yum源
刪除舊版本
# yum -y remove php
二. Apache
1. 安裝Apache
# yum install httpd
2. 配置Apache
# vim /etc/httpd/conf/httpd.conf //搜索 # AddType application/x-gzip .gz .tgz //然后在后面添加 # AddType application/x-httpd-php .php //搜索 # IfModule dir_module //在DirectoryIndex下面添加 index.php //修改#ServerName www.example.com:80 # ServerName localhost:80
修改默認(rèn)Web站點(diǎn)目錄
找到: DocumentRoot "/var/www/html"
修改為: DocumentRoot "/var/www"
找到:
修改為:
3. 啟動(dòng)Apache服務(wù)
# systemctl start httpd
4. 查看httpd狀態(tài)
systemctl status httpd
三. PHP 7.0.7
1. 下載好對應(yīng)版本的centos的PHP源碼包
php-7.0.7.tar.gz
2. 解壓源碼包
# tar zxvf php-7.0.7.tar.gz
3. 進(jìn)入解壓包編譯安裝php所需要的依賴包
# yum install -y gcc gcc-c++ make automake autoconf gd file bison patch mlocate flex diffutils zlib zlib-devel pcre pcre-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel libcurl libcurl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers openldap-devellibxslt-devel kernel-devel libtool-libs readline-devel gettext-devel libcap-devel php-mcrypt libmcrypt libmcrypt-devel recode-devel gmp-devel icu libxslt libxslt-devel php-devel # yum -y install libxslt-devel* # yum -y install perl* # yum -y install httpd-devel # find / -name apxs //得到的路徑是:/usr/bin/apxs 編譯參數(shù)的時(shí)候用到,是配置Apache支持PHP的關(guān)鍵參數(shù)
4. 編譯參數(shù)
./configure \
--prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--with-zlib-dir \
--with-freetype-dir \
--enable-mbstring \
--with-libxml-dir=/usr \
--enable-xmlreader \
--enable-xmlwriter \
--enable-soap \
--enable-calendar \
--with-curl \
--with-zlib \
--with-gd \
--with-pdo-sqlite \
--with-pdo-mysql \
--with-mysqli \
--with-mysql-sock \
--enable-mysqlnd \
--disable-rpath \
--enable-inline-optimization \
--with-bz2 \
--with-zlib \
--enable-sockets \
--enable-sysvsem \
--enable-sysvshm \
--enable-pcntl \
--enable-mbregex \
--enable-exif \
--enable-bcmath \
--with-mhash \
--enable-zip \
--with-pcre-regex \
--with-jpeg-dir=/usr \
--with-png-dir=/usr \
--with-openssl \
--enable-ftp \
--with-kerberos \
--with-gettext \
--with-xmlrpc \
--with-xsl \
--enable-fpm \
--with-fpm-user=php-fpm \
--with-fpm-group=php-fpm \
--with-fpm-systemd \
--with-apsx2 \
--disable-fileinfo
6. 編譯并安裝
# make && make install
7. 安裝完查看PHP版本
# /usr/local/php/bin/php -v
8. 編輯 /etc/profil 添加環(huán)境變量
# vim /etc/profil
添加進(jìn)去
PATH=$PATH:/usr/local/php/bin export PATH
9. 更新環(huán)境變量
# source /etc/profile
10. 查看環(huán)境變量
# echo $PATH
11. 查看PHP版本
# php -v
12. 配置PHP配置文件php-fpm
# cp php.ini-production /etc/php.ini # cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf # cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf # cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm # chmod +x /etc/init.d/php-fpm # vim /usr/local/php/etc/php-fpm.conf # 配置錯(cuò)誤日志: # # error_log = /usr/local/php/var/php-fpm.log # # 配置pid文件: # # pid = /usr/local/php/var/run/php-fpm.pid # # 保存退出 # cd /usr/local/src/php-7.2.4 # cp ./sapi/fpm/php-fpm.service 到 /usr/lib/systemd/system/下
13. 啟動(dòng)php-fpm
配置開機(jī)啟動(dòng)php-fpm:
# systemctl enable php-fpm
啟動(dòng)php-fpm
# systemctl start php-fpm
查看狀態(tài)
# systemctl status php-fpm ● php-fpm.service – The PHP FastCGI Process Manager Loaded: error (Reason: Invalid argument) Active: inactive (dead) Dec 13 14:37:27 localhost.localdomain systemd[1]: [/usr/lib/systemd/system/php-fpm.service:7] Not an absolute path, ignoring: ${prefix}/va…fpm.pid Dec 13 14:37:27 localhost.localdomain systemd[1]: [/usr/lib/systemd/system/php-fpm.service:8] Executable path is not absolute, ignoring: $…pm.conf Dec 13 14:37:27 localhost.localdomain systemd[1]: php-fpm.service lacks both ExecStart= and ExecStop= setting. Refusing. Dec 13 14:37:27 localhost.localdomain systemd[1]: Cannot add dependency job for unit php-fpm.service, ignoring: Unit is not loaded properl…gument. Hint: Some lines were ellipsized, use -l to show in full.
14. 測試php-fpm的配置
#測試php-fpm配置 /usr/local/php/sbin/php-fpm -t /usr/local/php/sbin/php-fpm -c /usr/local/php/etc/php.ini -y /usr/local/php/etc/php-fpm.conf -t #啟動(dòng)php-fpm /usr/local/php/sbin/php-fpm /usr/local/php/sbin/php-fpm -c /usr/local/php/etc/php.ini -y /usr/local/php/etc/php-fpm.conf #關(guān)閉php-fpm kill -INT `cat /usr/local/php/var/run/php-fpm.pid` #重啟php-fpm kill -USR2 `cat /usr/local/php/var/run/php-fpm.pid`
15. 解決辦法
# vim /usr/lib/systemd/system/php-fpm.service
將其中的${prefix}和${exec_prefix}改成/usr/local/php然后保存
//重新啟動(dòng)系統(tǒng) # reboot
16. 重啟Apache和php-fpm
# systcl restart httpd # systcl restart php-fpm
17. 安裝 對應(yīng)的xdebug
#復(fù)制phpinfo.php整個(gè)網(wǎng)頁內(nèi)容,粘貼到https://xdebug.org/wizard.php 確定Xdebug版本
根據(jù)提示文檔進(jìn)行操作安裝
18. yum安裝PHPMyAdmin
# yum install phpmyadmin
修改配置文件
# vi /etc/httpd/conf.d/phpMyAdmin.conf
AddDefaultCharset UTF-8 # Apache 2.4 # Require ip 127.0.0.1 #注釋掉 # Require ip ::1 #注釋掉 Require all granted #新添加 # Apache 2.2 Order Deny,Allow Deny from All Allow from 127.0.0.1 Allow from ::1 # Apache 2.4 #Require ip 127.0.0.1 #注釋掉 #Require ip ::1 #注釋掉 Require all granted #新添加 # Apache 2.2 Order Deny,Allow Deny from All Allow from 127.0.0.1 Allow from ::1
修改phpmyadmin配置文件
# vi /etc/phpMyAdmin/config.inc.php //修改如下內(nèi)容 # $cfg['Servers'][$i]['host'] = '127.0.0.1'; # $cfg['Servers'][$i]['user'] = 'root'; # $cfg['Servers'][$i]['password'] = '123456';
重啟Apache
# systemctl restart httpd
安裝完MySQL后測試
# 瀏覽器地址欄輸入: 服務(wù)器ip/phpMyAdmin
四. 安裝MySQL 5.7
1. 安裝源
# rpm -Uvh https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
2. yum安裝MySQL
# yum install mysql-community-server
3. 啟動(dòng)MySQL
# systemctl start mysqld # systemctl enable mysqld //開機(jī)自啟
4. 在更改root默認(rèn)密碼前,可以根據(jù)需要,關(guān)閉密碼策略。 如果沒有關(guān)閉密碼策略,則新密碼要求是大小寫字母+數(shù)字+字符的組合。
# vim /etc/my.cnf [mysqld] validate_password = off //重啟,使修改后的密碼策略生效 # systemctl restart mysqld
5. 修改MySQL的root默認(rèn)密碼
//查看默認(rèn)密碼 # grep 'temporary password' /var/log/mysqld.log //默認(rèn)密碼是: )U4FB:Kw!evF # 2018-12-18 A temporary password is generated for root@localhost: )U4FB:Kw!evF
運(yùn)行安全設(shè)置向?qū)В⑿薷哪J(rèn)密碼
mysql_secure_installation //輸入root默認(rèn)密碼 Enter password for user root: *** //設(shè)置新密碼 New password:*** Re-enter new password: *** //是否更改root密碼 Change the password for root ? ((Press y|Y for Yes, any other key for No) ://直接回車,表示No //是否刪除匿名用戶 Remove anonymous users? (Press y|Y for Yes, any other key for No) : y //禁止root遠(yuǎn)程登錄 Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y //刪除test數(shù)據(jù)庫 Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y //重新加載權(quán)限表 Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
//也可以使用mysql直接更改root密碼 mysql -uroot -p ALTER USER 'root'@'localhost' IDENTIFIED BY '新密碼'; exit;
//為安全root僅限本地登錄,根據(jù)需要可以新建一個(gè)有管理員權(quán)限的遠(yuǎn)程用戶 mysql -uroot -p GRANT ALL PRIVILEGES ON *.* TO '用戶名'@'%' IDENTIFIED BY '登錄密碼' WITH GRANT OPTION; FLUSH PRIVILEGES; exit;
安裝完成
以上是“Centos7.4環(huán)境如何安裝lamp-php7.0”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對大家有幫助,更多相關(guān)知識,歡迎關(guān)注創(chuàng)新互聯(lián)成都網(wǎng)站設(shè)計(jì)公司行業(yè)資訊頻道!
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。