Apache LAMP server - mowen0303/note GitHub Wiki

Install Apache

sudo apt update
sudo apt install apache2

error log: sudo tail -100 /var/log/apache2/error.log

Once apache installation done — run this commands

sudo systemctl stop apache2.service
sudo systemctl start apache2.service
sudo systemctl enable apache2.service

Install PHP 7.3

sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install -y php7.3

if any confirmation comes — select Yes. Install few necessary extensions

sudo apt-get install php7.3-cli php7.3-fpm php7.3-json php7.3-pdo php7.3-mysql php7.3-zip php7.3-gd php7.3-mbstring php7.3-curl php7.3-xml php7.3-bcmath php7.3-json

Once done — restart the apache server

sudo systemctl restart apache2

check php version installed using

php -v

Install MariaDB

sudo apt install mariadb-server mariadb-client

once done — run this commands

sudo systemctl stop mariadb.service
sudo systemctl start mariadb.service
sudo systemctl enable mariadb.service

Setup the installation

sudo mysql_secure_installation

When prompted, answer the questions below by following the guide.

Enter current password for root (enter for none): Just press the Enter

Set root password? [Y/n]: Y

New password: Enter password

Re-enter new password: Repeat password

Remove anonymous users? [Y/n]: Y

Disallow root login remotely? [Y/n]: Y

Remove test database and access to it? [Y/n]: Y

Reload privilege tables now? [Y/n]: Y

Once done restart the service

sudo systemctl restart mariadb.service
sudo systemctl restart apache2

Now you can run mysql

sudo mysql

exit;

Install Phpmyadmin

sudo apt-get update
sudo apt-get install phpmyadmin

Select apache2 on window pop up.

Configure database for phpmyadmin with dbconfig-common?

Select NO

Check mysql admin user

SELECT User, Host, Password FROM mysql.user;

Change admin user name

rename user 'phpmyadmin'@'localhost' to 'jerry'@'localhost';

Then https://serverIP/phpmyadmin

Should work.

example: https://127.0.0.1/phpmyadmin

Multiple website and domain

copy apach2 config file

sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/new-default.conf
sudo chmod 777 /etc/apache2/sites-available/new-default.conf

update new-default.conf

<VirtualHost *:80>
	ServerName html.swingpark.ca
	ServerAdmin webmaster@localhost
	DocumentRoot /var/www/html
	ErrorLog ${APACHE_LOG_DIR}/error.log
	CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:80>
	ServerName test.swingpark.ca
	ServerAdmin webmaster@localhost
	DocumentRoot /var/www/test
	ErrorLog ${APACHE_LOG_DIR}/error.log
	CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:80>
	ServerName new.swingpark.ca
	ServerAdmin webmaster@localhost
	DocumentRoot /home/jerry/phpApps/swingpark
	ErrorLog ${APACHE_LOG_DIR}/error.log
	CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

use new config file

sudo a2ensite new-default.conf
sudo systemctl reload apache2
sudo service apache2 restart
  • config location: cd /etc/apache2/sites-available
  • project location: cd /var/www/

Apache Command

  • apache2 -v
  • sudo systemctl status apache2
  • sudo service apache2 restart

Install PHP 7.3 on ubuntu 22

sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install -y php7.3

switch php version

// disable current php version
sudo a2dismod php8.1

// restart apache2
systemctl restart apache2

// enable new php version
sudo a2enmod php7.3

//Set PHP 7.3 as default version
sudo update-alternatives --set php /usr/bin/php7.3

//restart apach2
sudo service apache2 restart

Install MySQlL && PHPMyAdmin

  • sudo apt-get install mysql-server
  • systemctl status mysql.service
  • sudo apt-get install phpmyadmin -y
  • sudo service mysql restart

Mysql Command

  • CREATE USER 'jerry'@'%' IDENTIFIED BY 'mypassword'; //创建管理员
  • ALTER USER 'jerry'@'%' IDENTIFIED BY 'newpassword!;' //修改管理员密码
  • GRANT ALL PRIVILEGES ON * . * TO 'jerry'@'%' WITH GRANT OPTION;

MYSQL 解决中文字符集乱码问题的方法

修改 /etc/mysql/my.cnf

增加内容

[client]
default-character-set = utf8mb4

[mysql]
default-character-set = utf8mb4

[mysqld]
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci