基於centos7.3 redhat7.3安裝LAMP(php7.0 php7.1)生產環境實踐
#將yum安裝的包緩沖到本地,然後制作本地local_yum
vim /etc/yum.conf
#本機信息
hostname | LAMP |
ip | 192.168.42.10 |
#由於官網yum源下載慢,這裏添加ali源
yum clean all rm -rf /etc/yum.repos.d/*.repo wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo sed -i ‘/aliyuncs/d‘ /etc/yum.repos.d/CentOS-Base.repo sed -i ‘/aliyuncs/d‘ /etc/yum.repos.d/epel.repo sed -i ‘s/$releasever/7/g‘ /etc/yum.repos.d/CentOS-Base.repo
#關閉selinux&firewalld
sed -i ‘s/SELINUX=.*/SELINUX=disabled/‘ /etc/selinux/config setenforce 0 systemctl stop firewalld systemctl disable firewalld
#同步各個節點時間:
yum -y install rdate rdate -s time-a.nist.gov echo rdate -s time-a.nist.gov >> /etc/rc.d/rc.local chmod +x /etc/rc.d/rc.local
#添加EPEL repo來安裝最新的phpMyAdmin如下:
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY* yum -y install epel-release
#MariaDB是MySQL開發人員Monty Widenius的MySQL分支。MariaDB與MySQL兼容,我選擇在這裏使用MariaDB而不是MySQL。運行這個命令來安裝MariaDB和yum:
yum -y install mariadb-server mariadb
#啟動maridb 並設置開機啟動
systemctl start mariadb.service systemctl enable mariadb.service
#設置maridb密碼
mysql_secure_installation
[ [email protected] ~]# mysql_secure_installation /usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MariaDB to secure it, we‘ll need the current password for the root user. If you‘ve just installed MariaDB, and you haven‘t set the root password yet, the password will be blank, so you should just press enter here. Enter current password for root (enter for none): <--ENTER OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MariaDB root user without the proper authorisation. Set root password? [Y/n] New password: <--yourmariadbpassword Re-enter new password: <--yourmariadbpassword Password updated successfully! Reloading privilege tables.. ... Success! By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment.
Remove anonymous users? [Y/n] <--ENTER ... Success! Normally, root should only be allowed to connect from ‘localhost‘. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n] <--ENTER ... Success! By default, MariaDB comes with a database named ‘test‘ that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y/n] <--ENTER - Dropping test database... ... Success! - Removing privileges on test database... ... Success! Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n] <--ENTER ... Success! Cleaning up... All done! If you‘ve completed all of the above steps, your MariaDB installation should now be secure.
Thanks for using MariaDB!
#apache 2.4。Apache包已經提供,因此我們可以這樣安裝它:
yum -y install httpd
#啟動apache 並設置開機啟動
systemctl start httpd.service systemctl enable httpd.service
#如果開啟的防火墻 那麽設置防火墻策略來允許
firewall-cmd --permanent --zone=public --add-service=http firewall-cmd --permanent --zone=public --add-service=https firewall-cmd --reload
#測試apapche是否正常提供網頁
firefox 192.168.42.10
#安裝php
#添加存儲庫
rpm -Uvh http://rpms.remirepo.net/enterprise/remi-release-7.rpm
#安裝yum - utils,因為我們需要yum -config- manager實用程序。
yum -y install yum-utils
安裝php5.4
yum -y install php
#安裝PHP 7.0(可選)
#可以安裝PHP 7.0和Apache PHP 7.0模塊如下:
yum-config-manager --enable remi-php70 yum -y install php php-opcache
#安裝PHP 7.1(可選)
#如果您想使用PHP 7.1,請使用:
yum-config-manager --enable remi-php71 yum -y install php php-opcache
#必須重新啟動Apache來應用更改:
systemctl restart httpd.service
#測試PHP /獲取有關PHP安裝的詳細信息
vim /var/www/html/info.php <?php phpinfo(); ?
#查看測試頁
firefox http://192.168.42.10/info.php
#在PHP中獲得MySQL支持
#為了在PHP中獲得MySQL支持,我們可以安裝php71w - MySQL包。安裝其他PHP模塊也是一個好主意,因為您可能需要它們用於您的應用程序。您可以搜索可用的PHP5模塊:
yum search php
#選擇你需要的,然後安裝:
yum -y install php-mysql
#在接下來的步驟中,我將安裝一些通用的PHP模塊,這些模塊是由CMS系統(如Wordpress、Joomla和Drupal)所要求的:
yum -y install php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-soap curl curl-devel
#重啟apache更改生效
systemctl restart httpd.service
#現在重新加載http://192.168.42.10/info。在您的瀏覽器中,再向下滾動到模塊部分。你現在應該在那裏找到很多像curl這樣的新模塊。
#如果您不再需要php信息輸出,那麽出於安全原因刪除該文件。
rm /var/www/html/info.php
#phpMyAdmin是一個可以管理MySQL數據庫的web界面。
#phpMyAdmin現在可以安裝如下:
yum -y install phpMyAdmin
#現在我們配置phpMyAdmin。我們更改Apache配置,以便phpMyAdmin不僅允許來自本地主機的連接
vim /etc/httpd/conf.d/phpMyAdmin.conf
[...] Alias /phpMyAdmin /usr/share/phpMyAdmin Alias /phpmyadmin /usr/share/phpMyAdmin <Directory /usr/share/phpMyAdmin/> AddDefaultCharset UTF-8 <IfModule mod_authz_core.c> # Apache 2.4 </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/> Options none AllowOverride Limit Require all granted </Directory> [...]
#接下來,我們將phpMyAdmin中的身份驗證更改為http:
vim /etc/phpMyAdmin/config.inc.php
[...] $cfg[‘Servers‘][$i][‘auth_type‘] = ‘http‘; // Authentication method (config, http or cookie based)? [...]
#重啟apache服務
systemctl restart httpd.service
#訪問http://192.168.42.10/phpmyadmin/下phpMyAdmin:
firefox 192.168.42.10/phpmyadmin #密碼為root賬號密碼
#好了 到這裏 LAMP (php7.1)的環境就搭建好了,下一篇,基於LAMP搭建owncloud開源雲盤,有不懂得在評論區留言,看到第一時間回復,轉載請註明出處,創作不易。
本文出自 “宋城西柵” 博客,請務必保留此出處http://limaomao.blog.51cto.com/12623570/1963978
基於centos7.3 redhat7.3安裝LAMP(php7.0 php7.1)生產環境實踐