Việc tạo localhost với apache, PHP, MariDB, phpMyAdmin đơn giản nhất có lẽ là cài đặt bằng Xammp. Trong bài viết này mình sẽ nói về cách cài đặt Xammp trên máy tính Ubuntu, Linuxmint và Debian.
1. Tải Phần Mềm Xammp Về Máy Tính
Bạn truy cập vào https://www.apachefriends.org/download.html
Tùy theo phiên bản PHP 5.6, 7.0, 7.1 hoặc 7.2 bạn muốn sử dụng mà bạn download Xammp về máy tính.
2. Cài Đặt Xammp
Download xong, bạn vào terminal cd đến thư mục vừa tải xammp về hoặc vào thư mục đó, click chuột phải và chọn Open in Terminal
Next
Và next liên tục đến khi cài đặt kết thúc
Và bạn chọn Launche XAMPP, sau đó start các dịch vụ: Apache webserver, MySQL, FTP nếu bạn muốn sử dụng ngay.
Sau khi bạn bật Apache Web Server, lúc này bạn có thể truy cập vào http://localhost trên trình duyệt.
3. Tạo Shortcut cho Xammp Trên Desktop
Thông thường để bật XAMMP hay khởi động lại XAMMP chúng ta phải dùng lệnh:
Lệnh Start:
Tạo file xammp.desktop với nội dung sau :
4. Tiến Hành Config Bảo Mật, Đặt Mật Khẩu Tài Khoản root MySQL và FTP
Bây giờ ta sẽ chạy lệnh sau để config bảo mật XAMMP (tạo mật khẩu root cho MySQL, FTP )
5. Cấu Hình XAMMP Tự Chạy Khi Bật Máy
Nếu muốn XAMMP tự chạy khi bật máy, bạn làm như sau:
chạy lệnh:
6. Activate eAccelerator (Tùy chọn)
Từ phiên bản 1.7.2, eAccelerator bị disable vì không tương thích với PHP 5.3.0
Chúng ta sẽ activate nó bằng cách edit file cấu hình php.ini
7. Chạy Website
Để chạy website, bạn cần upload code vào thư mục:
1. Tải Phần Mềm Xammp Về Máy Tính
Bạn truy cập vào https://www.apachefriends.org/download.html
Tùy theo phiên bản PHP 5.6, 7.0, 7.1 hoặc 7.2 bạn muốn sử dụng mà bạn download Xammp về máy tính.
2. Cài Đặt Xammp
Download xong, bạn vào terminal cd đến thư mục vừa tải xammp về hoặc vào thư mục đó, click chuột phải và chọn Open in Terminal
sudo chmod +x xampp-linux-x64-7.0.30-0-installer.run sudo ./xampp-linux-x64-7.0.30-0-installer.run
Next
Và next liên tục đến khi cài đặt kết thúc
Và bạn chọn Launche XAMPP, sau đó start các dịch vụ: Apache webserver, MySQL, FTP nếu bạn muốn sử dụng ngay.
Sau khi bạn bật Apache Web Server, lúc này bạn có thể truy cập vào http://localhost trên trình duyệt.
3. Tạo Shortcut cho Xammp Trên Desktop
Thông thường để bật XAMMP hay khởi động lại XAMMP chúng ta phải dùng lệnh:
Lệnh Start:
sudo /opt/lampp/lampp startLệnh Restart:
sudo /opt/lampp/lampp restartLệnh stop:
sudo /opt/lampp/lampp stopThực hiện bằng lênh hơi tốn công, ta có thể đơn giản hóa bằng cách tạo shortchut cho XAMMP trên Desktop
Tạo file xammp.desktop với nội dung sau :
#!/usr/bin/env xdg-open [Desktop Entry] Version=1.0 Type=Application Terminal=false Icon[en_US]=/opt/lampp/htdocs/favicon.ico Name[en_US]=XAMPP Exec=gksu /opt/lampp/manager-linux-x64.run Comment[en_US]=Start XAMPP Control Panel Name=XAMPP Comment=Start XAMPP Control Panel Icon=/opt/lampp/htdocs/favicon.icoSau khi save xong, file đó sẽ liền thành shortcut cho phần mềm XAMMP của chúng ta.
4. Tiến Hành Config Bảo Mật, Đặt Mật Khẩu Tài Khoản root MySQL và FTP
Bây giờ ta sẽ chạy lệnh sau để config bảo mật XAMMP (tạo mật khẩu root cho MySQL, FTP )
sudo /opt/lampp/lampp securityKết quả:
sudo /opt/lampp/lampp security XAMPP: Quick security check... XAMPP: MySQL is accessable via network. XAMPP: Normaly that's not recommended. Do you want me to turn it off? [yes] no XAMPP: The MySQL/phpMyAdmin user pma has no password set!!! XAMPP: Do you want to set a password? [yes] yes XAMPP: Password: XAMPP: Password (again): XAMPP: Setting new MySQL pma password. XAMPP: Setting phpMyAdmin's pma password to the new one. XAMPP: MySQL has no root passwort set!!! XAMPP: Do you want to set a password? [yes] yes XAMPP: Write the password somewhere down to make sure you won't forget it!!! XAMPP: Password: XAMPP: Password (again): XAMPP: Setting new MySQL root password. XAMPP: Change phpMyAdmin's authentication method. XAMPP: The FTP password for user 'daemon' is still set to 'xampp'. XAMPP: Do you want to change the password? [yes] yes XAMPP: Password: XAMPP: Password (again): XAMPP: Reload ProFTPD...not running. XAMPP: Done.
5. Cấu Hình XAMMP Tự Chạy Khi Bật Máy
Nếu muốn XAMMP tự chạy khi bật máy, bạn làm như sau:
chạy lệnh:
sudo nano /etc/rc.localthêm vào dòng:
/opt/lampp/lampp startta được tương tự:
#!/bin/sh -e # # rc.local /opt/lampp/lampp start # # This script is executed at the end of each multiuser runlevel. # Make sure that the script will "exit 0" on success or any other # value on error. # # In order to enable or disable this script just change the execution # bits. # # By default this script does nothing. exit 0Sau đó nhấn
Ctrl + xddienf Y và enter để lưu lại.
6. Activate eAccelerator (Tùy chọn)
Từ phiên bản 1.7.2, eAccelerator bị disable vì không tương thích với PHP 5.3.0
Chúng ta sẽ activate nó bằng cách edit file cấu hình php.ini
/opt/lampp/etc/php.iniĐể dễ dàng làm, bạn nên thực hiên trên phần mềm edit text. Mình hay dùng Geany nên mình sẽ cài đặt Geany trước.
sudo apt install geanycài đặt xong, mình dùng geany để edit file php.ini
sudo geany /opt/lampp/etc/php.iniBây giờ ta sẽ bỏ dấu
;trong đoạn sau:
;extension="eaccelerator.so" ;eaccelerator.shm_size="16" ;eaccelerator.cache_dir="/opt/lampp/temp/eaccelerator" ;eaccelerator.enable="1" ;eaccelerator.optimizer="1" ;eaccelerator.check_mtime="1" ;eaccelerator.debug="0" ;eaccelerator.filter="" ;eaccelerator.shm_max="0" ;eaccelerator.shm_ttl="0" ;eaccelerator.shm_prune_period="0" ;eaccelerator.shm_only="0" ;eaccelerator.compress="1" ;eaccelerator.compress_level="9"Save lại và khởi động lại apache.
7. Chạy Website
Để chạy website, bạn cần upload code vào thư mục:
/opt/lampp/htdocs/
==> Đăng ký mã VPSSIM Business tại đây ! Thanks.