Hướng dẫn cài đặt LAMP trên CentOS 7.x | Chia sẽ kiến thức Linux/Unix

728x90 AdSpace

Nổi bật
Wednesday, October 4, 2017

Hướng dẫn cài đặt LAMP trên CentOS 7.x

Hướng dẫn cài đặt LAMP trên CentOS 7.x
Bước 1: Cài đặt Apache
- Cài đặt Apache 2.4 bằng lệnh sau:
# yum -y install httpd
- Cấu hình Apache tự khởi động cùng hệ thống
# systemctl enable httpd.service
- Cấu hình firewall cho phép apache chạy qua
# firewall-cmd --permanent --zone=public --add-service=http
# firewall-cmd --permanent --zone=public --add-service=https
# firewall-cmd --reload
- Khởi động Apache
# systemctl start httpd.service
- Kiểm tra hoạt động Apache
Truy cập trình duyệt http://your_ip_server hoặc http://your_domain
http://192.168.2.160/
Bước 2: Cài đặt MySQL/Mariadb
MariaDB là 1 nhánh con được phát triển từ Monty Widenius. Hỗ trợ và tương thích với MySQL. Bài viết sẽ sử dụng MariaDB thay cho MySQL.
- Cài đặt Mariadb theo lệnh:
#yum -y install mariadb-server mariadb
- Cấu hình Mariadb tự khởi động cùng hệ thống
# systemctl enable mariadb.service
- Khởi động MariaDB
# systemctl start mariadb.service
- Cấu hình thông tin quản trị MariaDB
#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: <--Nhập mật khẩu
Re-enter new password: <--Nhập lại mật khẩu
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!
Bước 3: Cài đặt PHP
Đối với CentOS 7.x mặc định cài đặt sẽ là PHP 5.4. Bài viết sẽ hướng dẫn kích hoạt thêm PHP 7.0 và PHP 7.1
- Thêm gói Remi Centos
# rpm -Uvh http://rpms.remirepo.net/enterprise/remi-release-7.rpm
- Cài đặt gói quản trị yum
# yum -y install yum-utils
và chạy lệnh update
# yum updateVới PHP 5.4
# yum -y install php
* Với PHP 7.0
# yum-config-manager --enable remi-php70
# yum -y install php php-opcache
* Với PHP 7.1
# yum-config-manager --enable remi-php71
# yum -y install php php-opcache
* Với PHP 7.2
# yum-config-manager --enable remi-php72
# yum -y install php php-opcache
- Để cài đặt thực thi, phải khởi động Apache
# systemctl restart httpd.service
Bước 4: Kiểm tra hoạt động PHP
Tại thư mục root Apache /var/www/html, khởi tạo PHP file (info.php)
# vi /var/www/html/info.php
<?php
phpinfo();
?>
Truy cập trình duyệt http://your_ip_server/info.php hoặc http://your_domain/info.php
Bước 5: Cài đặt các module PHP
Nếu cài đặt PHP 7.0 hoặc PHP 7.1 thì gói phpxx-tên gói. Ví dụ cài đặt php 7.0 thì gói là php7.0-mysql
Nếu cài gói php5 chúng ta cài module như sau:
# yum -y install php-mysql
# yum -y install php-gd php-ldap php-odbc php-pear php-xml 
php-xmlrpc php-mbstring php-soap curl curl-devel
- Khởi động dịch vụ Apache
# systemctl restart httpd.service
Bước 6: Cài đặt phpMyAdmin
- Cài đặt Epel hỗ trợ chứa gói cài đặt phpMyAdmin
# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY*
# yum -y install epel-release
- Cài đặt phpMyAdmin
# yum -y install phpMyAdmin
- Cấu hình phpMyAdmin
# vi /etc/httpd/conf.d/phpMyAdmin.conf
Thêm Require all granted vào như sau:
- Khởi động dịch vụ Apache
# systemctl restart httpd.service
Truy cập trình duyệt http://your_ip_server/phpmyadmin hoặc http://your_domain/phpmyadmin
http://192.168.2.160/phpmyadmin/

Xem thêm video

Chúc bạn thành công !
Hướng dẫn cài đặt LAMP trên CentOS 7.x Reviewed by HAPPY on 10:46 PM Rating: 5 Hướng dẫn cài đặt LAMP trên CentOS 7.x Bước 1 : Cài đặt Apache - Cài đặt Apache 2.4 bằng lệnh sau: # yum -y install httpd - Cấu hình ...

No comments:

Copyright © 2017 - 2027 Chia sẽ kiến thức Linux/Unix All Right Reserved
Thiết kế bởi HAPPY
Scroll to Top