本文實(shí)例講述了Centos7.4環(huán)境安裝lamp-php7.0的方法。分享給大家供大家參考,具體如下:
一. 環(huán)境準(zhǔn)備
橋接模式
能訪問外網(wǎng)
ping得通則能到外網(wǎng)
關(guān)閉防火墻
#systemctl disable firewalld //禁用防火墻
#systemctl stop firewalld //關(guān)閉防火墻
關(guān)閉seLinux
改為:
配置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源安裝成功,比原來多了一個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源
刪除舊版本
二. Apache
1. 安裝Apache
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"
找到:<Directory "/var/www/html">
修改為:<Directory "/var/www">
3. 啟動Apache服務(wù)
4. 查看httpd狀態(tài)
三. PHP 7.0.7
1. 下載好對應(yīng)版本的centos的PHP源碼包
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. 編譯并安裝
7. 安裝完查看PHP版本
# /usr/local/php/bin/php -v
8. 編輯 /etc/profil 添加環(huán)境變量
添加進(jìn)去
PATH=$PATH:/usr/local/php/bin
export PATH
9. 更新環(huán)境變量
10. 查看環(huán)境變量
11. 查看PHP版本
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
配置開機(jī)啟動php-fpm:
# systemctl enable php-fpm
啟動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
#啟動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然后保存
16. 重啟Apache和php-fpm
# systcl restart httpd
# systcl restart php-fpm
17. 安裝 對應(yīng)的xdebug
#復(fù)制phpinfo.php整個網(wǎng)頁內(nèi)容,粘貼到https://xdebug.org/wizard.php 確定Xdebug版本
根據(jù)提示文檔進(jìn)行操作安裝
18. yum安裝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
//修改如下內(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. 啟動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ū)?,并修改默認(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ù)需要可以新建一個有管理員權(quán)限的遠(yuǎn)程用戶
mysql -uroot -p
GRANT ALL PRIVILEGES ON *.* TO '用戶名'@'%' IDENTIFIED BY '登錄密碼' WITH GRANT OPTION;
FLUSH PRIVILEGES;
exit;
安裝完成
希望本文所述對大家CentOS服務(wù)器配置有所幫助。