您好,登錄后才能下訂單哦!
這篇文章主要講解了“Centos環境怎么安裝lamp-php”,文中的講解內容簡單清晰,易于學習與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學習“Centos環境怎么安裝lamp-php”吧!
一. 環境準備
橋接模式
能訪問外網
#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;
感謝各位的閱讀,以上就是“Centos環境怎么安裝lamp-php”的內容了,經過本文的學習后,相信大家對Centos環境怎么安裝lamp-php這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是億速云,小編將為大家推送更多相關知識點的文章,歡迎關注!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。