Hướng dẫn cài đặt LEMP trên CentOS 7.x
Bước 1: Cài đặt yum cập nhật gói mới nhất cho CentOS 7.x# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY*
# yum -y install epel-releaseBước 2: Cài đặt MySQL/MariaDB
- Cài đặt MariaDB theo lệnh sau:
# yum -y install mariadb-server mariadb- Cấu hình dịch vụ Mariadb khởi động cùng hệ thống
# systemctl enable mariadb.service- Khởi động dịch vụ Mariadb
# systemctl start mariadb.service- Cài đặt mật khẩu 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!
- Kiểm tra
# mysql -u root -p
Bước 3: Cài đặt Nginx,PHP
- Kích hoạt gói cài đặt phiên bản PHP
# rpm -Uvh http://rpms.remirepo.net/enterprise/remi-release-7.rpm # yum -y install yum-utils # yum-config-manager --enable remi-phpxx* PHP 5.4
# yum install -y nginx php-fpm php
* PHP 5.5
# yum-config-manager --enable remi-php55
* PHP 5.6
# yum-config-manager --enable remi-php56
* PHP 7.0
# yum-config-manager --enable remi-php70
* PHP 7.1
# yum-config-manager --enable remi-php71
- Cài đặt Nginx,PHP-FPM
# yum install -y nginx php-fpm php- Tắt dịch vụ Apache
# systemctl stop httpd.service # systemctl disable httpd.service- Cấu hình Nginx tự khởi động cùng hệ thống
# systemctl enable nginx.service- Khởi động dịch vụ Nginx
# systemctl start nginx.service- Cho phép Nginx hoạt động qua Firewalld
# firewall-cmd --permanent --zone=public --add-service=http # firewall-cmd --permanent --zone=public --add-service=https # firewall-cmd --reloadTruy cập link http://your_ip_server hoặc http://your_server
Bước 4: Cài đặt Module PHP
# yum install -y php-opcache php-pecl-apcu php-cli php-pear php-pdo php-mysqlnd php-pgsql php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-gd php-mbstring php-mcrypt php-xml php-soap curl curl-devel php-intl php-mysqlBước 5: Cấu hình Nginx, PHP-FPM
# vi /etc/php.ini- Chỉnh theo dòng như sau:
cgi.fix_pathinfo=0
date.timezone = Asia/Ho_Chi_Minh
- Cấu hình PHP-FPM
# vi /etc/php-fpm.d/www.confuser = nginx
group = nginx
listen.owner = nginx
listen.group = nginx
- Khởi động dịch vụ PHP-FPM
# systemctl start php-fpm # systemctl enable php-fpm- Cấu hình Virtual Host Nginx
# vi /etc/nginx/conf.d/default.conf
# # The default server # server { listen 80; server_name localhost;# Tên server của bạn location / { root /usr/share/nginx/html; # Nơi chứa thông tin website index index.php index.html index.htm; try_files $uri $uri/ /index.php?q=$uri&$args; } error_page 404 /404.html; location = /404.html { root /usr/share/nginx/html; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { root /usr/share/nginx/html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }- Khởi động dịch vụ Nginx
# systemctl restart nginx.serviceBước 6: Kiểm tra hoạt động PHP
- Khởi tạo file PHP
# vi /usr/share/nginx/html/info.php
<?php phpinfo(); ?>- Khởi động dịch vụ Nginx, PHP-FPM
# systemctl restart nginx.service
# systemctl restart php-fpmTruy cập link http://your_ip_server/info.php hoặc http://your_domain/info.php.
Bước 7: Cài đặt phpMyAdmin
- Cài đặt phpMyAdmin
* PHP 5.4
yum install -y phpMyAdmin
* PHP 5.5
yum install -y phpMyAdmin
* PHP 5.6
yum install -y phpMyAdmin
Đối với PHP 7.0 hoặc PHP 7.x xem tại đây
- Cấu hình phpMyAdmin
# ln -s /usr/share/phpMyAdmin /usr/share/nginx/html/ # vi /etc/php.inisession.save_path = "/var/lib/php/session/"
# chown -R nginx:nginx /var/lib/php/session/- Khởi động dịch vụ Nginx, PHP-FPM
# systemctl restart nginx.service # systemctl restart php-fpmTruy cập link http://your_ip_server/phpMyAdmin hoặc http://your_domain/phpMyAdmin
Xem thêm video
Chúc bạn thành công !
No comments: