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:
1# yum -y install httpd
- Cấu hình Apache tự khởi động cùng hệ thống1# systemctl enable httpd.service
- Cấu hình firewall cho phép apache chạy qua123# firewall-cmd --permanent --zone=public --add-service=http
# firewall-cmd --permanent --zone=public --add-service=https
# firewall-cmd --reload
- Khởi động Apache1# systemctl start httpd.service
- Kiểm tra hoạt động ApacheTruy 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:
1#yum -y install mariadb-server mariadb
- Cấu hình Mariadb tự khởi động cùng hệ thống1# systemctl enable mariadb.service
- Khởi động MariaDB1# systemctl start mariadb.service
- Cấu hình thông tin quản trị MariaDB1#mysql_secure_installation
/usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not foundNOTE: 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
1# rpm -Uvh http://rpms.remirepo.net/enterprise/remi-release-7.rpm
- Cài đặt gói quản trị yum1# yum -y install yum-utils
và chạy lệnh update# yum updateVới PHP 5.4
1# yum -y install php
* Với PHP 7.012# yum-config-manager --enable remi-php70
# yum -y install php php-opcache
* Với PHP 7.112# 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
1# systemctl restart httpd.service
Bước 4: Kiểm tra hoạt động PHPTại thư mục root Apache /var/www/html, khởi tạo PHP file (info.php)
1# vi /var/www/html/info.php
123<?php
phpinfo();
?>
Truy cập trình duyệt http://your_ip_server/info.php hoặc http://your_domain/info.phpBướ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:
1# yum -y install php-mysql
1# yum -y install php-gd php-ldap php-odbc php-pear php-xml
1php-xmlrpc php-mbstring php-soap curl curl-devel
- Khởi động dịch vụ Apache1# 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
12# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY*
# yum -y install epel-release
- Cài đặt phpMyAdmin1# yum -y install phpMyAdmin
- Cấu hình phpMyAdmin1# vi /etc/httpd/conf.d/phpMyAdmin.conf
Thêm Require all granted vào như sau:- Khởi động dịch vụ Apache
1# systemctl restart httpd.service
Truy cập trình duyệt http://your_ip_server/phpmyadmin hoặc http://your_domain/phpmyadminhttp://192.168.2.160/phpmyadmin/
Xem thêm video
Chúc bạn thành công !