您好,登錄后才能下訂單哦!
這篇文章主要介紹Centos7.4環境如何安裝lamp-php7.0,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!
本文實例講述了Centos7.4環境安裝lamp-php7.0的方法。分享給大家供大家參考,具體如下:
一. 環境準備
橋接模式
能訪問外網
#ping www.baidu.com
ping得通則能到外網
關閉防火墻
#systemctl disable firewalld //禁用防火墻 #systemctl stop firewalld //關閉防火墻
關閉seLinux
#vim /etc/selinux/config
改為:
SELINUX=disabled
配置yum源
# cd /etc/yum.repos.d/ # mkdir repo_bak //創建備份源文件夾 # mv *.repo repo_bak/ //將源文件都放到備份文件夾 # wget http://mirrors.aliyun.com/repo/Centos-7.repo //配置阿里源 # wget http://mirrors.163.com/.help/CentOS7-Base-163.repo //配置網易源 # ls //列出/etc/yum.repos.d/目錄下的文件 Centos-7.repo CentOS-Base-163.repo repo.bak # yum clean all //清除系統所有yum緩存 # yum makecache //生成yum緩存 # yum list | grep epel-release //查看epel源列表 # yum install -y epel-release //安裝epel源 # ls //epel源安裝成功,比原來多了一個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 //再次清除系統yum緩存 # yum makecache //重新生成新的yum緩存 # yum repolist enabled //查看系統可用的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
修改默認Web站點目錄
找到: DocumentRoot "/var/www/html"
修改為: DocumentRoot "/var/www"
找到:<Directory "/var/www/html">
修改為:<Directory "/var/www">
3. 啟動Apache服務
# systemctl start httpd
4. 查看httpd狀態
systemctl status httpd
三. PHP 7.0.7
1. 下載好對應版本的centos的PHP源碼包
php-7.0.7.tar.gz
2. 解壓源碼包
# tar zxvf php-7.0.7.tar.gz
3. 進入解壓包編譯安裝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 編譯參數的時候用到,是配置Apache支持PHP的關鍵參數
4. 編譯參數
./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 添加環境變量
# vim /etc/profil
添加進去
PATH=$PATH:/usr/local/php/bin export PATH
9. 更新環境變量
# source /etc/profile
10. 查看環境變量
# 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 # 配置錯誤日志: # # 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. 啟動php-fpm
配置開機啟動php-fpm:
# systemctl enable php-fpm
啟動php-fpm
# systemctl start php-fpm
查看狀態
# 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 #啟動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 #關閉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然后保存
//重新啟動系統 # reboot
16. 重啟Apache和php-fpm
# systcl restart httpd # systcl restart php-fpm
17. 安裝 對應的xdebug
#復制phpinfo.php整個網頁內容,粘貼到https://xdebug.org/wizard.php 確定Xdebug版本
根據提示文檔進行操作安裝
18. yum安裝PHPMyAdmin
# yum install phpmyadmin
修改配置文件
# vi /etc/httpd/conf.d/phpMyAdmin.conf
<Directory /usr/share/phpMyAdmin/> AddDefaultCharset UTF-8 <IfModule mod_authz_core.c> # Apache 2.4 <RequireAny> # Require ip 127.0.0.1 #注釋掉 # Require ip ::1 #注釋掉 Require all granted #新添加 </RequireAny> </IfModule> <IfModule !mod_authz_core.c> # Apache 2.2 Order Deny,Allow Deny from All Allow from 127.0.0.1 Allow from ::1 </IfModule> </Directory> <Directory /usr/share/phpMyAdmin/setup/> <IfModule mod_authz_core.c> # Apache 2.4 <RequireAny> #Require ip 127.0.0.1 #注釋掉 #Require ip ::1 #注釋掉 Require all granted #新添加 </RequireAny> </IfModule> <IfModule !mod_authz_core.c> # Apache 2.2 Order Deny,Allow Deny from All Allow from 127.0.0.1 Allow from ::1 </IfModule> </Directory>
修改phpmyadmin配置文件
# vi /etc/phpMyAdmin/config.inc.php //修改如下內容 # $cfg['Servers'][$i]['host'] = '127.0.0.1'; # $cfg['Servers'][$i]['user'] = 'root'; # $cfg['Servers'][$i]['password'] = '123456';
重啟Apache
# systemctl restart httpd
安裝完MySQL后測試
# 瀏覽器地址欄輸入: 服務器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. 啟動MySQL
# systemctl start mysqld # systemctl enable mysqld //開機自啟
4. 在更改root默認密碼前,可以根據需要,關閉密碼策略。 如果沒有關閉密碼策略,則新密碼要求是大小寫字母+數字+字符的組合。
# vim /etc/my.cnf [mysqld] validate_password = off //重啟,使修改后的密碼策略生效 # systemctl restart mysqld
5. 修改MySQL的root默認密碼
//查看默認密碼 # grep 'temporary password' /var/log/mysqld.log //默認密碼是: )U4FB:Kw!evF # 2018-12-18 A temporary password is generated for root@localhost: )U4FB:Kw!evF
運行安全設置向導,并修改默認密碼
mysql_secure_installation //輸入root默認密碼 Enter password for user root: *** //設置新密碼 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遠程登錄 Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y //刪除test數據庫 Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y //重新加載權限表 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僅限本地登錄,根據需要可以新建一個有管理員權限的遠程用戶 mysql -uroot -p GRANT ALL PRIVILEGES ON *.* TO '用戶名'@'%' IDENTIFIED BY '登錄密碼' WITH GRANT OPTION; FLUSH PRIVILEGES; exit;
安裝完成
以上是“Centos7.4環境如何安裝lamp-php7.0”這篇文章的所有內容,感謝各位的閱讀!希望分享的內容對大家有幫助,更多相關知識,歡迎關注億速云行業資訊頻道!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。