21
2020
02

Turn your Android smartphone into a Linux web server

http://prochal.com/2017/09/turn-android-smartphone-linux-web-server-part-2/


Installing LAMP


First, make sure you’re logged as root. If you set the user to root in the previous step, most likely you would. If not, elevate user privileges by adding ‘sudo’ word before all commands from this chapter. Next, ensure your system and apt package lists are fully up-to-date by running the following:


apt-get update -y && apt-get upgrade -y


The -y flag tells apt to go ahead and update the system without prompting you. Next you’ll need some kind of text editor. Personally I used nano, but actually any is going, to be fine. It’s up to your preference.


apt-get install nano -y


OR:


apt-get install gedit -y


PHP 7


apt-get install python-software-properties

add-apt-repository ppa:ondrej/php

apt-get update

apt-get purge php5-fpm

apt-get install php7.0-cli php7.0-common libapache2-mod-php7.0 php7.0 php7.0-mysql php7.0-fpm php7.0-mysql

apt-get install php7.0-cgi php7.0-dbg php7.0-dev php7.0-curl php7.0-gd

apt-get install php7.0-mcrypt php7.0-xsl php7.0-intl


After the installation is complete, restart Apache2:


service apache2 restart


And verify if the PHP7 installed correctly:


php -v


Apache2


Please run for the standard Apache installation


apt-get install apache2


or in case you don’t want to use the php-fpm package:


apt-get install apache2 libapache2-mod-php -y


Check if the Apache is running:


service apache2 status


If not, try to start it manually:


service apache2 start


Apache2 enable mod_rewrite


sudo a2enmod rewrite

sudo service apache2 restart


Then open the configuration file:


nano /etc/apache2/apache2.conf


AllowOverride None to AllowOverride All


<Directory /var/www/>

Options Indexes FollowSymLinks

AllowOverride All

Require all granted

</Directory>


sudo service apache2 restart


MySQL


apt-get install mysql-server -y


mysql_secure_installation


Follow the prompts as below:


Would you like to setup VALIDATE PASSWORD plugin? press Enter here for No

Please set the password for root here. New password: Type a secure password here then press Enter

Re-enter new password: Re-type the secure password here then press Enter

Remove anonymous users? (Press y|Y for Yes, any other key for No) : press y and then Enter here

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : press y and then Enter here

Remove test database and access to it? (Press y|Y for Yes, any other key for No) : press y and then Enter here

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : press y and then Enter here

Then try to start mysql service:


service mysql start


You log into the client by running:


mysql -u root -p



Cannot touch ‘/var/log/mysql/error.log’: Permission denied

This means the MySQL process cannot access logs directory, you can fix it by running:


chown -R mysql /var/log/mysql


…or any other mentioned catalog in the log. If that doesn’t help, try setting the access rights by running CHMOD -R 777 for given directory and gradually decrease the rights.


ERROR: The partition with /var/lib/mysql is too full!

Check if you have any free space on the partition, if you do and the error persists, try changing the owner of the catalog recursively as in the previous example.


ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (111)

Firstly, you can try going to /etc/mysql/my.cnf and change ‘bind-address’ parameter to ‘localhost’ or ‘127.0.0.1’.  Sometimes the Android kernel can be compiled with CONFIG_ANDROID_PARANOID_NETWORK setting. This allows only certain users to use the device network i.e. users that belong to hardcoded groups –


aid_bt


aid_bt_net


aid_inet


aid_net_raw


aid_admin


To fix it add mysql user to one of the groups:


usermod -a -G aid_inet,aid_net_raw mysql


Well done, you have a working web server!  Just put your project in the var/www/html catalog or define your own in the etc/apache2/sites-enabled configuration file. To find your IP address, to which you can connect from outside devices, run the following command:


ifconfig | grep inet



下一篇 »

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。