💡 Update: Using Local! You can create very quickly a simple wordpress on localhost with a domain website.local
. You can also backup your site and drag-n-drop into Local for using locally.
I create Math2ITwp theme for math2it.com from scratch. This note contains the basic things to create a theme like that.
👉 Note: All notes of Wordpress.
Install Apache + MySQL + PHP.
Linux
Below are the short steps from this post.
# upate system
sudo apt update
# install apache2
sudo apt install apache2
# Adjust the Firewall to Allow Web Traffic
sudo ufw app list
sudo ufw app info "Apache Full" # it should show that it enables traffic to ports 80 and 443
sudo ufw allow in "Apache Full"
# try browsing http://localhost
# install mysql
sudo apt install mysql-server
# setup mysql (choose Y for all, set passwords if neccessary)
sudo mysql_secure_installation
sudo mysql
SELECT user,authentication_string,plugin,host FROM mysql.user;
# change 'YourPassword' with your own password!!!
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'YourPassword';
FLUSH PRIVILEGES;
# verify that 'root' has 'mysql_native_password' in filed 'plugin'
SELECT user,authentication_string,plugin,host FROM mysql.user;
exit
After set a new password to root
user of mysql, instead of using sudo mysql
, you have to use following command to access mysql with the root
mysql -u root -p # and then type the new password (YourPassword above)!
# install php
sudo apt install php libapache2-mod-php php-mysql
# tell web server to prefer .php file
sudo gedit /etc/apache2/mods-enabled/dir.conf
# find IfModule mod_dir.c and move index.php to the first
# restart apache webserver
sudo systemctl restart apache2
# check status on apache2
sudo systemctl status apache2 # press Q to exit
# install some additional modules
apt search php- | less # press Q to quit
Testing a php file in /var/www/html/
sudo gedit /var/www/html/info.php
and paste
<?php
phpinfo();
?>
Goto localhost/phpmyadmin
to test.
# install phpmyadmin
sudo apt update
sudo apt install phpmyadmin php-mbstring php-gettext
# choose apache2 as default if you are asked for this
# enable the mbstring PHP extension
sudo phpenmod mbstring
# restart Apache for your changes to be recognized
sudo systemctl restart apache2
If you meet error ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
, follow this help on stackoverflow.
If you have error Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'
, check this.
All above errors: Try to remove and reinstall again mysql and
sudo apt-get remove --purge mysql*
sudo apt-get autoremove
sudo apt-get autoclean
sudo apt-get install mysql-server mysql-client
Login to mysql
mysql -u root -p
See the list of current user in mysql
# in the mysql environment
SELECT user,authentication_string,plugin,host FROM mysql.user;
Create a new user and give it a strong password
CREATE USER 'thi'@'localhost' IDENTIFIED BY 'YourPassword';
Grant your new user appropriate privileges
GRANT ALL PRIVILEGES ON *.* TO 'thi'@'localhost' WITH GRANT OPTION;
After installing phpmyadmin, there has to be an user phpmyadmin
in the list of user of mysql, if not, you need to create a such user and give it grant control like above.
Go to http://localhost/phpmyadmin
. Login with your user and password you created above (thi
for example).
Windows
- Download and install WampServer.
- By default, after installing, your site will be at
C:\wamp64\www
. - Run WarmServer, an green icon on the right of taskbar will appear.
MacOS
PHP executable (optional)
Just for running PHP + PHP IntelliSense
on Visual Studio Code.
Download PHP (Windows, portable).
Put below lines in VSC setting file (change the path to yours).
{
"php.validate.executablePath": "C:\\wamp64\\bin\\php\\php7.0.4\\php.exe",
"php.executablePath": "C:\\wamp64\\bin\\php\\php7.0.4\\php.exe"
}
Create local database + Wordpress
Create a database
# Sign in to MySQL
mysql -u root -p
# Check the list of users
SELECT user,authentication_string,plugin,host FROM mysql.user;
# Create a new user `thi` and assign to this user a password, e.g. `thipassword`
CREATE USER 'thi'@'localhost' IDENTIFIED BY 'thipassword';
# Set the orivileges to this user
GRANT ALL PRIVILEGES ON *.* TO 'thi'@'localhost' WITH GRANT OPTION;
- Open
http://localhost/phpmyadmin/
, - Create a new database
testing_db
(remember to chooseutf8_general_ci
before pressing Create) - Create a new user
thi
withALL PRIVILEGES
(click on Check all).
Install Wordpress
- Download Wordpress.
- Create a folder
thi
inC:\wamp64\www
(Windows),/var/www/html
(Linux). - Extract the content (
wp-admin
,wp-content
,...) of the zip file downloaded in step 1 to/thi/
. - Go to
http://localhost/thi
and follow the instructions. - Type the username and password you created (
thi
andthipassword
). - Press Install and wait.
- Login with username and password.
- All the configuration is at
http://localhost/texmath/wp-admin/
.
Clone a website to localhost
- Install Apache + MySQL + PHP.
- Create database + install Wordpress.
- At least, you have a workable site at
http://localhost/thi/
. - Download and install an FTP app like WinSCP (Windows) or FileZilla or Transmit.
- Download the current theme on the remote to local. The theme is located at
/wp-content/themes/
. - Clone database from remote site to local by using plugin All-in-One WP Migration. More detailed guid: English, Vietnamese. If your site's too big, exlude the media files and copy them later. They're all in
wp-content/uploads
. - Note that, you have to use
username
andpassword
given in the downloaded database instead of the one you created on localhost. - Enable the downloaded theme in
/wp-admin
.
💬 Comments