這篇文章主要講解了“Centos環(huán)境怎么安裝lamp-php”,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來(lái)研究和學(xué)習(xí)“Centos環(huán)境怎么安裝lamp-php”吧!
創(chuàng)新互聯(lián)是專(zhuān)業(yè)的城固網(wǎng)站建設(shè)公司,城固接單;提供網(wǎng)站建設(shè)、網(wǎng)站設(shè)計(jì),網(wǎng)頁(yè)設(shè)計(jì),網(wǎng)站設(shè)計(jì),建網(wǎng)站,PHP網(wǎng)站建設(shè)等專(zhuān)業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行城固網(wǎng)站開(kāi)發(fā)網(wǎng)頁(yè)制作和功能擴(kuò)展;專(zhuān)業(yè)做搜索引擎喜愛(ài)的網(wǎng)站,專(zhuān)業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來(lái)合作!一. 環(huán)境準(zhǔn)備
橋接模式
能訪問(wè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源安裝成功,比原來(lái)多了一個(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. 下載好對(duì)應(yīng)版本的centos的php源碼包
php-7.0.7.tar.gz
2. 解壓源碼包
# tar zxvf php-7.0.7.tar.gz
3. 進(jìn)入解壓包編譯安裝php所需要的依賴(lài)包
# 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
配置開(kāi)機(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. 測(cè)試php-fpm的配置
#測(cè)試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. 安裝 對(duì)應(yīng)的xdebug
#復(fù)制phpinfo.php整個(gè)網(wǎng)頁(yè)內(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后測(cè)試
# 瀏覽器地址欄輸入: 服務(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 //開(kāi)機(jī)自啟
4. 在更改root默認(rèn)密碼前,可以根據(jù)需要,關(guān)閉密碼策略。 如果沒(méi)有關(guān)閉密碼策略,則新密碼要求是大小寫(xiě)字母+數(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) ://直接回車(chē),表示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ù)庫(kù) 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;
感謝各位的閱讀,以上就是“Centos環(huán)境怎么安裝lamp-php”的內(nèi)容了,經(jīng)過(guò)本文的學(xué)習(xí)后,相信大家對(duì)Centos環(huán)境怎么安裝lamp-php這一問(wèn)題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是創(chuàng)新互聯(lián)網(wǎng)站建設(shè)公司,,小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!