LAMP with Yii1

Installing PHP

    sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt

    Install php extensions

        sudo apt-get install php5-mysql
        sudo apt-get install php5-sqlite
        sudo apt-get install php5.6-mbstring
        sudo apt-get install libapache2-mod-php5.6

In most cases, we’ll want to modify the way that Apache serves files when a directory is requested. 
Currently, if a user requests a directory from the server, Apache will first look for a file called index.html. 
We want to tell our web server to prefer PHP files, so we’ll make Apache look for an index.php file first.

To do this, type this command to open the dir.conf file in a text editor with root privileges:

sudo nano /etc/apache2/mods-enabled/dir.conf
It will look like this:


    DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm

We want to move the PHP index file highlighted above to the first position after the DirectoryIndex specification, like this:


    DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm



----------------------------------------------------------------

Install Multiple PHP Versions on Ubuntu 16.04

Install PHP 5.6

Step 1: Update Apt-Get
apt-get update && apt-get upgrade
apt-get install -y software-properties-common
add-apt-repository ppa:ondrej/php
apt-get update

Step 2: Install PHP 5.6
apt-get install -y php5.6

Changing PHP Version for Apache (if your server have more than one php version)

a2dismod php7.0; a2enmod php5.6; service apache2 restart
a2dismod php5.6; a2enmod php7.0; service apache2 restart

Changing PHP Version for Ubuntu

update-alternatives --config php
and then choose one php version for command line ( Ubuntu )

----------------------------------------------------------------


Installing Apache Web Server

Step 1 — 
    sudo apt update
    sudo apt install apache2

Step 2 — Adjusting the Firewall

    sudo ufw app list
    sudo ufw allow 'Apache'
    sudo ufw status

    or custom port allow

    sudo ufw allow 8080
    sudo ufw reload

Step 3 — Checking your Web Server

    sudo systemctl status apache2

    hostname -I
    at command line : curl -4 testwebsite.com
    at browser : http://your_server_ip

Step 4 — Managing the Apache Process

    sudo systemctl stop apache2
    sudo systemctl start apache2
    sudo systemctl restart apache2
    sudo systemctl reload apache2
    sudo systemctl disable apache2
    sudo systemctl enable apache2

Step 5 — Setting Up Virtual Hosts (Recommended)

    sudo mkdir /var/www/your_domain
    sudo chown -R $USER:$USER /var/www/your_domain
    sudo chmod -R 755 /var/www/your_domain

    nano /var/www/your_domain/index.html
    and added some html code into index.html

    sudo nano /etc/apache2/sites-available/your_domain.conf

    /etc/apache2/sites-available/your_domain.conf
    
        ServerAdmin webmaster@localhost
        ServerName your_domain
        ServerAlias www.your_domain
        DocumentRoot /var/www/your_domain
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
    

    Or 

    
        ServerName ipaddress
        DocumentRoot /var/www/html/testwebsite
        
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
        
    	

Allowing Rewrite rules to Apache2 Web Server at Ubuntu

    a2enmod rewrite
    systemctl restart apache2

Let’s enable the file with the a2ensite tool:

    sudo a2ensite your_domain.conf

Disable the default site defined in 000-default.conf:

    sudo a2dissite 000-default.conf

Next, let’s test for configuration errors:

    sudo apache2ctl configtest

You should see the following output:

Output
Syntax OK

Restart Apache to implement your changes:

    sudo systemctl restart apache2

Checking Errors log at Apache Server

/var/log/apache2/access.log

----------------------------------------------------------------

Installing MySQL to Manage Site Data

    sudo apt install mysql-server php5-mysql
    sudo mysql_secure_installation

Allow MySql without 'sudo' at command line
    sudo mysql
    mysql> SELECT user,authentication_string,plugin,host FROM mysql.user;
    mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
    mysql> FLUSH PRIVILEGES;
    mysql> SELECT user,authentication_string,plugin,host FROM mysql.user;
    mysql> exit
and then, you can access mysql without sudo 'mysql -u root -p'

Adding new user and grant databases / only one database

    // Creating new database user
    CREATE USER 'YourUserName'@'localhost' IDENTIFIED BY 'YourPassword';
    CREATE USER 'YourUserName'@'%' IDENTIFIED BY 'YourPassword';

    // Granting the one user to all database
    GRANT ALL ON *.* TO 'YourUserName'@'localhost';
    GRANT ALL ON *.* TO 'YourUserName'@'%';

    // Granting the one user to one database
    GRANT ALL ON YourDatabaseName.* TO 'YourUserName'@'localhost';
    GRANT ALL ON YourDatabaseName.* TO 'YourUserName'@'%';

----------------------------------------------------------------    


Advertisements

Ubuntu OS မွာ Apache ၿဖင္႔ PHP ကို Multiple Versions ေၿပာင္းလဲ အသံုးၿပဳၿခင္း

Ubuntu OS မွာ Apache ၿဖင္႔ PHP ကို Multiple Versions ေၿပာင္းလဲ အသံုးၿပဳၿခင္း
အကယ္၍ မိမိ development လုပ္ေနေသာ Environment မွာ PHP ကို Version တစ္မ်ဴိးထက္ပိုၿပီး Install လုပ္ထားရတယ္ ( eg. 5.6 and 7.3 )။ မိမိရဲ႕ Project ရဲ႕လုိအပ္ခ်က္အရ PHP ကို Version 5.6 နဲ႕ 7.3 Version ၂ မ်ဴိးလံုးအသံုးၿပဳဖုိ႕လိုအပ္ခဲ႕လွ်င္
——————————————————-
ဥပမာ အေနနဲ႕
Project1 – Yii Framework Version 1 – PHP 5.6
Project2 – Laravel Framework Version 5.7 – PHP 7.3
——————————————————-
How to change PHP Version for Apache
Enable php 5.6  and disable php 7.3
sudo a2dismod php7.3
sudo a2enmod php5.6
sudo service apache2 restart
Enable php 7.3  and Disable php 5.6
sudo a2dismod php5.6
sudo a2enmod php7.3
sudo service apache2 restart
/var/www/html folder ထဲတြင္ info.php ဆိုၿပီး PHP Script File တစ္ခုတည္ေဆာက္ၿပီး
<?php
phpinfo();
?>
ဆုိၿပီး သိမ္းဆည္းလိုက္ပါ။ ၿပီးလွ်င္ Browser မွ http://localhost/info.php ဆိုၿပီးေခၚၿကည္႔လုိက္ပါ။
မိမိရဲ႕ Apache Web Server ရဲ႕ လက္ရွိ PHP Version ကို ၿမင္ရပါလိမ္႔မယ္။
———————————————-
How to change PHP Version for Ubuntu ( command line usage )
Terminal ( Command Line ) တြင္
sudo update-alternatives –config php
PHP Version selection Questions ေပၚလာပါလိမ္႔မယ္။ မိမိ အလုိရွိေသာ PHP Version ကိုေရြးခ်ယ္ ေၿပာင္းလဲလုိ႕ရပါသည္။ ေၿပာင္းလဲၿပီးစီးသည္႔အခါ Teminal တြင္
php -v
ၿဖင္႔ PHP current version ကို ေခၚၿကည္ႏုိင္ပါသည္။
————————————————–
OS – Ubuntu – 16.04 / 18.04
Web Server – Apache
PHP – 5.6 & 7.3
—————————————————
Wai Yan Aung
20190921